![¿Por qué \shorthandon y \shorthandoff no se pueden incrustar en otras macros?](https://rvso.com/image/286988/%C2%BFPor%20qu%C3%A9%20%5Cshorthandon%20y%20%5Cshorthandoff%20no%20se%20pueden%20incrustar%20en%20otras%20macros%3F.png)
La macro circundante \title
con \shorthandon{;:!?}
y \shorthandoff{;:!?}
da el resultado esperado con babel
el french
idioma (espacio agregado antes de '?', '!', ':' y ';'):
\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\shorthandon{;:!?}%
\title{La crise? Quelle crise?}
\shorthandoff{;:!?}%
%
\begin{document}
\maketitle
\end{document}
Pero esto no funciona si \shorthandon
y \shorthandoff
están integrados en (una redefinición de) la \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}
¿Cuál es la razón de esto? ¿Existe alguna solución?
Respuesta1
El decir \shorthandon{?}
hace ?
un personaje activo. Entonces, cuando se absorbe el argumento to \title
, en el primer ejemplo, está activo y, en \maketitle
, LaTeX usará la definición actual, que resulta ser la definida por babel-french
.
Por el contrario, en el segundo caso el \shorthandon
comando se ejecuta cuando el argumento to \title
ya ha sido absorbido, por lo que ?
no está activo y permanecerá para siempre (en el texto de reemplazo de \@title
, que es la macro donde \title
almacena el título).
Debe retrasar la lectura del argumento una vez \shorthandon
ejecutado.
\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}
Pero simplemente lo colocaría \title
después \begin{document}
.