13

I read the excellent question Difference between ref, varioref and cleveref. Decision for a thesis and various doc on the net (the varioref package documentation) and tried to use it... but with many errors

An exemple :

\documentclass{article}
\usepackage[a4paper]{geometry}
\geometry{top=25mm,bottom=25mm,inner=25mm,outer=20mm,,marginparwidth=1cm,marginparsep=10pt}

\usepackage[ansinew]{inputenc}
\usepackage[french]{babel}
\usepackage[lmodern]
\usepackage[T1]{fontenc}
\usepackage{microtype}

\usepackage{color,xcolor}


\ifpdf%
        \usepackage[pdftex,pagebackref=true,hyperindex=true,colorlinks=true]{hyperref}
        \hypersetup{pdfstartview={FitH}, bookmarksnumbered={true}}
\else%
        \usepackage[hypertex=true,hyperindex=true,colorlinks=false]{hyperref}
\fi

\usepackage{cleveref}
\usepackage{varioref} 

\usepackage{lipsum}


\begin{document}
\section{Bla bla}\label{sec:bla}
\lipsum[1]

\newpage
\section{Second bla bla}
Test section 1 : 
\begin{itemize}
    \item with \verb"\ref" : \ref{sec:bla}
    \item with \verb"\vref" : \vref{sec:bla}
          = error "!Missing \verb"\endcsname" inserted" 
    \item with \verb"\cref" : \cref{sec:bla}
          = error "!Missing \verb"\endcsname" inserted"       
\end{itemize}

\newpage 
\section{Third bla bla}
Test section 1 : 
\begin{itemize}
    \item with \verb"\ref" : \ref{sec:bla}
    \item with \verb"\vref" : \vref{sec:bla}
          = error "!Missing \verb"\endcsname" inserted" 
    \item with \verb"\cref" : \cref{sec:bla}
          = error "!Missing \verb"\endcsname" inserted"       
\end{itemize}
\end{document}

I get the error !Missing \endcsname inserted and more other after... (same error with vref as for cref.

How is it possible to resolve this ? I don't find an answer on this forum nor on the net.

I will use those packages (vref and cref) for my customized environnements, for exemple with such a macro-box :

\newtheorem{theoreme}{{\sffamily Théorème}}[section]

\newcommand{\boxthm}[2]
{{\colorbox{yellow}{\begin{minipage}{0.98\linewidth}
      \begin{theoreme}\label{thm:#1}
        {\sffamily ~\\#2}
      \end{theoreme}
\end{minipage}}}\\~}

I presume that if I can resolve the problem for a section, I also get the tip for all my macro-boxes (thm, definitions, algorithms, lemma, examples, ...) ?

5
  • 1
    Load varioref after cleveref. What's the purpose of loading aeguill? It's a very obsolete package. If you haven't the CM-Super fonts installed, use lmodern. Also giving both the frenchb and francais options to babel is redundant: use either one or simply french.
    – egreg
    Nov 22, 2012 at 13:42
  • 1
    Load lmodern or install the CM-Super fonts.
    – egreg
    Nov 22, 2012 at 15:33
  • indeed with 'varioref' after 'cleveref', the command vref works (but not wioth french label as seen in its documentation). But cref doesn't work ... the problem is always pending
    – madit
    Nov 22, 2012 at 15:39
  • 2
    Now I see! It's a completely different problem: it's caused by the colons in the labels.
    – egreg
    Nov 22, 2012 at 15:42
  • code edited for correction given by egreg (thanks)
    – madit
    Nov 22, 2012 at 15:50

2 Answers 2

10

The problem is that varioref and cref don't like babel shorthands in the labels. Since the colon has a special meaning for French, you get that strange errors.

\documentclass{article}
\usepackage[a4paper]{geometry}
\geometry{top=25mm,bottom=25mm,inner=25mm,outer=20mm,
  marginparwidth=1cm,marginparsep=10pt}

\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage[english,french]{babel}
\usepackage{microtype} % loads also ifpdf

\usepackage{xcolor}

\usepackage{varioref}

\ifpdf
  \usepackage[pagebackref=true,hyperindex=true,colorlinks=true]{hyperref}
  \hypersetup{pdfstartview={FitH}, bookmarksnumbered={true}}
\else
  \usepackage[hypertex=true,hyperindex=true,colorlinks=false]{hyperref}
\fi

\usepackage{cleveref}

\begin{document}
\section{Bla bla}\label{sec-bla}
\lipsum[1]

\section{Second bla bla}
Test section 1 : 
\begin{itemize}
    \item with \verb|\ref| : \ref{sec-bla}
    \item with \verb|\vref| : \vref{sec-bla}
    \item with \verb|\cref| : \cref{sec-bla}
\end{itemize}

\newpage

\vref{sec-bla}
\end{document}

Some notes. The packages ae and aeguill are really obsolete and don't have really good metric files.

Better use the Type1 fonts that are provided by the CM-Super package (it depends on what distribution you're using how you install them) or say

\usepackage{lmodern}
3
  • Well ! So there is no possible solution ... It's a pity. Thank you anyway for your research.
    – madit
    Nov 26, 2012 at 6:21
  • Use \label{sec:bla}, then \cref{sec\string:bla} to work around the babel shorthand. (\string is mentioned in babel doc.) Nov 14, 2018 at 8:06
  • Also note that \shorthandoff{:} inside a macro can’t be used as a workaround (or at least, not simply) as it has no effect in a macro. Nov 14, 2018 at 8:10
2

I kind of found a workaround for that, but it is not super clean.

I load cleveref-package with the french option, and define a custom command \citeref (instead of \cref) as following

\newcommand{\citeref}[1]{
    \begin{otherlanguage}{british}
    \cref{#1}
    \end{otherlanguage}
}

Then it does work fine.

2
  • Looks like a nice solution. It's better, if you can, to add a full minimal working example to show that it works.
    – user30471
    Apr 6, 2016 at 12:59
  • 1
    Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it).
    – ebosi
    Apr 6, 2016 at 13:39

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.