18

MWE needs to be compiled with LuaTeX to reproduce the problem:

\documentclass[11pt]{report}%
\usepackage{amsmath,mathtools}
\usepackage{breqn}                         
\begin{document}
$J^{\ast} = \text{JFK} \to \text{NO} \to \text{SFO}$
\[
J^{\ast} = \text{JFK} \to \text{NO} \to \text{SFO}
\]
\end{document}

Gives (no compile error or any warning) the following strange output

Mathematica graphics

I have to use breqn package. If I remove it, then I get the expected output

Mathematica graphics

Is there a way to work around this, so I can use breqn and get correct output?

TL 2015. filelist: (compiled with lualatex)

This is LuaTeX, Version beta-0.80.0.1 (TeX Live 2015) (rev 5863)

 *File List*
  report.cls    2014/09/29 v1.4h Standard LaTeX document class
  size11.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
 amsmath.sty    2013/01/14 v2.14 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
mathtools.sty    2015/11/12 v1.18 mathematical typesetting tools
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
    calc.sty    2014/10/28 v4.3 Infix arithmetic (KKT,FJ)
 mhsetup.sty    2010/01/21 v1.2a programming setup (MH)
   breqn.sty    2015/08/11 v0.98d Breaking equations
   expl3.sty    2015/12/20 v6326 L3 programming layer (loader) 
expl3-code.tex    2015/12/20 v6326 L3 programming layer 
l3pdfmode.def    2015/11/11 v6250 L3 Experimental driver: PDF mode
flexisym.sty    2015/08/11 v0.98d Make math characters macros
  cmbase.sym    2007/12/19 v0.92
mathstyle.sty    2015/08/11 v0.98d Tracking mathstyle implicitly
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
luatex-loader.sty    2010/03/09 v0.4 Lua module loader (HO)
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 ***********

Update

I found another case of duplication when using breqn, which does not involve \text at all. But the solution provided below also fixes this issue. I am adding this second case here for reference just in case it might be useful. Here is MWE

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath,mathtools}
\usepackage{breqn}
\begin{document}
\[
\underset{\mathbf{S}} {\operatorname{arg\,min}}  
   \sum_{i=1}^{k} \sum_{\mathbf x \in S_i} 
     \left\| \mathbf x - \boldsymbol\mu_i \right\|^2 
\]
\end{document}

The output is

Mathematica graphics

After adding the patch in the answer below the correct output is now given, which is

Mathematica graphics

  • Strange, I failed to reproduce the error. Ubuntu 15.10. – Masroor Apr 9 '16 at 1:36
  • Problem is LuaTeX specific. Is pdfTeX an option? Or XeTeX? Those both work. Note that I'm not denying this shouldn't happen. But if you need a workaround. – cfr Apr 9 '16 at 1:45
  • 2
    I can also reproduce your error (mactex2015 system). I've edited the title of your posting since each argument of \text is actually quadrupled, not tripled: What's going on -- no idea why! -- is that all four possibilities of \mathchoice -- displaystyle, textstyle, scriptstyle, and scriptscriptstyle -- are being generated, and not just textstyle. – Mico Apr 9 '16 at 3:13
  • 2
    Interestingly, your MWE crashes (with a nearly incomprehensible error message) if the unicode-math package is loaded as well. – Mico Apr 9 '16 at 3:22
  • 1
    A possible workaround is to use \mbox instead of \text when in display-math mode. Extremely tedious, for sure. – Mico Apr 9 '16 at 3:30
12

“Missing termination in the redefinition of \mathchoice made by mathstyle.sty (loaded by breqn):

\documentclass[11pt]{report}
\usepackage{amsmath,mathtools}
\usepackage{breqn}

\makeatletter
\def\mathchoice{%
  \relax\ifcase\numexpr\mathstyle\relax % <----- trailing \relax added
    \expandafter\@firstoffour % Display
  \or
    \expandafter\@firstoffour % Cramped display
  \or
    \expandafter\@secondoffour % Text
  \or
    \expandafter\@secondoffour % Cramped text
  \or
    \expandafter\@thirdoffour % Script
  \or
    \expandafter\@thirdoffour % Cramped script
  \else
    \expandafter\@fourthoffour % (Cramped) Scriptscript
  \fi
}
\makeatother

\begin{document}

$J^{\ast} = \text{JFK} \to \text{NO} \to \text{SFO}$
\[
J^{\ast} = \text{JFK} \to \text{NO} \to \text{SFO}
\]
\end{document}

enter image description here

Explanation: \mathstyle returns an integer, but doesn't stop the search for further digits. According to the manual of LuaTeX 0.95:

It is possible to discover the math style that will be used for a formula in an expandable fashion (while the math list is still being read). To make this possible, LuaTeX adds the new primitive: \mathstyle. This is a ‘convert command’ like e.g. \romannumeral: its value can only be read, not set.

Simple test, to compile with LuaTeX:

$\count255=\mathstyle 2\showthe\count255$\bye

issues, on the terminal,

> 22.
<to be read again> 
                   $
l.1 $\count255=\mathstyle 2\showthe\count255$

So the behavior is expected, even if strange. In order to properly terminate it in the context of a <number>

\numexpr\mathstyle\relax

should be used.

  • 1
    Wow, that's great detective work!!! You should bring this issue and the proposed solution to the attention of Hans Hagen and co., so that they can decide if (and how) to address this matter. – Mico Apr 9 '16 at 9:13
  • 1
    @Mico Hans explained the behavior in tug.org/pipermail/luatex/2016-April/005823.html and I updated my answer accordingly. – egreg Apr 9 '16 at 15:31
  • Many thanks for this update and providing a revised, thorough answer! – Mico Apr 9 '16 at 16:26
  • @Mico Yes, of course! – egreg Nov 19 '16 at 18:45

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.