[Tex/LaTex] Automatic left and right commands

bracketsmath-mode

Is it possible to automatically "add" \left and \right commands in front of all brackets? The source code should be left intact, but LaTeX should interpret every pair of brackets as if they were preceded by such commands. This is because adding \left and \right commands is time consuming and makes source code longer and less readable. I considered defining new commands such as \lb and \rb for \left( and \right), but it doesn't seem very elegant to me: what if I also want to add square brackets for example?

Any ideas? Thanks.

Best Answer

The \DeclarePairedDelimiter command from mathtools is useful. For example defining an absolute value macro;

\DeclarePairedDelimiter\abs{\lvert}{\rvert}

gives also a starred version with \left and \right

\abs*{\frac{a}{b}}

and the unstarred version takes an optional argument that can be \big, \Big, etc

\abs[\Bigg]{\frac{a}{b}}
Related Question