It appears that I have a case where \ifx\\#2\\
is false, even though #2
is empty.
Here is the relevant excerpt from the log file, with \tracingcommands
and \tracingmacros
turned on:
\lastpageref ->\lastpagereftxt
\lastpagereftxt #1->\pagesLTS@@pageref #1*\END
#1<-pagesLTS.arabic
\pagesLTS@@pageref #1*#2\END ->\ifx \\#2\\\pagesLTS@@@pageref {#1}\else \expand
after \pagesLTS@@@pagerefstar \fi
#1<-pagesLTS.arabic
#2<-
{restricted horizontal mode: \ifx}
{false}
As a result, \pagaesLTS@@@pagerefstar
is called, and mayhem results. Not least because this happens in the output routine, while typesetting a complicated page header, and the next token happens to be \cr
. But that is all beside the point, which is that this can't happen! And yet it does.
My question: How to debug something like this? Assuming it is not a bug in the TeX engine itself, there must be some natural explanation for it. I have verified (using \show
) that \ifx
really means \ifx
at this point, and I assure you that there is no \unless
lurking in the code either. And as far as I know, that exhausts the range of possible explanations. Can you come up with more possibilities I can look for?
Edit: I managed to chop the problem files down to size. Here is my input file:
\errorcontextlines=99
\documentclass{blargh}
\begin{document}
(Dummy text to ensure we get a page.)
\end{document}
And my class file, chopped down from over 300 lines to the bare essentials for this problem, and named blarhg.cls
:
\NeedsTeXFormat{LaTeX2e}
\LoadClass{report}
\RequirePackage[pagecontinue=false]{pageslts}
\AtBeginDocument{\thispagestyle{Eks}}
\def\PageText#1#2{Page #1 of #2}
\newtoks\firstpageupperright
\firstpageupperright{\PageText{\thepage}{\lastpageref{pagesLTS.arabic}}}
% Taken from pageslts.sty, so I could add \showtokens
\def\pagesLTS@@pageref#1*#2\END{%
\ifx\\#2\\% no star
\pagesLTS@@@pageref{#1}%
\else% star
\showtokens{"#2"}%
\expandafter\pagesLTS@@@pagerefstar%
\fi%
}
\def\ps@Eks{\let\@mkboth\@gobbletwo
\def\@oddhead{\hfill \vtop to 0pt{\let\\\cr
\halign{\strut\hfil####\cr
\relax\tracingall
\the\firstpageupperright\cr
\llap{}\cr}\vss}}
\def\@oddfoot{}\let\@evenfoot\@oddfoot
\let\@evenhead\@oddhead}
\showtokens{"#2"}
to see if there is a space or similar as part of#2
.\cr
probably the\ifx
is expanding durong the pre-scan looking for\omit
and the first\\
expands then, and then the second\\
isn't seen until after the cell template is inserted\showtokens
shows that #2 is indeed empty.\relax
in front to stop that didn't help. Besides, wouldn't the expansion of the double backslash [how do I type that so it shows correctly in a comment?] show up in the log?