latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
123 stars 34 forks source link

Problems with \Ref and babel (The Latex Companion 3rd edition p.78) #292

Open Boupaul opened 2 months ago

Boupaul commented 2 months ago

Hello,

Having just bought The LaTeX Companion Third edition, I'm testing the examples given in the book. On p.78, the example treats of the using of \labelformat and \Ref.

\documentclass[10pt,a4paper]{article}

\usepackage[nospace]{varioref}
%\usepackage{babel}

\labelformat{section}{section~#1}
\labelformat{equation}{equation~(#1)}

\begin{document}
\section{An example}\label{sec}
\Ref{sec} shows the use of the \verb=\labelformat= declaration with a reference to \ref{eq}.
\begin{equation} a = b \label{eq} \end{equation}  
\end{document}

everything works fine, but if you add an

\usepackage{babel}

with whatever language you want you get a

! Incomplete \iffalse; all text was ignored after line 11.

If you replace \Ref with \ref, all works fine again, but you loose the UpperCasing of the first letter, evidently.

I've tried with [english]babel and [french]babel and babel with no option. I've tried with pdfLaTeX, LaTeX, XeLaTeX, LuaLaTeX ... same problem ...

David Carlisle and Ulrike Fischer gave me some tricks to go around the problem on Tex Stack Exchange but they encouraged me to post the bug on GitHub (in the hope it will be resolved ?)

Thanks

davidcarlisle commented 2 months ago

Link for ease of reference https://tex.stackexchange.com/a/715560/1090

jbezos commented 2 months ago

As David explained, babel modifies some internal macros to deal with shorthands. The option safe=none tells babel to keep the original definitions and not to modify them — the name comes from the fact formerly shorthands were not ‘safe’ and raised an error (admittedly, currently this can be misleading). Some time ago, \ref was redefined in the LaTeX kernel so that shorthands are safe even with safe=none. As Ulrike pointed out in Stackexchange, this behavior is documented (just search the babel manual for ’varioref’), and in my tests shorthands work in \Ref even with safe=none, too.

The real fix is most likely to make safe=none the default, but I’ve not taken this step yet because \nocite, \bibcite and the like are still unsafe.