Alla fine l’errore era dovuto a un’incompatibilità già nota tra lipsum e babel quando si specifica spanish come ultima opzione. (Scrivo qui come promemoria per me stesso che spanish ridefinisce [tt]\@roman[/tt] per forzare i numeri romani in maiuscolo: si può ovviare con [tt]\def\@roman{\romannumeral}[/tt].)
`\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish,french,english,german,italian]{babel}
\usepackage{lipsum,textcase}
\title{Nomi dei mesi in maiuscolo}
\author{}
\usepackage{datetime}
\usepackage{etoolbox}
\makeatletter
\DeclareRobustCommand*\patchmonthname[1]{%
\if@dt@multilingual
\begingroup
\expandafter\ifx\csname monthname\languagename\endcsname\relax
\typeout{No original \string\monthname\languagename}%
\endgroup
\else
\expandafter\ifx\csname p@monthname\languagename\endcsname\relax
\endgroup
\typeout{Patching \string\monthname\languagename}%
\@patchmonthname
\typeout{Patched \string\monthname\languagename}%
\else
\typeout{Already patched \string\monthname\languagename}%
\endgroup
\fi
\fi
\fi}
\def\@patchmonthname{%
% Uso \x per fare prima a scrivere
\expandafter\let\expandafter\x\csname\string\monthname\languagename\endcsname
\@@patchmonthname
\expandafter\let\csname p@monthname\languagename\endcsname\x}
\begingroup
\@makeother\#
\gdef\@@patchmonthname{%
% Senza bisogno di generare errore se il patching fallisce:
% se il problema esiste si ripresenterà durante l'espansione
\patchcmd\x{\the\@orgargctr}{#1}\relax\relax
\patchcmd\x{\the\@orgargctr}{#1}\relax\relax
\patchcmd\x{\@orgargctr=#1\relax}{}\relax\relax
\patchcmd\x{\@orgargctr}{#1\relax}\relax\relax}
\endgroup
\DeclareRobustCommand*\Monthname[1]{%
\edef\x{%
% Non dovrebbero esserci problemi
\csname p@monthname\languagename\endcsname[#1]}%
\expandafter\MakeTextUppercase\x}
\patchmonthname{english}
\apptocmd\select@language{\patchmonthname{#1}}{}{%
\errmessage{Cannot patch \string\select@language}}
\makeatother
\setlipsumdefault{66}
\begin{document}
\maketitle
\section{È possibile?}
\Monthname{1} 2012. \lipsum
\begin{otherlanguage}{french}
\Monthname{2} 2012. \lipsum
\end{otherlanguage}
\begin{otherlanguage}{italian}
\Monthname{3} 2012. \lipsum
\end{otherlanguage}
\begin{otherlanguage}{spanish}
\Monthname{4} 2012. \lipsum
\end{otherlanguage}
\begin{otherlanguage}{german}
\Monthname{5} 2012. \lipsum
\end{otherlanguage}
\begin{otherlanguage}{english}
\Monthname{6} 2012. \lipsum
\end{otherlanguage}
\begin{otherlanguage}{spanish}
\Monthname{7} 2012. \lipsum
\end{otherlanguage}
\end{document}`
Chiedo:
- C’è qualche grave falla in questo codice?
- Non sono riuscito a incorporare [tt]\@@patchmonthname[/tt] dentro [tt]\@patchmonthname[/tt]: ho dovuto definirlo a parte dopo aver posto [tt]\@makeother\#[/tt]. Perché? Se provo a incorporarlo, scrivendo “#1” nel secondo o terzo argomento di [tt]\patchcmd[/tt], il compilatore giustamente si lamenta che [tt]\@patchmonthname[/tt] non ha argomenti (cioè non può risolvere quel “#1”); se invece scrivo “##1”, rimangono entrambi i ##, anziché venire dimezzati. Mi sfugge qualcosa? Per essere più precisi, non funziona questo:
`\def\@patchmonthname{%
% Uso \x per fare prima a scrivere
\expandafter\let\expandafter\x\csname\string\monthname\languagename\endcsname
\patchcmd\x{\the\@orgargctr}{##1}\relax\relax
\patchcmd\x{\the\@orgargctr}{##1}\relax\relax
\patchcmd\x{\@orgargctr=##1\relax}{}\relax\relax
\patchcmd\x{\@orgargctr}{##1\relax}\relax\relax}
\expandafter\let\csname p@monthname\languagename\endcsname\x}`
A [tt]\patchcmd[/tt] viene passato “##1”, invece di “#1”. Perché?
Grazie,
Antonio