3

In the following example, why does the word Spam appear four timestimestimestimes?

$ cat mwe.tex 
\documentclass{beamer}
\usepackage{breqn}
\newcommand{\spam}{\textrm{Spam}}
\begin{document}
\begin{frame}
\[ \spam \]
\end{frame}
\end{document}

Resulting PDF converted to PNG

...and what can I do to get it just once?

I'm using:

  • LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238),
  • beamer 2015/01/05 3.36,
  • breqn 2015/08/11 v0.98d.
gerrit
  • 5,165

1 Answers1

4

The problem is triggered, if the redefinition of \mathchoice in package mathstyle meets LuaTeX's \mathstyle, from package mathstyle:

\def\mathchoice{%
  \relax\ifcase\mathstyle
    \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
}

\ifcase expects a number and continues the expansion until a token is found, which does not contain to a number (non-digit). Thus the first \expandafter of case "0" for "display style" is called at the wrong time, when the number is still being read. A \relax stops that and should fix the issue:

\documentclass{beamer}
\usepackage{breqn}

\makeatletter
\def\mathchoice{%
  \relax\ifcase\mathstyle\relax
    \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

\newcommand{\spam}{\textrm{Spam}}
\begin{document}
\begin{frame}
\centering

$\displaystyle \mathchoice{D}{T}{S}{s}$

\[ \spam \]
\end{frame}
\end{document}

Result

Heiko Oberdiek
  • 271,626