[tex-live] Nested macro resetting problem
Geoff Russell
geoffrey.russell at gmail.com
Mon Jun 15 09:17:59 CEST 2009
On 6/14/09, enrico.gregorio at univr.it <enrico.gregorio at univr.it> wrote:
> This is not the right place for this kind of problems; however, here is a different solution.
Apologies and thanks for the different solution. I don't know latex
internals well
enough to understand it fully, but well enough to use it. Thanks.
Cheers,
Geoff.
> All commands are defined globally, because an abbreviation's first use in a chapter might
> be in a group. You should probably add a meaningful error message
>
> ===
> \documentclass[a4paper]{book}
> %%% here are the relevant definitions
> \makeatletter
> \newtoks\abbr at list % a hook where we memorize all the definitions
> \def\newabbr#1#2{%
> \@ifundefined{#1}
> {\addto at hook\abbr at list{\global\@namedef{#1}/{#2\global\@namedef{#1}/{#1}}}}%
> {\errmessage{Ouch}}%
> }
> % a patch to the \chapter command, to execute again all the definitions
> \toks@=\expandafter{\chapter}
> \edef\chapter{\noexpand\the\abbr at list\the\toks@}
> % define the abbreviations for the first time, just to be safe
> \AtBeginDocument{\the\abbr at list}
> \makeatother
> %%% end of the definitions
>
> \newabbr{TUG}{\TeX\ Users Group}
> \newabbr{XYZ}{Xy Yz Zu}
>
> \begin{document}
> ...
> \chapter{A title}
> \TUG/ is expanded; now \TUG/ is not. The same for \XYZ/ and \XYZ/.
> \chapter{A title}
> \TUG/ is expanded; now \TUG/ is not. The same for \XYZ/ and \XYZ/.
> \end{document}
>
> Ciao
> Enrico
>
>
> --
> Enrico Gregorio + Dipartimento di Informatica + Tel: +39 045 8027937
> Enrico.Gregorio at univr.it + Università degli Studi di Verona +
> (gregorio at math.unipd.it) + Strada le Grazie 15 / I-37134 Verona + Fax: +39 045 8027928
>
--
6 Fifth Ave,
St Morris, S.A. 5068
Australia
Ph: 041 8805 184 / 08 8332 5069
More information about the tex-live
mailing list