I have nearly finished writing my ph.d. thesis, and throughout I've been using regular parenthesis mostly, for everything math. Now, I'd like to replace all instances of (...) by their \left(...\right) variant. This is quite an immense task to do manually.

The best I've been able to come up with is a regular expression that finds all pairs of parentheses that do not have the \left and \right prefix, and then check manually and replace accordingly.

Surely this community must be able to come up with a better solution?

  • 4
    A query up front: Why would you want to do this? If you're not sure, I suggest you search this site for postings as to why it's actually a poor idea to use \left and \right everywhere. – Mico Aug 23 '15 at 8:59
  • Mico has already pointed out that this might not be the best of ideas (see, amongst others, “(” or “\left(” parentheses?, Spacing around \left and \right), but it certainly is not impossible Macro for \left( and \right). – moewe Aug 23 '15 at 9:14
  • As Mico says, this is a very bad idea. For example autoscalling easily disturbs line spacing when used in the text. In the wrong hands they will overpower a displayed expression, plus they cannot be broken across lines. – daleif Aug 23 '15 at 9:15
  • 1
    I tend to use the following rule : it should be clear to the reader, what is being fenced in. But not to such an extent that the fences takes focus in the expression. – daleif Aug 23 '15 at 9:16
  • 2
    @MartinLauridsen - Not only should you only consider applying \left and \right only if the size of the parentheses isn't "right" (or "looks dumb", as you put it), you should consider using explicit sizing instructions (such as \bigl(, \Bigr|, \biggl[ and \Biggr\} instead of hoping that \left and \right will somehow "get it right". – Mico Aug 23 '15 at 10:04

Warning: The following answer will not help you achieve your stated goal. Instead, it is meant to convince you to abandon your plan, by showing that using \left( and right) everywhere in math mode is bound to produce poor typographic results.

Incidentally, while you mentioned round parentheses in your posting, I assume you also want to include square brackets, curly braces, angle brackets, vertical bars, and all other (typographic) "fences" in this exercise.

In addition to needing to be aware of three obvious, major typographic issues that tend to arise when using \left and right everywhere -- the resulting fences may be too large; the resulting fences may be too small; and the spacing around the fences may be too wide -- you also need to be aware of problems that arise in inline-math cases. Basically, TeX does not insert a line break inside a term delimited by \left and \right; this can easily cause massively overfull lines. Moreover, TeX cannot adjust the spacing around binary and relation operators (such as + and =) if the formula is delimited by left and \right; this, too, may easily cause overfull lines.

Consider the following code

\usepackage[textwidth=1mm]{geometry} % choose a very narrow text block
\setlength\parindent{0pt}            % just for this example




which generates the following output:

enter image description here

For the first two formulas, which do not contain \left and \right directives, LaTeX was able to find three potential line breaks. In contrast, the third formula, which contains three \left( and three \right) directives, not a single line break was "found", despite the fact that one \allowbreak statement is present. If such a formula occurs anywhere near the right-hand edge of the text block, an overfull line will almost certainly result. Incidentally, in addition to the non-presence of line breakpoints, the \left(\left(a+b\right)\allowbreak\left(c+d\right)\right) formula features two additional defects: The outer parentheses are not any larger than the inner ones, and the space between the inner parentheses is excessive.

Do study the fourth formula as well: Not only does it not feature a line break after the + symbol, the spacing around the + symbol isn't reduced (because TeX isn't allowed to do so inside a \left...\right construct!). As a result, this formula too has the potential to generate an overfull line, whether the formula occurs at the right-hand edge of the text block or somewhere in the interior of the line.

  • 1
    Thanks for this very fulfilling answer (which I've marked). So I will basically go over the document and where things look OK I won't change anything. Where it looks bad, I'll find some solution. – Martin Lauridsen Aug 23 '15 at 11:43
  • @MartinLauridsen - I'd say your (revised) plan looks perfect. – Mico Aug 23 '15 at 12:04
  • Just as an additional question. I guess it is a matter of style, but say I write O(2^{n/2}) in inline text. The parentheses do not cover totally the top. Should I use \bigl \bigr in such a case? – Martin Lauridsen Aug 23 '15 at 12:33
  • @MartinLauridsen - If it's in inline-math material, I'd leave the parentheses at their basic size, i.e., to leave O(2^{n/2}) as is. However, if you have enough time and energy to make the changes, I suppose O\bigl(2^{n/2}\bigr) isn't wrong either. – Mico Aug 23 '15 at 13:20
  • Thanks again, @Mico. I've noticed that many times, using e.g. \bigl over \left makes the horizontal spacing to whatever came before slightly diminished. For example, I would before have \Pr\left[ ... \right], but replacing this by \Pr\bigl[ ... \bigr] makes the "Pr" stand very close to the [. What is your take on this? – Martin Lauridsen Aug 23 '15 at 20:11

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.