views:

224

answers:

3

I'm trying to get an auto generated list of symbols in my latex project. Here is the macro that I have so far...

\newcommand{\addsymbol}[3]{%
  \symboldisplay{#1}{#2}\\%
  \setelem{#3}{#1}
}
\newcommand{\symboldisplay}[2]{%
  $#1$ \parbox{5in}{\dotfill #2}%
}

\def\setelem#1{\expandafter\def\csname myarray(#1)\endcsname}
\def\dispsymbol#1{\csname myarray(#1)\endcsname}

I then include my list of symbols like so

\begin{listofsymbols}
\input{symbols}
\end{listofsymbols}

where the symbols.tex file is

\addsymbol{n}{Number of sample points}{num_points}
\addsymbol{f_s}{Sampling frequency}{samp_frequency}

I can then get my symbol by label like so: \dispsymbol{num_points} -- this displays n in this case.

This works all find and dandy... when I am calling \dispsymbol in the same chapter (the List of Symbols chapter) as the \addsymbol def. When I try to get the label for the symbol in another chapter nothing seems to work.

Could anyone help me, or suggest a package that will do what I am looking for?

+3  A: 

To automatically generate a list of symbols you can use the nomencl package, or for more complex documents that requires also glossaries or lists of acronyms, the glossaries package.

Check the examples in the documentation ;)

Alessandro C.
I have looked at nomencl and it looks good, but the other code dose what I want. Plus i get to say I wrote it mostly by myself :)Thanks
Brian
+3  A: 

The thing is that

\begin{listofsymbols} 
\end{listofsymbols} 

is the scope and any macro is lost after this group. You should define the global macros. Replace the following

\def\setelem#1{\expandafter\def\csname myarray(#1)\endcsname} 

with

\def\setelem#1{\expandafter\gdef\csname myarray(#1)\endcsname} 
Alexey Malistov
Alexey,This worked, thanks alot.
Brian
A: 

Hello I am trying to implement your algorithm in my thesis. I've searched all around, you seem to be simplest solution for building a symbol list, congrats. but I don't understand under what name should I save it? I tried listofsymbols.txt and listofsymbols.tex but it didn't worked.

thanks for sharing.

\newcommand{\addsymbol}[3]{% \symboldisplay{#1}{#2}\% \setelem{#3}{#1} } \newcommand{\symboldisplay}[2]{% $#1$ \parbox{5in}{\dotfill #2}% }

\def\setelem#1{\expandafter\def\csname myarray(#1)\endcsname} \def\dispsymbol#1{\csname myarray(#1)\endcsname}

victor carreto