Re: Numerazione section alfanumerica

#25409
Up
0
Down
::

Lo so che si potrebbero creare delle variabili che tengono in memoria i valori e che settare il contatore chaper manualmente non è proprio il massimo.. Però così è come serve a me. Si accettano ovviamente suggerimenti e finezze per rendere il codice più funzionale ed elegante ! 🙂

Non occorre un contatore in più.
`\makeatletter
\renewcommand{\thechapter}{\@SetChapter\arabic{chapter}}
\def\Chapter{%
\expandafter\xdef\csname save@\@SetChapter\endcsname{\arabic{chapter}}%
\chapter}
\def\SetChapter#1{%
\gdef\@SetChapter{#1}%
\@ifundefined{save@#1}
{\setcounter{chapter}{0}}
{\setcounter{chapter}{\@nameuse{save@#1}}\stepcounter{chapter}}%
}
\makeatother`
Ora puoi inserire il tuo codice come
`\SetChapter{S}
\Chapter{titolo}

\Chapter{titolo}

\SetChapter{A}
\Chapter{titolo}

\Chapter{titolo}

\SetChapter{S}
\Chapter{titolo}

\Chapter{titolo}
…`
e avrai S1, S2, A1, A2, S3, S4. Occhio a \Chapter invece di \chapter; ho dovuto fare così perché i comandi \tableofcontents e altri si appoggiano a \chapter.

Il comando \Chapter aggiorna il significato del comando \save@S (se siamo dopo una dichiarazione \SetChapter{S}) che conterrà il numero del capitolo che si sta per cominciare diminuito di uno (perché è \chapter che fa avanzare il contatore).

Il comando \SetChapter{S} imposta il valore del contatore chapter a quello contenuto in \save@S, aumentato di uno. Tuttavia la prima volta che compare \SetChapter{S}, il comando \save@S non sarà definito e il contatore chapter è impostato a 0.

Ciao
Enrico

Go to top