Universal Parentheses

Making ( active is not really a solution because it is used in so many other ways, but here is how it would be done.

To help in this regard. I create \pactive to make ( active which, if used inside a group like an equation, can revert ( to its normal definition after the group is closed.

\documentclass{article}
\let\svlp(
\catcode`(=\active %
\def(#1){\left\svlp#1\right)}
\catcode`(=12 %
\newcommand\pactive{\catcode`(=\active }
\begin{document}
\[
\pactive
\deg(m_{\alpha_{1}/K}) + (\frac{a}{x+c})
\]
Normal use of ( or even \fbox{\makebox(20,30){test}}
\end{document}

enter image description here

The OP asks about automating the invocation of \pactive. Again, I don't recommend it, because there may be need in math mode to use the () set as an argument to some macro. But the use of

\everymath{\pactive}
\everydisplay{\pactive}

will accomplish it:

\documentclass{article}
\let\svlp(
\catcode`(=\active %
\def(#1){\left\svlp#1\right)}
\catcode`(=12 %
\newcommand\pactive{\catcode`(=\active }
\everymath{\pactive}
\everydisplay{\pactive}
\begin{document}
\[
%\pactive
\deg(m_{\alpha_{1}/K}) + (\frac{a}{x+c})
\]
Normal use of ( or even \fbox{\makebox(20,30){test}}

\(
%\pactive
\deg(m_{\alpha_{1}/K}) + (\frac{a}{x+c})
\)
Normal use of ( or even \fbox{\makebox(20,30){test}}
\end{document}

enter image description here

Thanks to Timm for reminding that, if one really wants to automate this, then one should have handy the override macro

\newcommand\pinactive{\catcode`(=12 }

An easy solution would just be to use the qty command from the physics package. Here's a MWE:

\documentclass{article}
\usepackage{physics}
\begin{document}
With \texttt{qty}:
\[
\qty(m_{\frac\alpha\beta}) + \qty(\frac{1}{x+y}) + \qty(\int^{\infty}_{0} x^2 \dd{x})
\]

Without \texttt{qty}:
\[
(m_{\frac\alpha\beta}) + (\frac{1}{x+y}) + (\int^{\infty}_{0} x^2 \dd{x})
\]
\end{document}

with and without qty


It's definitely a bad idea, but if you really want to get ugly documents, here it is. ;-)

\documentclass{article}

\newcommand{\extlparen}{\left\delimiter"4028300 }
\newcommand{\extrparen}{\right\delimiter"5029301 }
\begingroup\lccode`~=`( \lowercase{\endgroup\let~}\extlparen
\begingroup\lccode`~=`) \lowercase{\endgroup\let~}\extrparen

\AtBeginDocument{\mathcode`(="8000 \mathcode`)="8000 }

\begin{document}
\[
\deg(m_{\alpha_{1}/K})+(\sum_{i=1}^n i^2)
\]
\end{document}

enter image description here

The same with proper markup:

\[
\deg(m_{\alpha_{1}/K})+\biggl(\,\sum_{i=1}^n i^2\biggr)
\]

enter image description here

The parentheses are much better in the second case than in the top one.

Tags:

Brackets