2

Problem:

Trying to activate math mode inside underbrace text but I receive errors telling me that I am not allowed. I have managed to solve this with \[ and \] but the equation shifts to the center of the page despite using \noindent.

Minimal Working Example (MWE):

\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\noindent $(a \pm b)^2 = (a \pm b)(a \pm b) = a \cdot a \pm a \cdot b \pm \underbrace{b \cdot a}_\text{a \cdot b} + b \cdot b = a^2 \pm 2ab + b^2$

\end{document}

Desired output:

Get math mode to work inside underbrace text while keeping the overall text aligned to the left.

1
  • 1
    Although the accepted answer is a simpler solution, \[ \] is display mode, and you can instead use \( \) for inline.
    – Davislor
    Commented Jul 5, 2019 at 20:24

1 Answer 1

5

In theory you could use $...$ to have math mode inside \text{...}

\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\noindent $(a \pm b)^2 = (a \pm b)(a \pm b) = a \cdot a \pm a \cdot b \pm \underbrace{b \cdot a}_\text{$a \cdot b$} + b \cdot b = a^2 \pm 2ab + b^2$

\end{document}

But why do you use \text{...} for math? Just remove it:

\documentclass[a4paper,11pt]{book}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\noindent $(a \pm b)^2 = (a \pm b)(a \pm b) = a \cdot a \pm a \cdot b \pm \underbrace{b \cdot a}_{a \cdot b} + b \cdot b = a^2 \pm 2ab + b^2$

\end{document}
1
  • This is embarrassing - I certainly do not know why I had it in my mind that I had to use \text to get underbrace to work.
    – kexxcream
    Commented Jul 5, 2019 at 17:04

You must log in to answer this question.

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