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.
Best Answer
As barbara mentioned, you can use
\ensuremath
like this: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 toL_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:Both the above examples produce: