0

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

5
  • 2
    The syntax is incorrect: \newcommand{\textbelow}[2]{\underbrace{#1}_{\substack{#2}}} would be right.
    – egreg
    May 11, 2018 at 22:38
  • That example surely doesn't produce the error.
    – egreg
    May 11, 2018 at 22:51
  • @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.)? May 11, 2018 at 22:58
  • Without a real example producing the error, it's impossible to say. Check your braces, not only in that definition.
    – egreg
    May 11, 2018 at 23:02
  • @egreg I got it. Thanks for asking me to check the log file. ;) May 11, 2018 at 23:08

1 Answer 1

0

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.

3
  • 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. May 11, 2018 at 22:49
  • 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.
    – egreg
    May 11, 2018 at 22:53
  • I tried copying and pasting the exact code from your answer to the page I am currently working on. I still get the error. May 11, 2018 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .