[Tex/LaTex] Redefining brackets

delimitersmacros

In my thesis I'm working with a lot of brackets around fractions and every time I have to use
\left( \frac{a}{b} \right). It can get really confusing if i have a long equation and a lot of fractions.

Is there a way to redefine ( such that every time I type (, it automatically gets interpreted as \left(?

I tried to redefine it as a macro, but it doesn't seem to work with brackets.

Thank you for your suggestions.

Best Answer

Redefining the meaning of the parentheses, ( and ), may be rather dangerous since they can occur in so many contexts, even in math material. There may also be situations where you would not want the parentheses to be enlarged automatically.

Rather than redefining the meaning of the parentheses, you may want to consider defining a new macro called, say, \pfrac (short for "parenthetical fraction", I suppose) that encloses the fraction expression automatically in auto-sized parentheses:

\newcommand{\pfrac}[2]{\left( \frac{#1}{#2} \right)}

This will let you write expressions such as \pfrac{1}{2}. Observe that this is marginally simpler (and, importantly, less prone to "accidents" caused by omitted opening and/or closing parentheses) than writing (\frac{1}{2}).

If you go this route, i.e., have lots and lots of fractional expressions encased in auto-sized parentheses, I would recommend you also load the mleftright package and issue the command \mleftright in the preamble. Doing so gets rid of the extra space inserted in various situations by \left and \right.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\pfrac}[2]{\left(\frac{#1}{#2}\right)}
\usepackage{mleftright}
\mleftright
\begin{document}
\[ 
\pfrac{1}{2} \pfrac{3}{4} \pfrac{5}{6} 
\textstyle \pfrac{1}{2} \pfrac{3}{4} \pfrac{5}{6} 
\]
\end{document}

Addendum, prompted by a comment by egreg: One could also utilize the macro \genfrac of the amsmath package to define a fraction macro that automatically surrounds its contents with a pair of parentheses. For instance, one could define

\newcommand{\qfrac}[2]{\genfrac{(){)}{}{}{#1}{#2}}

Substituting this macro in place of \pfrac in the MWE above yields:

enter image description here

One notes that the parentheses are now set very close to the fraction expressions. You may (or may not) prefer this look to that produced by the \pfrac macro given above.

Related Question