Inspired by this great answer I tried to manually create a glossary-style environment for a simple list of symbols. Basically I wanted to create a command newsymbol
that can be executed from anywhere in the text and adds the new symbol together with a short explanation and the page number to a list of symbols at the end of the text. This is what I tried:
\documentclass{amsbook}
\usepackage{lstdoc,longtable}
\begin{document}
\makeatletter
\def\symbollist{}
\let\sort\lst@BubbleSort
\def\addtolist#1#2{
\lst@lAddTo\symbollist{#2}
}
\long\gdef\addterm#1#2{\addtolist\symbollist{#1,}}
\def\newsymbol#1#2#3{%
\long\expandafter\gdef\csname#1\endcsname{#2 & #3 & \thepage}
\addterm{#1}{#2}
\sort\symbollist
}
\def\PrintListOfSymbols{%
\begin{longtable}{r p{.8\textwidth} l}
\@for \i:=\symbollist\do{%
\csname\i\endcsname \\ }
\end{longtable}
}
\chapter{Contents}
Here the integers $\mathbb{Z}$ appear first.\newsymbol{Z}{$\mathbb{Z}$}{integers} \newpage
Here the other symbols appear first: $\mathbb{R},\mathbb{N}$. \newsymbol{R}{$\mathbb{R}$}{real numbers} \newsymbol{N}{$\mathbb{N}$}{natural numbers}
\begin{center} The entry from inside an environment does not appear. \newsymbol{Q}{$\mathbb{Q}$}{rational numbers} \end{center}
\chapter{List of Symbols}
\PrintListOfSymbols
\makeatother
\end{document}
The first argument of newsymbol
is just used for the sorting of the entries. Here is what the list looks like:
There are basically two problems yet to resolve:
- The page numbers are not correct, the
\thepage
variable returns the page where the list of notations is printed. How can I give a command the page number where the command is executed as an argument? - The command does nothing when executed from within an environment. How to fix that?
I'd be grateful for your help!
Best Answer
After some more debugging I got everything to work. In case anyone is interested, here is a working version: