Babel+french:与名称中的 cref 和冒号不兼容

Babel+french:与名称中的 cref 和冒号不兼容

如果我使用冒号,\cref{sec:mysection}那么当我使用法语 babel 时,编译会失败。我可以删除部分名称中的冒号,但这感觉有点脏。还有其他选择吗?

梅威瑟:

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

有关的:与 babel-french 一起使用时,prettyref 出现错误

答案1

cleveref\edef在标签名称上使用,这不像活动冒号。您可以尝试使其受保护(但我认为如果 babel 定义默认受保护会更好):

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

另一种方法是使冒号在本地是安全的,但如果对整个命令这样做,它会改变排版,因此必须猜测在哪里再次关闭它(并且也许还有其他命令仍然中断......):

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

相关内容