5

Here's a minimal example of what is not working for me:

\documentclass{article}

\newcommand{\foo}[1]{a_#1}

\begin{document}
$\foo{\hat{1}}$
\end{document}

Am I doing something wrong in my command definition, or is something else going wrong here?

6

Your current definition assumes that your argument to \foo will be a single token. Hover, \hat{1} is not a single token. Wrap the subscript in braces to allow multiple tokens to be properly set as a subscript:

\documentclass{article}

\newcommand{\foo}[1]{a_{#1}}

\begin{document}

$\foo{\hat{1}}$

\end{document}
  • Ah, that kind-of makes sense. Why does \hat{1} not count as a single token though? Things like $\foo{\mathbf{1}}$ do work, so what's the difference exactly? – Joeytje50 Oct 23 '16 at 18:45
  • @Joeytje50: It depends on how the macro is written as some are more robust. – Werner Oct 23 '16 at 18:53

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.