![Por que \shorthandon e \shorthandoff não podem ser incorporados em outras macros?](https://rvso.com/image/286988/Por%20que%20%5Cshorthandon%20e%20%5Cshorthandoff%20n%C3%A3o%20podem%20ser%20incorporados%20em%20outras%20macros%3F.png)
A macro circundante \title
com \shorthandon{;:!?}
e \shorthandoff{;:!?}
fornece o resultado esperado com o idioma babel
de french
(espaço adicionado antes de '?', '!', ':' e ';'):
\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%
\shorthandon{;:!?}%
\title{La crise? Quelle crise?}
\shorthandoff{;:!?}%
%
\begin{document}
\maketitle
\end{document}
Mas isso não funciona se \shorthandon
e \shorthandoff
estiverem incorporados (uma redefinição) na \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}
Qual é a razão disso? Existe uma solução alternativa?
Responder1
Dizer \shorthandon{?}
forma ?
um personagem ativo. Então, quando o argumento to \title
for absorvido, no primeiro exemplo, ele estará ativo e, em \maketitle
, o LaTeX usará a definição atual para ele, que passa a ser aquela definida por babel-french
.
Pelo contrário, no segundo caso o \shorthandon
comando é executado quando o argumento to \title
já foi absorvido, portanto ?
não está ativo e assim permanecerá para sempre (no texto substituto de \@title
, que é a macro onde \title
armazena o título).
Você tem que atrasar a leitura do argumento depois de \shorthandon
executado.
\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}
Mas eu simplesmente colocaria \title
after \begin{document}
.