2

In the MWE below, a pdflatex compilation (texlive 2020 and 2021) gives an error of type Extra \else.

The problem disappears

  • when I add an extra group around the \smash (e.g. {\smash{TTT}})
  • or if I add or subtract a couple of lines of text here and there in the body.

This last fact makes the issue very difficult to debug for me, since small changes may cause the problem to appear or disappear.

The tex source looks licit to me: I use a couple of well-known packages, define a header with a special value for the first page, and the body is only text with two wrapfigure environments. If there are no errors (please correct me if I'm wrong), I think that there might be some unexpected interaction between the packages around page breaks.

Any suggestion on how I should go on to debug this?

\documentclass{article}
\usepackage{wrapfig}
\usepackage{amsmath}

\makeatletter % Special header on first page \def\ps@mine{% \def@oddhead{% \ifnum\value{page}=1% \smash{TTT}% \else FFF% \fi}% } \makeatother

\pagestyle{mine}

\begin{document} hi \clearpage

Earum minus doloremque tempora aut et fugiat. Iste est in non asperiores. Laborum aut necessitatibus dolor aspernatur facilis fuga possimus. Alias ab quo laboriosam fugit sed voluptatem ut. In ut amet non facilis excepturi.

Ut libero velit vel voluptatem nulla. Et et et et cum id et. Harum nisi sit doloribus tempore quae occaecati. Est harum et nesciunt laborum rerum.

Odit magnam inventore explicabo doloribus enim asperiores provident. Aut ea nam non et nesciunt quasi quo. Inventore ut sed nulla et voluptatibus ullam dicta.

Odit magnam inventore explicabo doloribus enim asperiores provident. Aut ea nam non et nesciunt quasi quo. Inventore ut sed nulla et voluptatibus ullam dicta.

Odit magnam inventore explicabo doloribus enim asperiores provident. Aut ea nam non et nesciunt quasi quo. Inventore ut sed nulla et voluptatibus ullam dicta.

\begin{wrapfigure}{R}{0.5\textwidth} F1\vspace{2in} \end{wrapfigure} xxxxx xxxxxxxxx xxx xxxxxxxx xx xxx xxxxx xxxxxx xx xxx xxxxxxxxxx xxx xxx xx xxx xxxxxxx xx xxxxxx xxxx xxxx xxx xxxxxxx xxxxxxxx xxx xxxxxx xxxxx. Xxxxx xxxxxxx xxxxxxxx xxxxxxxxx xxxx xxxxx xxxx xx xxxx xxxxxxxxxx, xxxxx xxxx xxxxxxxxx. Xxx xxxx xxxxxxx xx xxx xxxxx xx xxxxxxx xxxxxxxxx, xxxxxxxxxx xx xxx-XxX xxxxxxxx xxx xxxxxxx xxxxx xxx xxxxx.

Xxxx, xxxx xxx xxxxxx xxxxx xxx xxx xx xx xxxxxxxxxxx xxxx xx xxx xx xxx xxxxxxxxxxxx xxxxx xxx. Xxxx xxxxx xxxxxxx xxxxxxxx xxxxxxx xxxxxxxxx xx xxxxxx xxxxxxxx xxxxx xxxx xxx xxxxxxx xxxxxx xxxxxx xxxxxxxx xxx xxxxxxxxxxx xxxxxxxx xxxxxxxxxx. Xxxxxxxxxxx xxxxxxxxx xxx xxxxxxxx xxxxxxxxxx xxx xx xxxxx xxxxxxxxxx xxxxxx xxxx x xxxx xxxxx xx xxxxxxxx, xxxx xxxx xx XxX xx xx xxxxxxxx xx XxX. Xxxxxxxxx xxx xxxxxxx xx xxxxxxxxxx xxx Xxxxx xxxxxxx xxxxxxxxxxx, xxxxx xxxxxxx x xxxx xxxxx xx xxxxxxxxxxx xxxxxxxxx xxxxxx xxxxxxxx xxx xxxxxxxx, xxxx xxxx xx xx

\begin{wrapfigure}{R}{0.5\textwidth} F2\vspace{2in} \end{wrapfigure} Quidem eum voluptates voluptatem fugiat et. Reprehenderit earum adipisci veritatis aut reprehenderit. Minus ab culpa quasi minima quia consectetur fuga aut.

Molestiae animi qui ab quo consectetur id saepe. Cumque eius blanditiis nobis reprehenderit. Voluptates temporibus necessitatibus odio adipisci ipsa. Quo quidem provident dignissimos iure id. Rem aut quas perferendis.

Earum minus doloremque tempora aut et fugiat. Iste est in non asperiores. Laborum aut necessitatibus dolor aspernatur facilis fuga possimus. Alias ab quo laboriosam fugit sed voluptatem ut. In ut amet non facilis excepturi.

Ut libero velit vel voluptatem nulla. Et et et et cum id et. Harum nisi sit doloribus tempore quae occaecati. Est harum et nesciunt laborum rerum.

\end{document}

David Carlisle
  • 757,742
Matteo Gamboz
  • 432
  • 3
  • 8
  • 2
    =1% should be =1 or =\@ne with the percent the \smash will expand before the test is made. – David Carlisle Sep 20 '21 at 14:01
  • 1
    Not tested, but my immediate reaction is that the % after the 1 in the \ifnum line can cause trouble because that causes TeX to keep looking for an additional numeric value, and \smash surely isn't numeric. Either insert a space before the % or get rid of it. – barbara beeton Sep 20 '21 at 14:02

2 Answers2

1

deleteing the % in

    \ifnum\value{page}=1%

so that it becomes

    \ifnum\value{page}=1

allows the number to be terminated and the test completed before \smash is expanded. With the % \smash gets expanded while the \ifnum is incomplete.

David Carlisle
  • 757,742
1

What happens with your code is that the constant that \value{page} should be compared with is not properly terminated.

Since there is no space after 1, TeX continues to expand tokens in order to find more digits. And it finds \smash, which is redefined by amsmath to have an optional argument. Everything goes awry, because this untimely expansion in the middle of a conditional makes everything unbalanced.

Either do

\ifnum 1=\value{page}%
  \smash{TTT}%

or

\ifnum\value{page}=1
  \smash{TTT}%

This is one of the cases where protecting an endline causes havoc. See When is it harmful to add percent character at end of lines in a \newcommand, or similar

egreg
  • 1,121,712