0

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?

3
  • The point of posting code examples is so that others can debug the error and answer, if you just post code that doesn't generate an error that makes it hard for anyone to help. \ifthenelse is a fragile command so any command defined using it is fragile and will fail in a moving argument unless protected with \protect the name of the command is not relevant, just where it is used. Jan 17 '17 at 16:41
  • unrelated to the error but you are missing a lot of % in your definitions. Jan 17 '17 at 16:42
  • Re David's last comment, see tex.stackexchange.com/questions/7453/… Mar 5 '17 at 10:25
1

The problem was that \pn was being called inside commands such as \chapter and \section.

2
  • That seems to verify David Carlisle's comment, above.
    – user103221
    Jan 17 '17 at 18:23
  • Yes, thank you, David. I'm fairly new to TeX so I guess I'm rubber-ducking a bit. Thanks for your patience.
    – spraff
    Jan 17 '17 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.