2

Using:

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)

... I compile the following MWE:

\documentclass[10pt,twoside,openright]{book}
%\usepackage[english]{babel}
\usepackage[greek,english]{babel} %% A
\usepackage{mparhack}             %% B
\usepackage{lipsum}

\begin{document}
\pagenumbering{roman}             %% C
Testing

\lipsum[1]
\end{document}

... which triggers the following error upon pdflatex test.tex:

! Use of \\@lipsum doesn't match its definition.
\text@command #1->\def \reserved@a {
                                    #1}\ifx \reserved@a \@empty \let \check@...
l.12 \end{document}

? 
! Unbalanced write command.
<write> \string \mph@setcol {ii:\thepage }{
                                           \string \mph@nr }
l.12 \end{document}

? X

Interestingly, this error appears only when all three: A, B, and C are present; it doesn't occur if we replace, say, A with \usepackage[danish,english]{babel} (if you delete the old .aux file first before recompiling). (Note: in my original doc, I actually got ! Incomplete \iffalse; all text was ignored after line ... appearing at \mph@outputpage@hook which is from mparhack; but similarly, that error appeared first only after adding greek to babel)

So this seems to be a specific error occuring when Greek babel, mparhack and \pagenumbering{roman} interact. How do I get rid of it?

3

The problem is quite subtle and lipsum is not really involved.

Analysis of the problem

The mparhack package makes some annotations in the .aux files, using

\newcommand*\mph@outputpage@hook{%
    \bgroup
    \advance\c@page\m@ne
    \immediate\write\@auxout{%
        \string\mph@setcol{ii:\thepage}{\string\mph@nr}%
    }%
    \egroup
}

and the problem starts here: with \pagenumbering{roman} the command \thepage means \roman{page} and, when Greek is used, the command \@roman that's used by \roman doesn't survive \write, because it now contains \textlatin which is not fully expandable.

The error involves \\@lipsum because this macro happens to be stored in \reserved@a, but it's just a symptom, not the disease.

The cure

\documentclass[10pt,twoside,openright]{book}
\usepackage[greek,english]{babel}     
\usepackage{mparhack}                 
\usepackage{lipsum}

\makeatletter
\renewcommand*\mph@outputpage@hook{%
    \bgroup
    \let\textlatin\@firstofone % make \textlatin a no-op
    \advance\c@page\m@ne
    \immediate\write\@auxout{%
        \string\mph@setcol{ii:\thepage}{\string\mph@nr}%
    }%
    \egroup
}
\makeatother

\begin{document}
\pagenumbering{roman}                 
Testing

\lipsum[1]

\end{document}

This successfully removes any attempt to expand the original \textlatin when writing the annotation. The redefinition is performed in a group, so the meaning of \textlatin will be restored as soon as \egroup is scanned. In the .aux file you'll find

\mph@setcol{ii:i}{\mph@nr}

which should be correct, because ii:i is used only as a unique label.

Further problems

In case the twocolumn option is used, the problem reappears in a different form; a possible solution is to patch also \mph@setcol and \mph@check, because in this case it's not really possible to remove \textlatin from the annotation, so we remove it when \mph@setcol and \mph@check are executed. Adding a group around them is not a problem, because both only do global assignments anyway.

\documentclass[10pt,twoside,openright,twocolumn]{book}
\usepackage[greek,english]{babel}
\usepackage{mparhack}
\usepackage{lipsum}

\usepackage{etoolbox}
\makeatletter
% this is the hack for one column output
\patchcmd\mph@outputpage@hook
  {\bgroup}
  {\bgroup\let\textlatin\@firstofone}
  {}{}
% this is the hack for two column output
\pretocmd\mph@setcol{\bgroup\let\textlatin\@firstofone}{}{}
\apptocmd\mph@setcol{\egroup}{}{}
\pretocmd\mph@check{\bgroup\let\textlatin\@firstofone}{}{}
\apptocmd\mph@check{\egroup}{}{}
\makeatother

\begin{document}
\pagenumbering{roman}
Testing

\lipsum[1]

\end{document}
  • Many thanks for that @egreg - I would never had guessed this had anything to with annotations in .aux files; cheers! – sdaau Oct 15 '14 at 11:06
  • Note that this hack introduces some breakage with the todonotes package, which can be fixed by patching additionally patching \mph@ifundef@or@smaller - see my post below – sdaau Nov 22 '14 at 19:14
1

Ok, I got something, but I'm not sure it's correct - so more erudite responses will be appreciated. By using package {trace}, I compared the trace outputs for the correct [english] and the problematic [greek,english] options for babel. Both variants end up in this stack trace:

\mph@outputpage@hook ->\bgroup \advance \c@page \m@ne \immediate \write \@auxout {\string \mph@setcol {ii:\thepage }{\string \mph@nr }}\egroup

  \thepage ->\csname @roman\endcsname \c@page

At this point, the \@roman command is called; in the [english]-only case, it is:

\@roman #1->\romannumeral #1

... but in the [greek,english] case, it is:

\@roman #1->\expandafter \textlatin \expandafter {\romannumeral #1}

... and \textlatin calls \text@command #1->\def \reserved@a {#1}... where #1<-i (the roman numeral i for page number 1); however it turns out in this case \reserved@a ->\\@lipsum somehow, and so we'd get, I guess \@lipsum{i} trying to execute, which indeed is wrong.

I read a bit through texdoc babel-greek, and it seems \textlatin is to ensure switching to a latin language font/encoding; I am guessing that apparently \@roman is redefined by babel-greek simply to ensure that the engine is in "latin text" mode before trying to typeset roman numerals, which makes sense - but makes the unfortunate interaction in this case.

My use for [greek,...]{babel} is mostly to ensure fonts/encoding for correct display of μ in siunitx and the like (related: Possible bug in babel-greek, TexLive 2014); I will not be using sections of greek text. Thus, the likelihood for typesetting roman numerals while in greek text mode is very low, so I thought: why not redefine the \@roman command back to what it was? Here texdef helps:

$ texdef -t latex -s @roman
% latex.ltx, line 1850:
\def\@roman#1{\romannumeral #1}

... and so, the fixed MWE that works now is:

\documentclass[10pt,twoside,openright]{book}
\usepackage{trace}
\usepackage[greek,english]{babel} %% A
\usepackage{mparhack}             %% B
\usepackage{lipsum}

\begin{document}
\traceon
\pagenumbering{roman}             %% C
% latex.ltx, line 1850:         % fix
\makeatletter                   % fix
\def\@roman#1{\romannumeral #1} % fix
\makeatother                    % fix

Testing

\lipsum[1]
\end{document}
  • 2
    Redefining \@roman to be the original is wrong: if Greek is the main language, your page numbers will use iota for ‘i’ and chi for ‘x’. – egreg Oct 15 '14 at 11:00
  • @egreg Yes, but the answer does make clear that it solves the problem, given that the use of Greek is limited and won't use roman numerals. – cfr Apr 1 '17 at 0:20

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.