7

Surrounding \title macro with \shorthandon{;:!?} and \shorthandoff{;:!?} gives the expected result with babel's french language (space added before the '?', '!', ':' and ';'):

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\shorthandon{;:!?}%
\title{La crise? Quelle crise?}
\shorthandoff{;:!?}%
%
\begin{document}
\maketitle
\end{document}

But this doesn't work if \shorthandon and \shorthandoff are embedded in (a redefinition of) the \title macro:

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\let\titleORI\title
\renewcommand{\title}[1]{%
  \shorthandon{;:!?}%
  \titleORI{#1}%
  \shorthandoff{;:!?}%
}
%
\title{La crise? Quelle crise?}
\author{Un auteur? Deux auteurs!}
%
\begin{document}
\maketitle
\end{document}

What is the reason of this? Is there a workaround?

Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85

1 Answers1

9

Saying \shorthandon{?} makes ? an active character. So, when the argument to \title is absorbed, in the first example, it is active and, at \maketitle, LaTeX will use the current definition for it, which happens to be the one defined by babel-french.

On the contrary, in the second case the \shorthandon command is executed when the argument to \title has already been absorbed, so ? is not active and such it will remain forever (in the replacement text of \@title, which is the macro where \title stores the title).

You have to delay reading the argument after \shorthandon has been executed.

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

\let\ORItitle\title
\renewcommand{\title}{%
  \shorthandon{;:!?}%
  \titlewithshorthand
}
\newcommand{\titlewithshorthand}[1]{%
  \ORItitle{#1}%
  \shorthandoff{;:!?}%
}

\title{La crise? Quelle crise?}

\begin{document}
\maketitle
\end{document}

But I'd simply place \title after \begin{document}.

egreg
  • 1,121,712
  • Placing \title after \begin{document}, and before \maketitle, is natural (and in any case necessary) as the corresponding argument will appear in the 'made' title. But, back to my other question http://tex.stackexchange.com/q/166878/18401, for other macros from a custom class, such as \keywords, it is not natural to impose its insertion before \maketitle. Hence, I would prefer to store all these 'document properties' macros (\title, \keywords, etc.) in the preamble, with the drawback of these characters active only at \begin{document}. – Denis Bitouzé Mar 25 '14 at 14:41
  • 1
    With babel 3.9 there's the KeepShorthandsActive option, but I wouldn't recommend it for general usage. – egreg Mar 25 '14 at 14:45
  • Yes: looks very dangerous! :) I prefer your solution that confines the shorthands deactivation. – Denis Bitouzé Mar 25 '14 at 14:50
  • @egreg And with 3.8, in fact. This is one of the oldest options of babel. – Javier Bezos Mar 25 '14 at 17:45
  • @JavierBezos Really? Well, I've always recommended putting \title and \author after \begin{document}. ;-) – egreg Mar 25 '14 at 17:47
  • TIL after using LaTeX since the early 1990s that arguments for one command can be consumed by another... – Fuhrmanator Aug 07 '20 at 02:56