# List of symbols/abbreviations and macros

It's on my task list for a while now, and this post made me ask a follow up question which is, in my mind, a missing part when setting such a list.

As an example, think of the standard notation of an n-dim space; I would use the following code to typeset it: \mathbb{R}^n. Then, in order to make things quicker, I would define a macro \newcommand*{\Rn}{\mathbb{R}^n}. So far so good. Now, I want to have a list of symbols as well. In short, the question is: what is the best practice to generate a list of symbols for complicated symbols?

Let me consider the nomencl package, but I think the question is valid when one is using other alternatives as well. Currently, I have a file where I define all the macros I am using in my document, similar to the one I gave as an example above. Then, in order to generate a list's entry I would add

\nomenclature{$\mathbb{R}^n$}{$n$-dimensonal real space}


where I use my macro \Rn for the first time. Is this the right/best way to go? One big drawback here is that when I would like to change the notation in the future, I will have to do it in two different places. Is there a smarter way to go? Somehow unify the two tasks of generating a list's entry and a macro which will be used in order to typeset the symbol later?

-

As long as you're sure that the first occurrence of \Rn is not in a section title or other moving argument, then you can define \Rn to emit the desired \nomenclature command and redefine itself:

\newcommand*{\Rn}{%
\nomenclature{$\mathbb{R}^n$}{$n$-dimensional real space}%
\gdef\Rn{\mathbb{R}^n}\mathbb{R}^n%
}


You can of course automatize this in a general macro:

\newcommand*{\definesymbol}[3]{%
\def#1{\nomenclature{$#2$}{#3}\gdef#1{#2}#2}%
}


and then say

\definesymbol{\Rn}{\mathbb{R}^n}{$n$-dimensional real space}


and similarly for other symbols.

Caution: this will break miserably if you say \section{Definition of $\Rn$} and this is the first appearance of \Rn.

If you plan using those symbols in section titles, the following modified definition should work:

\makeatletter
\newcommand*{\definesymbol}[3]{\def#1{%
\ifx\protect\@unexpandable@protect
#2%
\else
\nomenclature{$#2$}{#3}\gdef#1{#2}#2%
\fi}
}
\makeatother

-
 Regarding caution: Will using optional argument for section like \section[Definition of $\Rn$]{definition of $\mathbb{R}^n$} over come this failure? – Harish Kumar May 14 '12 at 9:24 @HarishKumar Yes; definitely. The first appearance of \Rn the next time the document is compiled would be in the table of contents! Putting \mathbb{R}^n in the optional argument and \Rn in the mandatory one might solve the issue. – egreg May 14 '12 at 9:27 Trying to make sure I understand, if the first time \Rn appears is in a section's title, then it should be produced by \section[Definition of $\mathbb{R}^n$]{Definition of $\Rn$}? – Dror May 14 '12 at 9:38 @egreg: Sorry. I typed reverse. So \section[Definition of $\mathbb{R}^n$]{definition of $\Rn$} (This is what I meant) solves it. I wonder whether there is any other fix for this problem besides optional argument? It will be nice of you if you incorporate all these remedies in to your answer. (already upvoted +1). – Harish Kumar May 14 '12 at 9:59 @Dror Yes. If I find time I'll think to a better way. Today is lecture day, starting at 11:30 and ending at 18:30; but the last two hours are the LaTeX course. :-) – egreg May 14 '12 at 12:42