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?

spraff
  • 1,501
  • 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. – David Carlisle Jan 17 '17 at 16:41
  • unrelated to the error but you are missing a lot of % in your definitions. – David Carlisle Jan 17 '17 at 16:42
  • Re David's last comment, see http://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines – Torbjørn T. Mar 05 '17 at 10:25

1 Answers1

1

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

spraff
  • 1,501
  • That seems to verify David Carlisle's comment, above. –  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