1

If I define the following two commands:

\newcommand{\TestA}[1][]{a^{#1} aaa}
\newcommand{\TestB}[1][]{#1}

and then call it by

$\TestA[\TestB[111]]$

I get the error:

"Argument of \\TestB has an extra  }."

But $\TestB[111]$ and $\TestA[111]$ works...

Is this a bug or am I doing something wrong?

  • Welcome to TeX.SX!. When asking questions it is better to provide a full minimal working example (MWE) both in order to demonstrate what you are trying to do and to help others help you. The MWE should look like \documentclass...\begin{document}...\end{document}, it should compile and contain close to the minimal amount of code needed to explain/demonstrate what you are asking. This saves everyone time:) – Andrew Nov 20 '14 at 13:08
4

You are confusing latex with the square backets for the optional arguments. When latex sees

 \TestA[\TestB[111]]

it thinks that the optional argument for \TestA is \TestB[111. Now it tries to evaluate this expression and gets confused because \TestB is not conforming to syntax.

To fix this you need to put brackets around the optional argument to \TestA:

\TestA[{\TestB[111]}]
  • 1
    Thanks. This workaround solves the problem. Nevertheless in my opinion I would expect Latex to behave differently... – mimi Nov 20 '14 at 14:17

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.