1

How can I define a macro (or macros) that works in an automatic way like the primitives \left and \right, but does not consider the space below or above operators like \sum or \bigcup?

This modified left and reight \mleft/\mright should work like \[\Bigl(\sum_i^j\Bigr)\] if the input is \[\mleft(\sum_i^j\mright)\], whereas the original \left/\right produces \[\Biggl(\sum_i^j\Biggr)\].

While I already have a solution (s.b.), it has some caveats and there might be a better approach.

1
  • Have a look at nath package
    – Aditya
    Dec 3, 2017 at 3:29

1 Answer 1

1

The following macro \lrm works by first using a \vphantom with the actual content of the parentheses to get the correct overall line height. Then it calls \left and creates another \vphantom, but this time it changes the catcodes and redefines ^ and _ to mean \relax. Finally it actually outputs the content within a \smash just before the call to \right. Because of \smash the line height does not increase.

\begingroup
\catcode`_=\active
\catcode`^=\active
\gdef\lrm#1#2#3{%
 \vphantom{#2}%
 \left#1%
 \vphantom{
   \begingroup
   \def\sb##1{\relax}%
   \def\sp##1{\relax}%
   \def_##1{\sb{##1}}%
   \def^##1{\sp{##1}}%
   \catcode`_=\active
   \catcode`^=\active
   \scantokens{ #2\endinput}%
   \endgroup
  }
  \smash{#2}
  \right#3%
}

\gdef\mleft#1#2\mright#3{\lrm{#1}{#2}{#3}}
\gdef\mmleft#1#2\mmright#3{\lrm{#1}{#2}{#3}}
\gdef\mmmleft#1#2\mmmright#3{\lrm{#1}{#2}{#3}}
\endgroup

This solutions has some caveats:

  • Sub- and superscripts within macros are not detected (\expandonce within the \scantokens helps, but would break most nested applications).
  • \mleft/\mright cannot be nested, but nesting \lrm is possible.
  • \scantokens requires eTeX (i.e. pdftex,luatex,xetex ...).
  • If used for parentheses surrounding a fraction with two sums, the resulting parentheses may look too small.

You must log in to answer this question.

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