In this example:
\documentclass{article}
\usepackage{ifthen}
\newcommand{\objtitle}[1]{%
\ifthenelse{\equal{#1}{a}}{avalue}{}%
\ifthenelse{\equal{#1}{b}}{bvalue}{}%
}
\newcommand{\counterpart}[1]{%
\ifthenelse{\equal{#1}{a}}{b}{}%
\ifthenelse{\equal{#1}{b}}{a}{}%
}
\begin{document}
\counterpart{a}
\objtitle{a}
\objtitle{\counterpart{a}}
\end{document}
\counterpart{a} and \objtitle{a} work separately but \objtitle{\counterpart{a}} produces and error:
! Argument of \equal has an extra }.
<inserted text>
\par
l.17 \objtitle{\counterpart{a}}
Using \objtitle{\protect\counterpart{a}} eliminates the error message but produces no output.
What is the problem and how to solve?
\ifthenelseis (very) fragile and can not be used in the argument of\equal– David Carlisle Oct 11 '18 at 19:41\protectproduces no output. Is there a solution? – Viesturs Oct 11 '18 at 19:45\protectmakes it safe but stops it executing at all so it will not be equal to anything. You do not want to use\ifthenelseat all, but you havn't given any description of what you actually want to do so not sure what to suggest. – David Carlisle Oct 11 '18 at 19:56