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.
Best Answer
The errors I get are
which clearly stem from the missing braces around
\substack{...}
.Indeed, if I add the braces, the example code runs without problems.
However, this doesn't seem good for typesetting text.