[Tugindia] Help me write a macro? (writing out strings to a file)

Ajay Narottam Shah ajayshah at mayin.org
Tue Sep 13 17:02:49 CEST 2005


> \documentclass[a4paper]{book}
> \usepackage{xspace}
> 
> \newwrite\keywrite
> 
> \def\keyword#1{\IfFileExists{\thechapter.keywords}%
>     {\immediate\write\keywrite{\string\key{#1}\string\\}}%
>     {\immediate\openout\keywrite=\thechapter.keywords
>      \immediate\write\keywrite{\string\key{#1}\string\\}}%
>     \textbf{#1}\xspace}
> 
> \def\key#1{\textsl{#1}}%
> 
> \def\tableofkeywords{%
>      \IfFileExists{\thechapter.keywords}%
>       {\immediate\closeout\keywrite
>        \section*{Keywords}%
>        \input{\thechapter.keywords}%
>       }%
>       {\typeout{Keywords File not available}}%
>      }
> 
> %---------------------------------------------------
> 
> \begin{document}
> 
> \chapter{One}
> 
> This is a keyword test.
> \keyword{One}
> \keyword{A}
> \keyword{B}
> \keyword{Keywords}
> 
> \tableofkeywords
> 
> \chapter{Two}
> 
> This is another chapter to test keywords.
> 
> \keyword{Two}
> \keyword{Another}
> \keyword{Ajay}
> 
> \tableofkeywords
> 
> \end{document}

Wow! Where would we be without CVR? Three-quarters of my
book-setup-style-file is by him.

This code will be widely useful. It ought to be in a keywords.sty

-- 
Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi



More information about the tugindia mailing list