2

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

Don´t ask me details about, I am not into them.

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.

Thanks for your help!

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}
Niklas
  • 642
  • 4
  • 13

1 Answers1

7

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!

enter image description here

\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}
David Carlisle
  • 757,742