# Another babel-french incompatibility with crossreftools

With the indicated line commented-out, the following course using both babel-french and crossreftools gives the expected output from the two crossreftools commands near its end:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

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

\makeatletter
\declaretheoremstyle[
]{thmstyle}
\makeatother
\theoremstyle{thmstyle}
\declaretheorem[name=Theorem]{theorem}

\usepackage{crossreftools}

\begin{document}

\begin{theorem}[theorem of Pythagoras]
\label{thm:prelim}

The square of the hypotenuse of a right triangle equals the sum of the squares of the other two sides.

\end{theorem}

\crtrefanchor{thm:prelim} --- \verb!\crtrefanchor{thm:prelim}!

\crtrefname{thm:prelim} --- \verb!\crtrefanchor{thm:prelim}!

\end{document}


However, when that line is uncommented, this error occurs:

./clash.tex:23: Missing \endcsname inserted.
:
l.23       \label{thm:prelim}


Undoubtedly the error has the same cause as noted in https://tex.stackexchange.com/a/510593/13492: the french option to babel makes : active, which interferes with the colon's use in the label.

A fix for another such class between babel-french and crossreftools was given in https://tex.stackexchange.com/a/510641/13492.

Question: How can this incompatibility be fixed for these two crossreftools commands?

Note: Why colons in labels?

In the book-length document from which the preceding MWE arises, I've been using colons in labels because they nearly all already have hyphens embedded in the phrase following the colon, e.g.,\label{thm:law-large-numbers}. Such a label makes the type of theorem (or definition, etc.) visually separate from the terse description of that particular theorem (etc.).

I tried semicolon instead, but find that also no good, since babel-french makes it active, too.

Character | might do (hope it doesn't lead to other problems), but it's rather obtrusive compared with : in a label. (Still, it will take some work to replace the colons in some 1500-1600 labels without inadvertently replacing needed colons punctuation body text.)

• You've been already advised not to use colons in labels. – egreg Oct 5 '19 at 10:24
• @egreg: The problem is, it's too late, really: I have nearly 1600 labels in my book-length document, each and every one with a colon. I adopted that convention long before I found that I needed crossreftools to do some of the cross-referencing. – murray Oct 5 '19 at 13:56
• @egreg Good to know, I have used : in labels for years ;(. What#s your suggestion instead for structuring labels? – Dr. Manuel Kuehner Oct 6 '19 at 19:33
• There is now an answer in another post: tex.stackexchange.com/a/510641/113546 – Pieter van Oostrum Oct 11 '19 at 15:08

This may help. I don't know if it is robust enough, but in simple cases it should work:

\edef\myoldcatcode{\the\catcode\:}
\let\myoriglabel\label
\def\label{\catcode\:=11 \mynewlabel}
\def\mynewlabel#1{\myoriglabel{#1}\catcode\:=\myoldcatcode}

• Seems not to be rubust: same error with babel-french and crossreftools, e.g., in something of the form \MakeTextLowercase{\crtrefname{thm:main}}. – murray Oct 6 '19 at 21:25
• Yes, because it mangles the catcode, it would only work at the outer level, not inside other macros. – Pieter van Oostrum Oct 6 '19 at 22:25
• @DavidCarlisle Since recent splits in the Oberdiek bundle, the etexcmds.sty package is no longer loaded automatically. It needs to be loaded explicitly for this MWE to compile properly, is this intended? – Daniel Flipo Dec 27 '19 at 13:47
• The additional fix to crossreftools from tex.stackexchange.com/a/510641/13492 is needed, too. – murray Jul 4 '20 at 20:12

You just need to make : safe when constructing csnames, something like

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

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

\makeatletter
\declaretheoremstyle[
]{thmstyle}

\let\zzz\active@prefix
\def\active@prefix{\ifincsname\expandafter\string\else\expandafter\zzz\fi}
\makeatother
\theoremstyle{thmstyle}
\declaretheorem[name=Theorem]{theorem}

\usepackage{crossreftools}

\begin{document}

\begin{theorem}[theorem of Pythagoras]
\label{thm:prelim}

The square of the hypotenuse of a right triangle equals the sum of the squares of the other two sides.

\end{theorem}

\crtrefanchor{thm:prelim} --- \verb!\crtrefanchor{thm:prelim}!

\crtrefname{thm:prelim} --- \verb!\crtrefanchor{thm:prelim}!

\end{document}

• While that works, it does not work if one uses \cref, etc., from cleveref, whereas the method of tex.stackexchange.com/a/511212/13492 does work with cleveref`. – murray Jul 4 '20 at 20:08
• @murray I know nothing:-) feel free to post a combined answer and self accept. I am not sure Ive ever used cleverref so would take me a while to test any answer, better if you self answer I think. – David Carlisle Jul 4 '20 at 20:43