wspr / breqn

Automatic line breaking in LaTeX equations
18 stars 2 forks source link

missing number error with \binom #42

Closed u-fischer closed 4 years ago

u-fischer commented 4 years ago

This here fails

\documentclass{article}
\usepackage{breqn}
\begin{document}
 $\binom{n}{2k}$ 
\end{document}

with

! Missing number, treated as zero.
<to be read again> 

My guess is that the right fix is to insert #4 into the genfrac definition:

\DeclareRobustCommand\genfrac[6]{%
  {#1\fracstyle
    {\begingroup #5\endgroup
      \csname @@\ifx\maxdimen#4\maxdimen over\else above\fi
        \if @#2@\else withdelims\fi\endcsname #2#3#4\relax %<--#4 inserted
     #6}%
  }%
}
wspr commented 4 years ago

Hmmm, that is @eg9's fault due to #25: https://tex.stackexchange.com/a/456215/179

Clearly I need more test files! I guess \binom needs to be patched too.

u-fischer commented 4 years ago

Hm. @eg9 use of \genfrac in the answer looks wrong

Argument #2 and #3 in the new genfrac are the delimiters, so if there are no delimiters, they should be both empty and the command should start with \genfrac{}{}{}.

u-fischer commented 4 years ago

I think you will have to patch \splitfrac from the mathtools package.

\renewcommand*\splitfrac[2]{%
  \genfrac{}{}{}{0pt}%
    {\textstyle#1\quad\hfill}%
    {\textstyle\hfill\quad\mathstrut#2}%
}
wspr commented 4 years ago

I am a bit confused. In mathstyle.dtx:

\renewcommand{\binom}{\genfrac{}(){0pt}}
\renewcommand{\dbinom}{\genfrac\displaystyle(){0pt}}
\renewcommand{\tbinom}{\genfrac\textstyle(){0pt}}

In amsmath.sty:

\DeclareRobustCommand{\binom}{\genfrac()\z@{}}
\newcommand{\dbinom}{\genfrac(){0pt}0}
\newcommand{\tbinom}{\genfrac(){0pt}1}

I'm reading this right that mathstyle screws up the order of the arguments. I need to re-add the missing #4 but most importantly redo the logic so it is backwards compatible (I don't want to start patching other packages...)

u-fischer commented 4 years ago

I'm reading this right that mathstyle screws up the order of the arguments.

It is changing it, that's what I think too. But I'm not sure if you can remedy it while keeping the name \genfrac and the number of arguments (in amsmath it has four arguments, and in mathstyle six) and not clashing with other package trying to use \genfrac.

u-fischer commented 4 years ago

looks good. I checked also the splitfrac example and it works fine now.

eg9 commented 4 years ago

Sorry, I don't understand. The bug was having #4 in that position.

eg9 commented 4 years ago

@u-fischer

Hm. @eg9 use of \genfrac in the answer looks wrong

No. The patch works as advertised. If Will wants to fix it differently, it's another pair of shoes.

wspr commented 4 years ago

@eg9 — I shouldn’t have said it was your fault! Definitely not.

Root cause of both problems was mathstyle had a whacky order of arguments and used different syntax for setting the mathstyle. Both fixed now.