Why do I get a 'macro parameter # in vertical mode' error?

1,755

The errors I get are

! Missing { inserted.
<to be read again> 
                   \vcenter 
l.12     \[ \textbelow{Look Down}{hello \\ world}
                                                  \]
? 
! Missing } inserted.
<inserted text> 
                }
l.12 ...[ \textbelow{Look Down}{hello \\ world} \]

which clearly stem from the missing braces around \substack{...}.

Indeed, if I add the braces, the example code runs without problems.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\textbelow}[2]{\underbrace{#1}_{\substack{#2}}}

\begin{document}

This \(\underbrace{Look Down}_{\substack{hello \\ world}}\) works fine.

But the newcommand does not:
    \[ \textbelow{Look Down}{hello \\ world} \]

\end{document}

enter image description here

However, this doesn't seem good for typesetting text.

Share:
1,755

Related videos on Youtube

Nanashi No Gombe
Author by

Nanashi No Gombe

Updated on August 01, 2022

Comments

  • Nanashi No Gombe
    Nanashi No Gombe over 1 year

    I am trying to define a new command in the following manner:

    \newcommand{\textbelow}[2]{\underbrace{#1}_\substack{#2}}
    

    It looks like the underscore character _ is creating the problem. If I remove it, I do not get any error, but that is not what I want to do.

    The syntax is correct, because outside of newcommand it works fine.

    \[\underbrace{Look Down}_{\substack{hello \\ world}}\]
    

    Why am I not able to make a new command out of this? If it is not possible to write an underscore _ inside newcommand, what is the workaround?

    Thank you for your assistance.


    If you so require, here is a full example of what I am trying to do.

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    
    \newcommand{\textbelow}[2]{\underbrace{#1}_\substack{#2}}
    \newcommand{\test}[2]{\underbrace{#1}\substack{#2}}
    
    \begin{document}
    
    This \(\underbrace{Look Down}_{\substack{hello \\ world}}\) works fine.
    
    But the newcommand does not:
        \[ \textbelow{Look Down}{hello \\ world} \]
    
    \end{document}
    

    Edit:

    @egreg's solution does not work for me. Here is a screenshot of the error I get in TeXstudio.

    error

    • egreg
      egreg over 5 years
      The syntax is incorrect: \newcommand{\textbelow}[2]{\underbrace{#1}_{\substack{#2}}} would be right.
    • egreg
      egreg over 5 years
      That example surely doesn't produce the error.
    • Nanashi No Gombe
      Nanashi No Gombe over 5 years
      @egreg I guess not. But would you terribly mind if I asked you to make a guess at why I might be getting the error? Could it be because of how I have structured my document (separate folders for packages, macros, chapters, main tex file etc.)?
    • egreg
      egreg over 5 years
      Without a real example producing the error, it's impossible to say. Check your braces, not only in that definition.
    • Nanashi No Gombe
      Nanashi No Gombe over 5 years
      @egreg I got it. Thanks for asking me to check the log file. ;)
  • Nanashi No Gombe
    Nanashi No Gombe over 5 years
    Thank you for your prompt answer. Maybe there is something else I am not telling you, but I get an error even with your simple fix. Please check the screenshot I added to my question.
  • egreg
    egreg over 5 years
    The “macro parameter in vertical mode” error usually means you have misplaced braces. Rather than the screenshot, please add the real error message you find in the .log file.
  • Nanashi No Gombe
    Nanashi No Gombe over 5 years
    I tried copying and pasting the exact code from your answer to the page I am currently working on. I still get the error.