# Making \left[ \right] ignore the height of \underbrace

This question is similar to Underbrace without big environment-braces ( \left(\right) ) but that article isn't exactly what I need. I need the underbrace to appear below the brackets.

The following code

\documentclass[12pt]{article}
\usepackage{mathtools,amssymb,amsthm}

\begin{document}
\begin{equation*}
E \left[ \smash{\underbrace{\int_0^t v^2(s) \, ds}_{\text{deterministic}}} \right] \qquad
E \left[ \underbrace{\int_0^t v^2(s) \, ds}_{\smash{\text{deterministic}}} \right]
\end{equation*}
\end{document}


produces this output:

But what I need is this:

Basically I need smash to operate on the underbrace and text, but not on the integral sign within the \underbrace argument.

• Why not some predefined size like \Biggl[ \Biggr]? – Sigur Feb 20 at 0:36
• Oh I guess that would also work :) – Jason D. Feb 20 at 0:58

I suggest using an explicit size rather than \left and \right.

It is possible to use \left and \right, though, by typesetting the material three times: one smashed, one with the underbrace suppressed and one for reestablishing the correct height of the material.

I also recommend other changes:

1. it's better to have a personal command for the expectation; if a reviewer pops up and orders you to typeset the “E” in a fancier font, you'll be able to do it by just changing one line of code;

2. the same holds for the differential sign; a journal you try to submit your paper to might want the “d” to be upright (unfortunately some do); with a personal command it's easier to comply; also, this \diff automatically adds the thin space when needed;

3. don't use \underbrace (or \overbrace) in your document: in this case it doesn't really matter (for the \postsmash macro to work it does, however), but in general it can lead to bad spacing;

4. when you're making the final revision, check the output for places where to add \, or \! in order to fix clashes.

\documentclass[12pt]{article}
\usepackage{mathtools,amssymb,amsthm}

\usepackage{lipsum} % for mock text

\DeclarePairedDelimiter{\expectationargument}{[}{]}
\newcommand{\expect}{E\expectationargument}

\newcommand{\diff}{\mathop{}\!d}

\newcommand{\ubrace}[2]{{% note the additional brace
\underbrace{#1}_{#2}%
}}

\makeatletter
\newcommand{\postsmash}[1]{%
\smash{#1}%
\vphantom{\let\ubrace\@firstoftwo#1}%
\gdef\fixverticalspace{\vphantom{#1}}%
}
\makeatother

\begin{document}

\lipsum[1][1-4]
\begin{equation*}
\expect[\Big]{\ubrace{\int_0^t v^2(s) \diff s}{\text{deterministic}}}
\expect[\bigg]{\,\ubrace{\int_0^t v^2(s) \diff s}{\text{deterministic}}\,}
\end{equation*}
\lipsum[2][1-4]
\begin{equation*}
\expect*{\,\postsmash{\ubrace{\int_0^t v^2(s) \diff s}{\text{deterministic}}}\,}
\fixverticalspace
\end{equation*}
\lipsum[3][1-4]
\begin{equation*}
\expect[\bigg]{\,\int_0^t v^2(s) \diff s}
\end{equation*}
where the integral is deterministic.

\end{document}


Final recommendation: avoid \underbrace as hard as possible.

• These are excellent suggesions. Thank you so much. – Jason D. Feb 21 at 6:26

Use \biggl-\biggr to adjust the brackets:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

$E \left[ \smash{\underbrace{\int_0^t v^2(s) \, \mathrm{d}s}_{\text{deterministic}}} \right] \qquad E \left[ \underbrace{\int_0^t v^2(s) \, \mathrm{d}s}_{\smash{\text{deterministic}}} \right] \qquad E \biggl[ \underbrace{\int_0^t v^2(s) \, \mathrm{d}s}_{\text{deterministic}} \biggr]$

\end{document}


Using \smash may cause the brace text to interfere with the surrounding (vertical) elements.

I have adopted, just for the last integral, a command macro used in this link, called \mystrut, to increase the vertical space above underbrace, that I have renamed:

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}

\usepackage{mathtools}
% \spvertund is a command that creates space above underbrace
\newcommand*\spvertund[1]{\vrule width0pt height0pt depth#1\relax}
\begin{document}
\lipsum[3]
$E \biggl[ \underbrace{\spvertund{2.5ex}\int_0^{t} v^{2}(s) ds}_{\text{deterministic}} \biggr], \quad E \Biggl[ \underbrace{\spvertund{3.5ex}\int_0^{t} v^{2}(s) ds}_{\text{deterministic}} \Biggr]$
\lipsum[5]
\end{document}


Everyone's given best-practice answers (size explicitly), but, in the spirit of answering the question asked:

\documentclass[12pt]{article}
\usepackage{mathtools,amssymb,amsthm}

\begin{document}
\begin{equation*}
\def\filler{\int_0^t v^2(s) \, \mathrm ds}
E \left[ \smash{\underbrace\filler_{\text{deterministic}}}\vphantom\filler \right]
\end{equation*}
\end{document}


This is basically the same as @egreg's answer, but maybe it's easier to see what's going on with some less macro indirection.