1

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[
  headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
]{thmstyle}
\makeatother
\theoremstyle{thmstyle}
\declaretheorem[name=Theorem]{theorem}

\usepackage[pdftex,colorlinks]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}

\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}

new-babel-french-crossreftools-clash

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

./clash.tex:23: Missing \endcsname inserted.
<to be read again> 
               :
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
1

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

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

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

\makeatletter
\declaretheoremstyle[
  headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
]{thmstyle}

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

\usepackage[pdftex,colorlinks]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}

\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}
0

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

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.