3

If I use colons in \cref{sec:mysection} then it fails to compile when I use the french babel. I can remove the colons in the section names, but this feel a bit dirty. Any other option?

MWE:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %% For UTF8 chars (accented letters).
\usepackage[french]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}

\begin{document}
The section is \cref{sec:mysection}.

\section{My section}\label{sec:mysection}

\end{document}

Related: prettyref bug when used with babel-french

2
  • I have this problem too. use \usepackage[French]{cleveref} and you can't use : because it is a special symbol in the French Babel. I couldn't find an easy work around, sadly.
    – anis
    Commented Jan 2, 2023 at 14:33
  • 1
    I thought the recent changes in the kernel meant that these would work too. Alas, there's indeed still a problem. But it is documented in cleveref's manual, at the "Non-bugs" section. For what it's worth, zref-clever can handle it. And, off-topic, you no longer need to specify \usepackage[utf8]{inputenc}, it's already the default.
    – gusbrs
    Commented Jan 2, 2023 at 14:38

1 Answer 1

7

cleveref uses \edef on the label name, and this doesn't like the active colon. You can try to make it protected (but it would be imho nicer if the babel definitions were protected by default):

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %% For UTF8 chars (accented letters).
\usepackage[english,french]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}

\begin{document}
% after begin document:
\addto\extrasfrench{\protected\edef:{\unexpanded\expandafter{:}}}
\selectlanguage{french}

The section is \cref{sec:mysection}.

\section{My section}\label{sec:mysection}

text: text

\selectlanguage{french}

The section is \cref{sec:mysection}. 

\selectlanguage{english}

The section is \cref{sec:mysection}. 
\end{document}

An alternative is to make the colon safe locally, but it would change typesetting if it done for the whole command so one have to guess a place where to switch that off again (and perhaps there are other commands which still break ...):

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[english,french]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[capitalise,noabbrev]{cleveref}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@cref{\begingroup}{\begingroup\@safe@activestrue}{}{\fail}
% it is only a guess that the following a good place to reactivate the active chars ...
\patchcmd\@cref{\cref@isstackfull{\@refsubstack}}{\cref@isstackfull{\@refsubstack}\@safe@activesfalse}{}{\fail}
\makeatother
\begin{document}
The section is \cref{sec:mysection} 

\section{My section}\label{sec:mysection}

text: text

\end{document}
3
  • Thanks a lot! But I tried to use your first solution in a \AtBeginDocument as many documents rely on the same include.tex file, but it fails with ERROR: Missing control sequence inserted. \inaccessible
    – tobiasBora
    Commented Jan 4, 2023 at 12:36
  • 1
    in the preamble you need to activate the shorthand first: \shorthandon{:} \addto\extrasfrench{\protected\edef:{\unexpanded\expandafter{:}}} \shorthandoff{:} Commented Jan 4, 2023 at 12:56
  • Hi @UlrikeFischer , could you detail how to move your first solution in the preamble? Following your suggestion, I tried \AtBeginDocument{ \shorthandon{:} \addto\extrasfrench{\protected\edef:{\unexpanded\expandafter{:}}} \shorthandoff{:}\selectlanguage{french} } but I get the same failure as above (\inaccessible being missing)
    – Guillaume
    Commented Mar 1 at 10:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .