8

\left and \right are convenient but sometimes they're a bit overeager in stretching the parentheses. In that case we can manually use \bigl, \Bigl, etc.

I have defined a new command like this

\newcommand{\avg}[1]{\ensuremath{\left\langle #1 \right\ranlge}}

I would like this command to have automatic stretching, but I don't want this mechanism to kick in too early. With this definition, \avg{x^2} already has bigger brackets than \avg{x}. I would prefer not to use stretching at this level at all. I would, however, like it to use stretching for \avg{\frac{x}{2}} in display mode. Something like this would be nice: 1. don't stretch at all in inline math 2. do stretch as normal above a certain size threshold in display math, but not below this threshold.

Is there an easy way to implement this? Perhaps it's less trouble to use \left\langle ... \right\rangle manually when I really need stretching.

  • Possible duplicate: Sloppy \left and \right? – Werner May 13 '13 at 4:54
  • 1
    @Werner It's not a duplicate. I can accept "this is too much trouble to do" as an answer, but note that I did mention \bigl et al in the question. This question is about how to set a size threshold for automatic resizing below which brackets are not resized at all. – Szabolcs May 13 '13 at 5:44
6

enter image description here

You can set \delimiterfactor to delay the start of stretching, however even if the brackets don't stretch, \left \right makes a math inner atom which affects the horizontal spacing (and prevents linebreaking).

(plain tex)

\def\x#1{\left({\vrule height#1pt}_{#1}a+b\right)}

$\x{08}\x{10}\x{12}\x{14}\x{16}\x{20}\x{24}$

{\delimiterfactor400
\delimitershortfall\maxdimen
$\x{08}\x{10}\x{12}\x{14}\x{16}\x{20}\x{24}$
}

\def\x#1{({\vrule height#1pt}_{#1}a+b)}
$\x{08}\x{10}\x{12}\x{14}\x{16}\x{20}\x{24}$

\bye

In a real example you would set \delimitershortfall to a smaller length to stop the brackets getting too small, set to \maxdimen here to highlight the effect.

6

Here is a fairly naive solution that has not been extensively tested:

enter image description here

\documentclass{article}
\usepackage{mathstyle}% http://ctan.org/pkg/mathstyle
\usepackage{multido}% http://ctan.org/pkg/multido (just for this example)
\makeatletter
\newcommand{\getmathstyle}{% https://tex.stackexchange.com/a/78874/5764
  \global\edef\curmathstyle{%
    \expandafter\@gobble\mathchoice{\@@displaystyle}{\@@textstyle}{\@@scriptstyle}{\@@scriptscriptstyle}}
}
\makeatother
\let\oldleft\left
\def\left#1#2\right#3{
  \getmathstyle\sbox0{$\curmathstyle#2$}
  \ifdim\ht0<20pt\relax
    #1#2#3
  \else
    \oldleft#1#2\right#3
  \fi
}
\begin{document}

$\multido{\i=10+2}{10}{
  \begin{array}{c}
    \texttt{\i pt} \\
    \left(\rule{1pt}{\i pt}\right)%
    \rule[-30pt]{0pt}{60pt}% Add a strut for visual clarity
  \end{array}
}$

\end{document}

The threshold for switching to the regular \left...\right usage is 20pt (changeable, of course). I'm not comfortable dealing with TeX primitives, so use of this solution is heavily cautioned.

The choice of math style capture is taken from How to capture the current math style?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.