# Inserting command with optional argument as optional argument Problem

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

 \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]}]