[tex-live] Nested macro resetting problem

Zdenek Wagner zdenek.wagner at gmail.com
Sat Jun 13 20:42:05 CEST 2009


Hi Geoffrey,
the easiest way is probably making use of grouping. Try the following
file, it shows different aspects. Notice that the macros must be
\protect'ed in moving arguments.

\documentclass{book}
\def\newabbr#1#2{\expandafter\def\csname #1\endcsname
    {#2 (#1)\expandafter\def\csname #1\endcsname{#1}}}

\newabbr{TUG}{\TeX\ Users Group}
\begin{document}
\tableofcontents
\begin{chapter}{The first chapter}
\TUG

\TUG
\end{chapter}

\begin{chapter}{Another chapter}
\TUG

\TUG
\end{chapter}

\begin{chapter}{Another chapter on \protect \TUG}
\TUG

\TUG
\end{chapter}

\begin{chapter}[The Last chapter]{\protect\TUG}
\TUG

\TUG
\end{chapter}

\begin{chapter}{\protect\TUG\ again}
\TUG

\TUG
\end{chapter}

\begin{chapter}*{Do not put me into toc}
\TUG

\TUG
\end{chapter}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

2009/6/13 Geoff Russell <geoffrey.russell at gmail.com>:
> When writing I like to put the full name of an organisation at the
> first reference
> and its initials subsequently:
>
> e.g., The TeXLive User Group (TUG) is always helpful in solving my
> problems, because
> TUG people are smarter than the average bear.
>
> So I want to say:  The \TUG/ is always helpful in solving my problems
> because \TUG/ people are smarter than the average bear.
>
> Easy,
>
> \def\TUG/{TeXLive User Group(TUG) \def\TUG/{TUG}}
>
> And I have a couple of dozen in the book, so I want
> \newabbr{TUG}{TeXLive User Group}
>
> Now comes the hard bit,  I want to reset these at the start of each chapter.
>
> \def\mychapter#1{\resetdefs
> \chapter{#1}
> }
>
> So I'm trying:
>
> \def\newabbr#1#2{%
> \edef\nnnn{\resetdefs}%
> \expandafter\def\csname#1\endcsname/{#2 (#1)
> \expandafter\def\csname#1\endcsname/{#1}}%
> \def\resetdefs{\nnnn \expandafter\def\csname#1\endcsname/{#2 (#1)}}%
> }
>
> But I'm getting a recursion error, input stack full.
>
> Any ideas?
>
> Cheers,
> Geoff Russell
>



-- 
Zdeněk Wagner
http://hroch486.icpf.cas.cz/wagner/
http://icebearsoft.euweb.cz


More information about the tex-live mailing list