Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I describe complex protocols with lots of variables in different files. The problem is that I might change the variable names later. My idea was to define variable names as Latex commands like \lengthtree (instead of writing e.g. $\ell_t$). Later I can easily change \lengthtree to $L_t$ by just redefine the latex command.

Now I want to create a list of symbols and I am searching for a possibility to create it automatically. I give the glossaries package a try, but I get Latex errors if I use the symbols in math environments.

What would be the "state-of-the-art" solution to define my variables (which can be used also in math mode) at one global point? A list of symbols should be created automatically.

share|improve this question
1  
i may be misinterpreting something, but this seems like a compelling reason to use \ensuremath. –  barbara beeton Oct 11 '13 at 16:42
1  
By symbol directory, do you mean list of symbols? –  Jubobs Oct 11 '13 at 16:48
    
@barbarabeeton: Oh thx, yes this would work but I have read that \ensuremath comes with a lot of problems. Other solutions? –  user4811 Oct 11 '13 at 17:08
    
@Jubobs: yes, sorry I am not a native speaker... –  user4811 Oct 11 '13 at 17:09
1  
if you're using amsmath, they you might try \text{$...$} as the expansion of your symbol code. \text ensures the correct size in sub- and superscripts, but it's expected to be used within a math context, so if you use it in text (such as in an ordinary sentence, or even as the entry for your symbols list), you need to put it in $...$'. and if any of these symbols are supposed to be large operators (like \sum`), this also won't automatically go into \displaystyle in a display equation. –  barbara beeton Oct 11 '13 at 17:16

2 Answers 2

up vote 12 down vote accepted

As barbara mentioned, you can use \ensuremath like this:

\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\newglossaryentry{lengthtree}%
{%
  name={\ensuremath{L_t}},
  description={description here},
  sort={L}
}

\begin{document}

In line: \gls{lengthtree}. In math mode: 
\[
  \gls{lengthtree}
\]

\printglossary[title={List of Symbols}]

\end{document}

The arguments against \ensuremath come down to two main issues (see When not to use \ensuremath for math macro?):

Firstly, you might end up with $ inside the argument of \ensuremath. This won't occur in this example, as the argument of \ensuremath is being explicitly set to L_t.

Secondly, there is an issue of semantics. Following this line of argument, you should define the entry without \ensuremath and do $\gls{lengthtest}$, which is fine in the document text that you type, but this will cause a problem in the glossary where the style doesn't automatically shift to math mode when it comes to the entry name. Personally, I think \ensuremath is okay in this context, but for the purists who can't stand it, here's an alternative solution:

\documentclass{article}

\usepackage{glossaries}

\makeglossaries

\newglossaryentry{lengthtree}%
{%
  name={$L_t$},
  text={L_t},
  description={description here},
  sort={L}
}

\begin{document}

In line: $\gls{lengthtree}$. In math mode: 
\[
  \gls{lengthtree}
\]

\printglossary[title={List of Symbols}]

\end{document}

Both the above examples produce:

Image of document

share|improve this answer
1  
Of course I like best the second solution. ;-) –  egreg Oct 12 '13 at 11:16
    
@egreg I had a feeling you might :-) –  Nicola Talbot Oct 12 '13 at 13:24
    
Thx Nicola! I played with both solution and I prefer this solution. No problems so far and the package puts only symbols in the list which I have used. –  user4811 Oct 12 '13 at 13:42

I think you mean something like this, that defines the commands and makes a list at the same time.

enter image description here

\documentclass{article}

\newcommand\mysymbol[3]{%
\protected\gdef#1{#2}%
\item[$#2$]#3}

\begin{document}

\section*{List of symbols}

\begin{description}
\mysymbol{\zzz}{z_z^z}{Something about $Zzzzz$.}
\mysymbol{\Txxx}{Tx_{xx}}{The xx component of T.}
\mysymbol{\vvvv}{V_2}{$V$, the second.}
\mysymbol{\vvvvv}{V_3}{$V$, the third.}
\end{description}
\section{zzz}

\[ \zzz=\Txxx\]
where
\[\vvvv=3\]
and
\[\vvvvv=X\]

\end{document}
share|improve this answer
    
I prefer the solution from Nicola but your solution is also nice. Thanks for your help!!! –  user4811 Oct 12 '13 at 13:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.