# Underbraces for multiplied components of an equation

From other sources (e.g. here and here), I have cobbled together an equation with underbraces labelling each part.

I would like to add an underbrace to this part:

\rm{tanh}(W_2x_t + U_2h_{t-1} + b_2)


but whenever I do, I get an error: Missing $inserted. In the comments in the MWE below, I include the code I tried that generated the error. How can I add an underbrace to that part of the equation - it's multiplied by a term that already has an underbrace, if that's a problem? \documentclass{article} \usepackage{mathtools}% Loads amsmath \begin{document} $c_t = \underbrace{\sigma(W_3 x_t + U_3h_{t-1} + b_3)}_\text{forget gate} c_{t-1} + \underbrace{\sigma(W_1x_t + U_1h_{t-1} + b_1)}_\text{input gate} \rm{tanh}(W_2x_t + U_2h_{t-1} + b_2)$ \end{document} %$% c_t = % \underbrace{\sigma(W_3 x_t + U_3h_{t-1} + b_3)}_\text{forget gate} c_{t-1} + % \underbrace{\sigma(W_1x_t + U_1h_{t-1} + b_1)}_\text{input gate} \underbrace{\rm{tanh}(W_2x_t + U_2h_{t-1} + b_2)}_\text{c_{new_t}} %$  ## 1 Answer Well, \text expects its argument to be text. I.e. inside its argument you are not in math mode anymore and must add $…\$ to get the text in math mode. However since you don’t want text at all, don’t use the macro and write \underbrace{…}_{c_{new_t}}.

You may also like to improve your code further:

1. Use \tanhinstead of using a deprecated font macro (\rm). (If you need other operators, they should be defined with\DeclareMathOperator{\tanh}{tanh} for example.
2. Use \text, where it is necessary, e.g. in c_{\text{new}_t}
\documentclass{article}
$c_t = \underbrace{\sigma(W_3 x_t + U_3h_{t-1} + b_3)}_\text{forget gate} c_{t-1} + \underbrace{\sigma(W_1x_t + U_1h_{t-1} + b_1)}_\text{input gate} \underbrace{\tanh(W_2x_t + U_2h_{t-1} + b_2)}_{c_{\text{new}_t}}$
`