# Outputting effective size of \left(…\right) parentheses

I am trying to get rid of \left( and \right) in my document while maintaining the mostly appropriate size of parentheses. However, there are maybe a couple dozen (or more) occurrences, and I would like to avoid going through the document bazillion times, trying out \big, \Big and the like for each one and repeatedly compiling. So I thought that maybe I could redefine \left( to output a warning to indicate

1. that I am using it and should not, and
2. the effective size of the current \left(...\right) construct to easy replacements.

I know that mathtools has a \delimsize, but I this can only be used with \DeclarePairedDelimiter.

Is this possible?

Something that would already help me: where are \left and \right actually defined?

• "I am trying to get rid of \left( and \right) in my document while maintaining the mostly appropriate size of parentheses." Eh... why would you want to do that? – wythagoras Jun 14 '17 at 11:20
• @wythagoras one example out of many on TeX.SX: tex.stackexchange.com/questions/31526/macro-for-left-and-right/… – bers Jun 14 '17 at 11:22
• @wythagoras another reason is that I feel like \left(...\right)should not consider accents such as \tilde etc., and I am getting tired of fighting the side-effects of \smash every time I use U and \tilde{U}, for example. Compare $\left(U\right. \left(\tilde{U}\right.$ – bers Jun 14 '17 at 11:33

## 1 Answer

Have your text editor change all occurrences of \left to either \xleft or \yleft, depending on which of these two methods you prefer. Then, any time a \left is invoked, an \fbox showing $\big#1\Big#1\bigg#1\Bigg#1$ is laid to the left of the construct.

This is a flag for you to do something about it. You can visually see if any of the 4 "big" constructs are the right size, and either edit that \xleft or \yleft to either the appropriate big delimiter of change it back to \left if none of them work.

The only difference between \xleft and \yleft is that the \yleft will \smash the \fbox. This is useful if nested \lefting occurs, otherwise the \fbox alters the natural size of the outer \lefts. The downside of \yleft is that it allows overlap to occur, which can be a bit confusing until the resolution is made.

\documentclass{article}
\def\xleft#1#2\right{
\fbox{$\big#1\Big#1\bigg#1\Bigg#1$}\left#1#2\right}
\def\yleft#1#2\right{
\smash{\fbox{$\big#1\Big#1\bigg#1\Bigg#1$}}\left#1#2\right}
\begin{document}
Here is the \verb|\yleft| method which smashes the test box.
$y = \yleft( x^2 + 3\right)$
And now for the next test:
$y = \yleft(\frac{a}{b}\right)$
Finally:
$y = 3\yleft(\frac{\yleft( x^2 + 3\right)}{b}\right)$
Here is the \verb|\xleft| method which does not smash the test box.
$y = \xleft( x^2 + 3\right)$
And now for the next test:
$y = \xleft(\frac{a}{b}\right)$
Finally:
$y = 3\xleft(\frac{\xleft( x^2 + 3\right)}{b}\right)$
\end{document}


For a dimension-based approach, invoke \basesizes at the beginning of the document to see the vertical dimension of \big, \Big, \bigg and \Bigg. Then change all \left to \zleft to reveal the required size for the given construct.

\documentclass{article}
\usepackage{scalerel}
\def\zleft#1#2\right{
\smash{\ThisStyle{\setbox0=\hbox{$\SavedStyle\left#1#2\right.$}%
\edef\tmp{\the\dimexpr\ht0+\dp0\relax}%
\fbox{\expandafter\truncate\expandafter{\tmp}}}}%
\left#1#2\right}
\newcommand\truncate[1]{\truncateaux#1\relax}
\def\truncateaux#1.#2\relax{#1pt}
\newcommand\basesizes{%
\noindent big: \setbox0=\hbox{\big(}\the\dimexpr\ht0+\dp0\relax\par
\noindent Big: \setbox0=\hbox{\Big(}\the\dimexpr\ht0+\dp0\relax\par
\noindent bigg: \setbox0=\hbox{\bigg(}\the\dimexpr\ht0+\dp0\relax\par
\noindent Bigg: \setbox0=\hbox{\Bigg(}\the\dimexpr\ht0+\dp0\relax\par
}
\begin{document}
\basesizes
Here is the \verb|\zleft| method which smashes the test box.
$y = \zleft( x^2 + 3\right)$
And now for the next test:
$y = \zleft(\frac{a}{b}\right)$
Finally:
$y = 3\zleft(\frac{\zleft( x^2 + 3\right)}{b}\right)$
\end{document}


• Oh, beautiful! I was kind of focused on measuring the height of the box and converting that to \big, \Big, ... - but just putting all of them next to the group is just as good. Thank you! – bers Jun 14 '17 at 11:59
• @bers I have added an addendum, if you prefer the dimension-based approach. – Steven B. Segletes Jun 14 '17 at 12:19
• @bers I don't know how best to handle that situation to that level of precision. I would likely just choose the next size up. One option, which would be a pain to recode your equations, would be to choose the closest big size and place it inside of the \scaleleftright or \stretchleftright macro (scalerel package), as in $a^{ \scaleleftright{(}{\mathstrut x^2}{)} }$. – Steven B. Segletes Jun 14 '17 at 14:13
• @bers See $a^{ ( x^2 ) } + a^{ \left( x^2 \right) } + a^{ \scaleleftright{(}{\mathstrut x^2}{)} }$ – Steven B. Segletes Jun 14 '17 at 14:18
• – Steven B. Segletes Jun 14 '17 at 14:25