[tex-live] Nested macro resetting problem

enrico.gregorio at univr.it enrico.gregorio at univr.it
Sun Jun 14 10:55:26 CEST 2009


This is not the right place for this kind of problems; however, here is a different solution.
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


More information about the tex-live mailing list