16

This question led to a new package:
fixcmex

While writing down my Combinatorics exercises I found that the binomial coefficient's delimiters weren't displayed as indicated inside the amsmath documentation.

By subsequent trials and errors I was able to reduce the volume of my document to this simpler and fully compilable MWE:

\documentclass[11pt]{article}
%
\usepackage{amsmath}
%
\makeatletter
%
\usepackage{lmodern}
\usepackage{lipsum}
%
\makeatother
%
\begin{document}
%
\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]
%
\end{document}

Which gives (using TeXworks 0.44 on MikTeX 2.9.4521 updated 09/10/13) this un-expected result:

enter image description here

While the amsmath doc shows that with the loaded packages inside the MWE the result would actually be like this:

enter image description here

From here we can see that the delimiters on the first example are a little bit stretched vertically as they surpass the arguments inside the binom. coeff.

The more strange event is that when I comment the line \usepackage{lmodern} the result on delimiter's shape in my example looks exactly as the amsmath doc:

\documentclass[11pt]{article}
%
\usepackage{amsmath}
%
\makeatletter
%
%\usepackage{lmodern}
\usepackage{lipsum}
%
\makeatother
%
\begin{document}
%
\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]
%
\end{document}

Output:

enter image description here

From here I deduce that the problem lies inside lmodern, but I'd like to keep using this package and fix this wierd "issue" with the math mode. Is there some clue that I've missed or this is in fact an update-process bug infecting amsmath's delimiter control?

  • Just a note: you don't need \makeatletter \makeatother in this MWE. – marczellm Oct 9 '13 at 16:18
  • @marczellm Yes, it works fluently both with and without those commands, as there is no @ in between that needs to be activated... – alandella Oct 9 '13 at 16:23
17

This is a problem in how lmodern sets up the math extensions font, by saying

\DeclareFontShape{OMX}{lmex}{m}{n}{%
   <->sfixed*lmex10%
   }{}

which is utterly wrong, in my opinion, because it destroys the settings made by amsmath which would solve the problem. The fonts, unfortunately, do not provide for optical sizes different from 10pt, so you have a few strategies

Let amsmath do the main work

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{lmodern}

\DeclareSymbolFont{largesymbols}{OMX}{cmex}{m}{n} % use cmex rather than lmex

\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]

\end{document}

Load exscale or, better, the fonts defined by it

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{lmodern}

\DeclareFontShape{OMX}{cmex}{m}{n}{%
      <-7.5> cmex7
      <7.5-8.5> cmex8
      <8.5-9.5> cmex9
      <9.5-> cmex10
       }{}
\DeclareSymbolFont{largesymbols}{OMX}{cmex}{m}{n} % use cmex rather than lmex

\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]

\end{document}

Make lmex10 scalable

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{lmodern}
\DeclareFontFamily{OMX}{lmex}{}
\DeclareFontShape{OMX}{lmex}{m}{n}{%
   <-> lmex10
   }{}

\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]

\end{document}

With all strategies the computation for the delimiter's sizes gives a better result. Strategy one and two are rather similar; the difference is that the second one scales all fonts even at non standard sizes, while the first uses only fixed sizes 7, 8, 9, 10, 11 (10.95), 12, 14 (14.4) and 17 (17.28).

enter image description here

  • I honestly didn't come up with this strange issue in one and a half years of intense LaTeXing, but is it possible to a simple user like me to point this out to a mantainer? – alandella Oct 9 '13 at 15:14
  • 1
    @AndreaL. Probably you never used 11pt as base font size. Omit the fix and try $A_{\sum}$ first without lmodern and then with it (load amsmath in both experiments). You'll have a surprise. – egreg Oct 9 '13 at 15:43
  • Thanks, I personally think that the second method shown in the answer is the most appropriate to my purposes. I'll think on the usage of stackengine (as given by @StevenB.Segletes) in addendum. – alandella Oct 9 '13 at 15:45
6

This answer relies on redefining \binom to use features of the scalerel and stackengine packages. The \scaleleftright macro will make the paren delimiters exactly match the height of the binomial contents, which are stacked using \stackanchor.

The vertical gap between the components of the binomial coefficient is an optional argument to \stackanchor (currently set at 1.8ex), and the horizontal limiting width of the parens of the coefficient are given as an optional argument to \scaleleftright (currently set to 1.5ex).

\documentclass[11pt]{article}
%
\usepackage{amsmath}
\usepackage{scalerel}
\usepackage{stackengine}
%
\makeatletter
%
\usepackage{lmodern}
\usepackage{lipsum}
%
\makeatother
%
\begin{document}
%
\lipsum[1]
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\renewcommand\binom[2]{\stackMath\mathop{%
  \scaleleftright[1.5ex]{(}{\stackanchor[1.8ex]{#1}{#2}}{)}}}
\begin{equation}
2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}
\end{equation}
\lipsum[1]

%
\end{document}

The top image is the original that you posted, while the lower one is the fix proposed here.

enter image description here

  • Even though egreg made an answer that matched the delimiter size exactly with amsmath doc, I kind of like the vertical shrinking, just aligned at the base of the argument. Now I have two possibilities, which is great. – alandella Oct 9 '13 at 15:50
  • @AndreaL. Thanks. The current MWE uses a "short" stack for the coefficient parts, wherein the gap is specified, and the stack is centered at the middle of the gap. You may prefer a "long" stack wherein the inter-baseline distance is specified and the stack is centered halfway between the baselines. To do that, \renewcommand\binom[2]{\stackMath\def\stacktype{L}\mathop{% \scaleleftright[1.5ex]{(}{\stackanchor[1.1\baselineskip]{#1}{#2}}{)}}} . You'll see differences for short letters in the upper slot and/or descending letters in the lower slot. – Steven B. Segletes Oct 9 '13 at 16:02
  • @AndreaL. As a follow up to prior comment, I should add that if differing heights/depths of indices over several terms within a single equation cause an odd look, a partial strut can be added in \binom before #1 and #2 in order to normalize the heights. – Steven B. Segletes Oct 9 '13 at 16:15
  • Well, thanks for the delucidation, the more tools and methods the more a knowledge is spread. – alandella Oct 9 '13 at 16:21
  • @StevenB.Segletes I am very happy with your answer, But, it does not sutiable with \usepackage{fouriernc}. Can you help me with when I add the command \usepackage{fouriernc}? – minthao_2011 Dec 8 '15 at 3:49

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.