1

This question already has an answer here:

I am trying to declare a new command using the following string:

\newcommand{\to8}[1]{\xrightarrow{\mathmakebox[0.8cm]{#1}}}

but the compiler returns many errors. I just don't understand why if I write

\xrightarrow{\mathmakebox[0.8cm]{iiiii}}

in the math mode the compiler returns no error but the compile does not allow it when I want to define it as a new command?

marked as duplicate by egreg macros Sep 25 '16 at 8:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Without knowing the answer how do I know it is the problem with the name? I thought it was the problem of the parameter 0.8cm.. – PhysicsMath Sep 25 '16 at 14:24
5

The definition of your macro is fine. The problem is that you cannot have numbers in the name of a macro, so if you change the name of your macro then all will be well:

enter image description here

Btw, rather than posting code snippets it is better to post a minimal working example. In particular, the code should compile, unless that's the problem. This makes it much easier for other people to trouble shoot your problem and hence help you. Here is a MWE for your (corrected) code:

\documentclass{article}
\usepackage{mathtools}
\newcommand{\toeight}[1]{\xrightarrow{\mathmakebox[0.8cm]{#1}}}

\begin{document}

  $\toeight{f}$

\end{document}
  • Got you Andrew! I will follow your advice in my future posts! Many thanks for both the answer and the advice! – PhysicsMath Sep 25 '16 at 14:25
3

Can't have a number as part of a command.

   \documentclass{article}

\usepackage{mathtools}

\newcommand{\toeight}[1]{\xrightarrow{\mathmakebox[0.8cm]{#1}}}
\begin{document}
    \begin{equation}
    \toeight{xxx}
    \end{equation}
\end{document}

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