TransWikia.com

Ask LuaLaTeX to ignore an active catcode previously written into aux file by pdflatex

TeX - LaTeX Asked on February 25, 2021

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}

One Answer

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
ifxdirectluaundefined
AtBeginDocument{immediatewrite@auxout{detokenize{%
 ifxdirectluaundefinedelseendinputfi}}}
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.

Correct answer by David Carlisle on February 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP