Spacing around \left and \right

I've found an answer in a usenet post by Heiko Oberdiek and another by Donald Arseneau. Improved code thanks to shiznick.

The issue is that \left and \right introduces an inner atom (see The TeXbook, chapter 18, section 4), which has different spacing rules than ordinary atoms, produced by ( and ) (and the other delimiters).

To remove this spurious spacing, one has to manually insert opening and closing atoms in the formula. Specifically, $\cos(\theta)$ and $\cos\mathopen{}\left(\theta\right)\mathclose{}$ render exactly the same.

However, inserting it does make your formulas ugly. So a good solution would be to just redefine \left and \right:

\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}

Incidentally, this code also fixes the spacing of |, that is very fragile. Check for example $|+x|$ and $\left|+x\right|$. Also $\cos|\theta|$ and $\cos\left|\theta\right|$. This is due to the fact that both delimiters are equal, and TeX doesn't know if they're opening or closing the expression. The same logic applies to \|.

EDIT: The old code had a problem with subscripts and superscripts: they didn't accompany the growth of the delimiters. Fixed now thanks to Philipp Stephani and Heiko Oberdiek.


The package mathtools has implemented a general solution for that problem. It defines the command \DeclarePairedDelimiter that you can use as follows: \DeclarePairedDelimiter\parentheses{\lparen}{\rparen}.

With this single declaration you have a new powerful command for several cases:

  • \parentheses{x} just replaces $(x)$
  • \parentheses*{x} will do the right thing with \left and \right (same result as the answer of Mateus Araújo)
  • \parentheses[\big]{x} which replaces $\bigr(x\bigl)$ (all the size commands work)

The following code fixes both \left and \right -- put it in the preamble:

\let\originalleft\left
\let\originalright\right
\def\left#1{\mathopen{}\originalleft#1}
\def\right#1{\originalright#1\mathclose{}}

I haven't tested it in all scenarios, of course, but I added it to the preamble of my entire Ph.D. dissertation, and it worked without errors and without any additional modifications to the code.