10

Code Sample:

\sqrt{\underbrace{\det((D\varphi)^T)}_{\det(D\varphi)} \det(D\varphi)}

Produces:

enter image description here

The problem: By using the underbrace, it is set in the square root and not under the square root - so the square root is bigger than the line height. How can I avoid this?

1
  • 2
    @barbarabeeton - I've retracted the close vote. – Mico Jan 29 at 16:16
11

The proposed solution uses a command \ubrace that better than \underbrace because it makes an ordinary atom instead of an operator atom and has a more conforming LaTeX syntax.

The argument to \usqrt is saved in a box where \ubrace is redefined to only deliver its first argument. So we can use this box as a phantom in order to set the radical to the desired height and width.

We back up by the width of this box and retypeset the argument with the normal meaning of \ubrace.

In the picture, the second formula is meant to provide a check for everything going as expected.

enter image description here

\documentclass{article}
\usepackage{amsmath}

\newcommand{\ubrace}[2]{{\underbrace{#1}_{#2}}}
\newsavebox{\usqrtbox}
\newcommand{\usqrt}[1]{% square root with underbraced material
  \sbox{\usqrtbox}{%
    \renewcommand{\ubrace}[2]{##1}% deliver only the main part
    $\displaystyle#1$%
  }%
  \sqrt{\phantom{\usebox{\usqrtbox}}}\hspace*{-\wd\usqrtbox}#1%
}

\begin{document}

\[
\usqrt{
  \ubrace{\det((D\varphi)^T)}{\det(D\varphi)}
  \det(D\varphi)
}=x
\]
\[
\sqrt{\det((D\varphi)^T)\det(D\varphi)}=x
\]

\end{document}

There is a small difference: indeed, TeX uses the cramped \displaystyle inside a square root. You can fix this by using mathtools.

\documentclass{article}
\usepackage{amsmath,mathtools}

\newcommand{\ubrace}[2]{{\underbrace{\ifsqrt\expandafter\cramped\fi{#1}}_{#2}}}

\newif\ifsqrt
\newsavebox{\usqrtbox}
\newcommand{\usqrt}[1]{% square root with underbraced material
  \begingroup
  \sqrttrue
  \sbox{\usqrtbox}{%
    \renewcommand{\ubrace}[2]{\cramped{##1}}% deliver only the main part
    $\displaystyle#1$%
  }%
  \sqrt{\phantom{\usebox{\usqrtbox}}}\hspace*{-\wd\usqrtbox}%
  #1%
  \endgroup
}

\begin{document}

\[
\usqrt{
  \ubrace{\det((D\varphi)^T)}{\det(D\varphi)}
  \det(D\varphi)
}=x
\]
\[
\sqrt{\det((D\varphi)^T)\det(D\varphi)}=x
\]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.