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}
5
  • 3
    generally it's not recommended to over-use \left and \right you often get better spacing if you choose the size explictly (\big( etc. Commented Oct 5, 2014 at 14:12
  • In addition to redefining ( the code shown makes all subscripts use an upright font?? Commented Oct 5, 2014 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.
    – Niklas
    Commented Oct 5, 2014 at 14:17
  • It is needed to use it with the amsmath package. Why is written in the "TeXnische Komödie"
    – Niklas
    Commented Oct 5, 2014 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). =)
    – user21820
    Commented Feb 20, 2021 at 14:50

1 Answer 1

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}
1
  • Okay, so it is possible, but makes no sense. Thank you.
    – Niklas
    Commented Oct 5, 2014 at 15:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .