0

I'm writing a package that loads babel and which users might run under either pdflatex or lualatex. When babel's french option is loaded, ":" is made active; and pdflatex writes the following into the .aux file:

\catcode `:\active 

This is all fine for pdflatex. However, if a user (for some reason) decides to starting running with lualatex, the existing .aux file is read, and an error is reported when subsequent lines of the .aux file contain ":". For example,

\newlabel{eqn:1}{{1}{1}}

results in

Undefined control sequence. 
<argument> r@eqn:
      1

One can just trash the .aux file and go again, but I'd like to prevent the message from appearing at all.

Is there a means of telling lualatex what to do with this active character (say, read it as ":")?

I'd thought of a construction such as

\RequirePackage{iftex}
\iflualatex
   \RequirePackage{etoolbox}
   \AtEndPreamble{\catcode`:<someaction>}
\fi

but I am not sure what someaction ought to be...

This MWE illustrates the problem in a single document:

% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage[french]{babel}
\begin{document}
Some English. \foreignlanguage{french}{Cette théorie formera désormais une des branches les plus importantes de la physique générale}. More English.

\begin{equation}\label{eqn:1}
f(x) = Ax
\end{equation}

\end{document}
2

If you are not using luatex, you can write a line to the aux file so the file will not be read if you are using luatex.

\documentclass{article}
\makeatletter
\ifx\directlua\undefined
\AtBeginDocument{\immediate\write\@auxout{\detokenize{%
 \ifx\directlua\undefined\else\endinput\fi}}}
\fi
\makeatother
\usepackage[french]{babel}

\begin{document}
Some English. \foreignlanguage{french}{Cette théorie formera désormais une des branches les plus importantes de la physique générale}. More English.

\begin{equation}\label{eqn:1}
f(x) = Ax
\end{equation}

\end{document}

so use pdflatex and the aux file will have the line

\ifx \directlua \undefined \else \endinput \fi 

which does nothing while you use pdftex, but will stop the file being read the first time you use luatex.

1
  • Brilliant -- that fully resolves my problem! Thank you, David.
    – John
    Dec 27 '20 at 23:38

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.