# Create list of abbreviations

I want to create something similar to \listoffigures, \listoftables etc. What I've done so far:

\def\startloa#1
{
\begingroup
\begin{listofabbrv}{SPMD}
\@input{\jobname.#1}
\end{listofabbrv}
\global\@nobreakfalse
\endgroup
\newpage
}

\newcommand{\listofabbreviations}
{
\@startloa{loa}
}

% abvr{abvr}{text}
\def\abvr#1#2
{
\makeatletter
\immediate\write\tempfile{\backslash item[#1] #2}
\makeatother
}

\newwrite\tempfile

\begin{document}

\immediate\openout\tempfile=\jobname.loa

\listofabbreviations

\abvr{NULL}{/dev/null}

\immediate\closeout\tempfile

\end{document}


The \begin/\end{listofabbvr} is predefined in the style I'm using, so I can't change it. Is it done this way:

\begin{listofabbrv}{SPMD}
\item[NULL] /dev/null
\end{listofabbrv}


The main problems:

• The \abvr command does not work. The file output is:

\delimiter "026E30F item[NULL] /dev/null


\item[NULL] /dev/null

• The command \listofabbreviations does not work. Is there something wrong with \def\startloa? A little snippet of the output log:

ERROR:
74  ! You can't use \spacefactor' in vertical mode.
75  \@->\spacefactor
76                   \@m
77  l.133   \listofabbreviations
78
79  ! Missing $inserted. --- x --- x --- ERROR: 79 ! Missing$ inserted.
80  <inserted text>
81                  $82 l.133 \listofabbreviations 83 84 ! Missing$ inserted.
--- x --- x ---
ERROR:
84  ! Missing $inserted. 85 <inserted text> 86$
87  l.134
88
89  [3]
--- x --- x ---

-

## migrated from stackoverflow.comJul 28 '11 at 16:41

This question came from our site for professional and enthusiast programmers.

I'll be happy solving the first problem (escaping ), the second can be solved with kind of a workaround. So if someone knows any way to print that char I'd appreciate. I've already tried \textbackslash, \\, $\$, \@backslashchar and none worked. –  Rodro Jul 28 '11 at 15:34
It's about @ in macro names: tex.stackexchange.com/questions/8351/… –  Andrey Vihrov Jul 28 '11 at 16:54
You could also try the nomencl or the glossaries packages. –  Andrey Vihrov Jul 28 '11 at 16:58

There are many problems in your code. TeX is not C, and

\def\x#1
{
...
}


is very different from

\def\x#1{...}


Here is a way to produce your list

\documentclass[a4paper]{article}
\makeatletter
\newcommand\@startloa{%
\begin{listofabbrv}{SPMD}
\InputIfFileExists{\jobname.loa}{}{\item[\null]}
\end{listofabbrv}
\newwrite\@loa
\immediate\openout\@loa=\jobname.loa
}
\newcommand{\listofabbreviations}{\@startloa}

% abvr{abvr}{text}
\def\abvr#1#2{\immediate\write\@loa{\unexpanded{\item[#1]#2}}}
\makeatother

\newenvironment{listofabbrv}[1]{\begin{itemize}}{\end{itemize}}

\begin{document}
\listofabbreviations

\abvr{NULL}{/dev/null}

\end{document}


The \newenvironment line is just to have a listofabbrv environment.

-
Unless I missed something, \provideenvironment` is an undefined control sequence. –  lockstep Jul 28 '11 at 17:10
@lockstep I keep forgetting it. :( –  egreg Jul 28 '11 at 17:39