3

I've unsuccessfuly searched for an answer to this problem. I'd like to use the smartref package together with babel with option frenchb, but there seems to be a conflict : command \chapterref in the following MWE :

\documentclass{book}[11pt]
\usepackage{smartref}         %Pour \chapterref
\usepackage[frenchb]{babel}
\addtoreflist{chapter}

\begin{document}

\chapter{A chapter}

Here is some text, see \S\ \chapterref{sec:try}.

\section{tata}

\section{toto}
\label{sec:try}

\end{document}

produces the following error :

! Missing \endcsname inserted.
<to be read again> 
                   \unskip 
l.14 ...is some text, see \S\ \chapterref{sec:try}

If I replace \usepackage[frenchb]{babel} with \usepackage[english]{babel}, the document compiles correctly and produces the expected result. I tried swapping both usepackage's commands, but compiling fails all the same.

I'm using Babel v3.8d with frenchb v2.6e (according to the log), and smartref version 1.9 (according to CTAN, 1.82 according to the readme file) just downloaded from CTAN.

I guess a private hacked babel frenchb would solve the problem, but I know too little of TeX (csname's etc...) to dig into this by myself. Does somebody have a hint ?

Thanks a lot in advance.

1
  • Welcome to TeX.SX! The frenchb babel setting makes the colon : active, which I suspect is the problem. Sep 2, 2014 at 13:14

1 Answer 1

2

The problem is exactly in the colon in the label, for which smartref has no protection mechanism like \ref has.

A quick patch is the following:

\documentclass{book}[11pt]
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{smartref}         %Pour \chapterref
\usepackage[frenchb]{babel}

\usepackage{regexpatch}
\makeatletter
\regexpatchcmd*{\addtoreflist}
  {([^1])\cP.\cP.2}%                        replace all ##2 not preceded by 1
  {\1\c{detokenize}\cB\{\cP\#\cP\#2\cE\}}%  with \detokenize{##2}
  {}{}
\makeatother

\addtoreflist{chapter}

\begin{document}

\chapter{A chapter}

Here is some text, see \S~\chapterref{sec:try}.

\section{tata}

\section{toto}
\label{sec:try}

\end{document}

Beware that this disallows macros in the argument to \label (more precisely, those that you intend to use with \chapterref or similar smartef commands) which doesn't seem a big limitation.

enter image description here

You must log in to answer this question.

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