# Active Delimiters to get correct delimiter size

I once read in "Die Texnische Komödie 1/2011" that it is possible to make the round delimiters () active, so you don´t need do use \left(\right) any more. The code is:

\makeatletter
\def\resetMathstrut@{%
\setbox\z@\hbox{%
\mathchardef\@tempa\mathcode\[\relax
\def\@tempb##1"##2##3{\the\textfont"##3\char"}%
\expandafter\@tempb\meaning\@tempa \relax
}%
\ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}
\makeatother
\begingroup
\catcode(\active \xdef({\left\string(}
\catcode)\active \xdef){\right\string)}
\endgroup
\mathcode(="8000 \mathcode)="8000
\setlength\delimitershortfall{-1pt}

\makeatletter
\catcode\_\active
\def_#1{\sb{\operator@font#1}}
\makeatother


Now I wonder if it is possible to change [] and maybe \{\} the same way, so that you don´t need to use \left...\right... any more for "normal" delimiters.

MWE:

\documentclass{scrartcl}
\usepackage{amsmath}
\makeatletter
\def\resetMathstrut@{%
\setbox\z@\hbox{%
\mathchardef\@tempa\mathcode\[\relax
\def\@tempb##1"##2##3{\the\textfont"##3\char"}%
\expandafter\@tempb\meaning\@tempa \relax
}%
\ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}
\makeatother
\begingroup
\catcode(\active \xdef({\left\string(}
\catcode)\active \xdef){\right\string)}
\endgroup
\mathcode(="8000 \mathcode)="8000
\setlength\delimitershortfall{-1pt}

\makeatletter
\catcode\_\active
\def_#1{\sb{\operator@font#1}}
\makeatother

\begin{document}
\begin{align}
((((a+b)(a-b))))=a^2-b^2
\end{align}
\end{document}

• generally it's not recommended to over-use \left and \right you often get better spacing if you choose the size explictly (\big( etc. Oct 5 '14 at 14:12
• In addition to redefining ( the code shown makes all subscripts use an upright font?? Oct 5 '14 at 14:15
• Yeah^^ I wanted this feature too, but it is not needed in the code here. You see, I am not into it. Oct 5 '14 at 14:17
• It is needed to use it with the amsmath package. Why is written in the "TeXnische Komödie" Oct 5 '14 at 14:20
• I just wanted to comment to thank you because your post gave me what I needed to finally answer my own question satisfactorily (compared with David's answer that just says it's not a good idea). =) Feb 20 at 14:50

You can just repeat the definitions used for ( with [ but really you should not do this, the setting with \delimitershortfall and over use of \left and \right is producing a really poor setting with over large delimiters and over large horizontal space. Automating this layout ought to be a non-aim!

\documentclass{scrartcl}
\usepackage{amsmath}
\makeatletter
\edef\zzz{\the\mathcode\[}
\def\resetMathstrut@{%
\setbox\z@\hbox{%
\mathchardef\@tempa\zzz\relax
\def\@tempb##1"##2##3{\the\textfont"##3\char"}%
\expandafter\@tempb\meaning\@tempa \relax
}%
\ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}
\makeatother

\begingroup
\catcode(\active \xdef({\left\string(}
\catcode)\active \xdef){\right\string)}
\endgroup
\mathcode(="8000 \mathcode)="8000

\begingroup
\catcode[\active \xdef[{\left\string[}
\catcode]\active \xdef]{\right\string]}
\endgroup
\mathcode[="8000 \mathcode]="8000

\setlength\delimitershortfall{-1pt}

\begin{document}

\begin{align}
((((a+b)(a-b))))=a^2-b^2 \\ \relax
[[[[a+b][a-b]]]]=a^2-b^2
\end{align}
\end{document}
`
• Okay, so it is possible, but makes no sense. Thank you. Oct 5 '14 at 15:08