# babel and crossreftools incompatibility?

The following MWE is giving error:

./test.tex:10: Missing \endcsname inserted.
:
l.10 \section{A section}\label{sec:one}


The source:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[french,main=english]{babel}

\usepackage{crossreftools}

\begin{document}

\section{A section}\label{sec:one}

Some math $1+1=2$.

\end{document}


There is no error if I:

• delete \usepackage{crossreftools}; OR
• omit french from the options to babel; OR
• replace french by german or russian.

The Incompatibilities section of the docs for crossreftools say "...any unexpandable content written to the aux-file by redefinitions of \label or @currentlabel etc will cause problems.

Is that what the french option to babel is doing — writing such unexpandable content to the .aux?

If so, is there some work-around?

• You can try the version currently in github.com/latex3/babel . – Javier Bezos Oct 2 '19 at 14:43
• @JavierBezos: Is that newer than the stable version 3.34 that I just updated with the TeXLive Utility? If so, how do I use latex on the .ins so as NOT to replace the stable version already in my texmf tree? Don't I want to do that and just place the new files in the same folder as my source document, for testing? – murray Oct 2 '19 at 19:01
• @JavierBezos: the problem arises not with babel itself, so far as I can see, but with babel-french.ldf, where : is made active. (Likewise ; and ! and ?). – murray Oct 5 '19 at 16:36

crossreftools creates a list of labels and tries to write the label key to it. That is a bit fragile ... You could add \detokenize:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[french,main=english]{babel}

\usepackage{crossreftools}
\makeatletter
\ifcrtfinal
\else
\protect\numberline{\expandafter\crtrefnumber\expandafter{\detokenize{#1}}}#1}%
\fi
}
\makeatother

\begin{document}
\crtlistoflabels
\tableofcontents
\section{A section:abc }  \label{sec:onea} \label{seconea}
Some math $1+1=2$.

\end{document}

• While that does fix the crossreftools+babel-french incompatibility for the crossreftools command crtlistoflabelsthat I raised, it does not fix the incompatibility with the other commands from that package, including its redefinition of the version of \cref(from cleveref). – murray Oct 11 '19 at 15:31
• There is another place where a \detokenize is needed, see my answer. – Pieter van Oostrum Oct 14 '19 at 10:46

The French option has made : active to produce French punctuation spacing and this interferes with its use in \label the simplest solution is simply to avoid punctuation characters in \label, \label{sec-one} works for example.

Normally babel ensures : still works in \label but apparently crossreftools disables that.

• Ouch! In my actual book-length document, all the 1500+ labels include a colon. So I'm hoping there's some other workaround -- for babel-french. – murray Oct 1 '19 at 22:02
• @murray oh there is always a workaround:-) I don't actually know crossreftools package and I was hoping to avoid looking but I'll look tomorrow if no one else has answered. – David Carlisle Oct 1 '19 at 22:09

There is another place where a \detokenize is needed:

\renewcommand{\@@crtextr@ct@ref}[2]{%
\expandafter\@@@crtextr@ct@ref\expandafter{\detokenize{#2}}{#1}%
}
\newcommand{\@@@crtextr@ct@ref}[2]{%
\expandafter\ifx\csname r@#1\endcsname\relax
\crt@refundefined%
\else
\expandafter\expandafter\csname crt@ref@splitter@#2\endcsname\csname r@#1\endcsname%
\fi
}

