I have this test case for \ifthenelse which works as expected when I put it directly in my document
\ifthenelse{\equal{x}{y}}{XXX}{YYY}
If I put this in the definition of a new command, it still works.
\newcommand{\tmpcmd}[1]
{
\textsf{#1}
\ifthenelse{\equal{x}{y}}{XXX}{YYY}
}
\tmpcmd{C}
However, if I change the name of this command to pn, it gives an error.
! Undefined control sequence.
<argument> \equal
{x}{y}
The command \pn is already established in my document. Its previous definition was
\newcommand{\pn}[1]
{
\textsf{#1}
}
but by changing it to
\newcommand{\pn}[1]
{
\textsf{#1}
\ifthenelse{\equal{x}{y}}{XXX}{YYY}
}
now I get the error message.
This doesn't make any sense to me. Why do the \ifthenelse and the \pn function each work separately, but not one inside the other?
\ifthenelseis a fragile command so any command defined using it is fragile and will fail in a moving argument unless protected with\protectthe name of the command is not relevant, just where it is used. – David Carlisle Jan 17 '17 at 16:41%in your definitions. – David Carlisle Jan 17 '17 at 16:42