3

I am using several \included files and within them several instances of KOMAs \ifthispageodd mechanism like in the following MWE:

\documentclass{scrbook}

\begin{filecontents}{fileA.tex}
  \ifthispageodd{odd Page}{even Page}
\end{filecontents}

\begin{filecontents}{fileB.tex}
  \ifthispageodd{odd Page}{even Page}
\end{filecontents}

% Uncomment the following line to get
% LaTeX Warning: Label `1' multiply defined.
%\includeonly{fileB}

\begin{document}
  \include{fileA}
  \include{fileB}
\end{document}

As soon as I use \includeonly an one of the \ifthispageodd instances is not included, pdfLaTeX will issue

LaTeX Warning: Label `1' multiply defined.

and possibly more of them with increasing numbers.

Those Warnings are not harmfull and as far as I can observe the \ifthispageodd work as expected probably because of the heuristic mentioned in scrguien.pdf (p. 72):

Because the \ifthispageodd command uses a mechanism that is very similar to a label and a reference to it, at least two LaTeX runs are required after every text modification. Only then the decision is correct. In the first run a heuristic is used to make the first choice.

3

scrbook tries to save on a counter by using a macro to store an incrementing value, but that means that it isn't seen by the mechanism \include uses to preserve counters for use in later chapters even when the file is not included.

It would be possible to modify the restore mechanism to preseve the macro but simpler and safer I think is just to use a latex counter:

If you delete the existing aux files, run this including both files, then again just including the second, you should avoid the warning.

\documentclass{scrbook}

\begin{filecontents}{fileA.tex}
  \ifthispageodd{odd Page}{even Page}
\end{filecontents}

\begin{filecontents}{fileB.tex}
  \ifthispageodd{odd Page}{even Page}
\end{filecontents}

% Uncomment the following line to get
% LaTeX Warning: Label `1' multiply defined.
\includeonly{fileB}
\newcounter{scbookpg}

\makeatletter
\renewcommand*{\is@thispageodd}{%
  \@bsphack
  \begingroup
    %\@tempcnta=\scr@tpo
    %\advance\@tempcnta by\@ne
    \stepcounter{scbookpg}%
    \xdef\scr@tpo{\thescbookpg}%
    \protected@write\@auxout{\let\arabic\relax}{%
      \string\new@tpo@label{\scr@tpo}{\arabic{page}}}%
    \expandafter\ifx\csname tpo@\scr@tpo\endcsname\relax
      \protect\G@refundefinedtrue
      \ClassWarning{\KOMAClassName}{%
        odd/even page label number \scr@tpo\space undefined}%
      \edef\@tempa{\the\value{page}}%
    \else
      \edef\@tempa{\csname tpo@\scr@tpo\endcsname}%
    \fi
    \ifodd\number\@tempa
      \aftergroup\thispagewasoddtrue
    \else
      \aftergroup\thispagewasoddfalse
    \fi
  \endgroup
  \@esphack
}
\makeatletter
\begin{document}
\include{fileA}
  \include{fileB}
\end{document}
  • I suspected something like this. Is there a reason KOMA uses its own kind-of- instead a standard LaTeX counter? – David Woitkowski Jan 21 '15 at 12:24
  • There are only a finite number of counters (256 in classic tex, rising to 2^15 in e-tex) so traditionally avoiding counters is a good idea if you do not need lots of arithmetic on them. But I can't say why the KOMA author did any particular design, I just looked at the source this morning in answer to your question. It may be worth raising a bug report on the class. – David Carlisle Jan 21 '15 at 12:40

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.