4

I'm writting in French so I use babel. I'd like to use prettyref to keep from writting "Section" and co.

The problem is that I can not use it with French babel. It throws me:

! Paragraph ended before \@prettyref was complete.
<to be read again> 
                   \par 
l.36 

? 

Here is an MWE:

\documentclass{article}

\usepackage{prettyref}

% Form package, just for info.
\makeatletter
\def\prettyref#1{\@prettyref#1:}
\def\@prettyref#1:#2:{%
    \expandafter\ifx\csname pr@#1\endcsname\relax%
    \PackageWarning{prettyref}{Reference format #1\space undefined}%
    \ref{#1:#2}%
    \else%
    \csname pr@#1\endcsname{#1:#2}%
    \fi%
}
\makeatother

\usepackage[french]{babel}
\usepackage[T1]{fontenc}

\begin{document}

\section{Introduction}\label{sec:intro}

See \prettyref{fig:defs}

\section{Definitions}\label{sec:defs}

See \prettyref{sec:conclusion}

\section{Conclusion}\label{sec:conclusion}

See \prettyref{sec:intro} and \prettyref{fig:defs}. With prettyref we simply write \verb|\prettyref{sec:intro}| to get \prettyref{sec:intro}.

\end{document}

Conclusion

Ok ! For all French peaple looking here, you can't define labels like fig:a. This causes problems as soon as an automatic reference package is used.

The reason is that the : "letter" becomes an active character in French babel, which leads all these problems :s

What I made is to use cleveref with labels like fig-a.

Thanks everyone !

  • prettyref is simply not compatible with babel-french. – egreg Feb 11 at 11:06
  • 1
    What egregs says, it is probably because of the active : – daleif Feb 11 at 11:07
  • @Mico IIRC, current LaTeX kernel copes with : in labels, even under babel-french. I recommend against using : with this setup though, precisely because of packages like cleveref that don't like it when active. – frougon Feb 11 at 12:02
  • 1
    You should probably post that cleveref question as a separate question as it will never be found by others under the current title (which you should not edit as it suits the original question). Besides the cleveref manual explicitly mentions that it is not compatible with active chars. – daleif Feb 11 at 13:08
  • 1
    I added an example with varioref and cleveref. – egreg Feb 11 at 14:51
3

You can make prettyref compatible with babel-french (but the fix will only work with it).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{prettyref}

% fix \prettyref to first detokenize its argument
% kudos to daleif for proposing the simplification
\makeatletter
\def\prettyref#1{\expandafter\@prettyref\detokenize{#1:}}
\makeatother


\begin{document}

\section{Introduction}\label{sec:intro}

See \prettyref{fig:defs}

\section{Definitions}\label{sec:defs}

See \prettyref{sec:conclusion}

\section{Conclusion}\label{sec:conclusion}

See \prettyref{sec:intro} and \prettyref{fig:defs}. With prettyref we 
simply write \verb|\prettyref{sec:intro}| to get \prettyref{sec:intro}.

\begin{figure}[htp]
\caption{caption}\label{fig:defs}
\end{figure}

\end{document}

enter image description here

On the other hand, a combination of varioref and cleveref would be more robust. However, cleveref doesn't like active colons, but doesn't rely on a precise label naming scheme, so you can use any other separator (avoid French special punctuation, though). The advantage over prettyref is that you can decide whether to use \ref (just the number), \cref (with the type) or \vref (with type and reference to the page).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{varioref,cleveref}

\crefname{figure}{figure}{Figure}

\begin{document}

\section{Introduction}\label{sec-intro}

See \vref{fig-defs}

\section{Definitions}\label{sec-defs}

See \cref{sec-conclusion}

\section{Conclusion}\label{sec-conclusion}

See \cref{sec-intro} and \cref{fig-defs}. With cleveref we 
simply write \verb|\vref{sec-intro}| to get \vref{sec-intro}.

\clearpage

\begin{figure}[htp]
\caption{caption}\label{fig-defs}
\end{figure}

\end{document}

enter image description here

| improve this answer | |
  • 1
    I have my own personal unreleased reimplementation of fancyref, which also uses : as the separator. AFAIR I detokenize the label and that seems to work fine with french babel. Not sure if that helps here. – daleif Feb 11 at 11:17
  • 2
    @daleif Seems to work, thanks. – egreg Feb 11 at 11:28

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.