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'm having a weird problem with glossaries (TeXLive 2011, glossaries v3.01), illustrated by the following example:

% compile this with
%    pdflatex example.tex
%    makeindex  -s "example.ist" -t "example.alg" -o "example.acr" "example.acn"
%    pdflatex example.tex

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{bm}
\usepackage[acronym,nomain]{glossaries}
\newglossary[slg]{symbolslist}{syi}{syg}{Symbole}
\makeglossaries

\newcommand{\vect}[1]{\bm{#1}}
%\newcommand{\cvect}[1]{\overline{\vect{#1}}}
\newcommand{\cvect}[1]{\underline{\vect{#1}}}

\newglossaryentry{sym:sc}{name={\ensuremath{\cvect{s}}},description={some complex vector},type=symbolslist}

\begin{document}

\gls{sym:sc}

\ensuremath{\underline{\bm{s}}}

\printglossary[type=symbolslist]

\end{document}

In my document, I need to typeset complex-valued vectors in boldfaced, italic letters with a line below, see the \cvect definition. This works as expected, except if I'm trying to use it for a symbol definition along with the glossaries package. Then, the pdflatex run is interrupted with a missing $ error.

The weird thing about this is: if I use \overline instead of \underline in the definition of \cvect, everything works as expected (see the commented version of \cvect).

My first idea was that this could be a problem with \ensuremath, however, when using it without \newglossaryentry (i.e., just in the document body), it works as expected.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

\underline is not robust. Try something like this:

\newcommand\cvect{}
\DeclareRobustCommand\cvect[1]{\underline{\vect{#1}}}
share|improve this answer
add comment

In the documentation of glossaries you can find the following hint:

sort This value indicates how makeindex or xindy should sort this entry. If omitted, the value is given by the name field. In general, it’s best to use the sort key if the name contains commands (e.g. \ensuremath{\alpha}). Note that the package options sort=def and sort=use override the sort key in \newglossaryentry.

Ulrike mentioned that \underline isn't robust. Instead of \underline you can use the command \uline provided by the package ulem

\usepackage[normalem]{ulem}

\newcommand{\cvect}[1]{\uline{\ensuremath{\vect{#1}}}}

\newglossaryentry{sym:sc}{sort=s,name={\cvect{s}},description={some complex vector},type=symbolslist}

Christoph Spiegel mentioned the very interesting information of the documentation ulem:

The various underlining commands are essentially textual, and will not work quite the same in math mode. But since some font commands, in A the old-L TEX style (‘oldlfont’) serve both for text and math, math mode is handled (in an approximate way). Generally, you should avoid using ulem’s commands within math, but math may appear in the text argument to ulem’s commands.

share|improve this answer
    
I'm sorry, in my minimal example, I omitted the sort parameter of \newglossaryentry. In my actual document, I'm using text-only tags for the sort parameter for exactly the reason that is mentioned in the glossaries manual. Thanks for then hint with \ulem anyway! –  Christoph Nov 9 '11 at 13:06
    
In the ulem docs, it says: "Generally, you should avoid using ulem’s commands within math, but math may appear in the text argument to ulem’s commands." -- I think one should therefore better not use it with math. –  Christoph Nov 9 '11 at 13:10
    
@christoph.spiegel: You are right. Thanks. I had never read this. Now \uline is outside the math-environment ;-) –  Marco Daniel Nov 9 '11 at 13:13
    
I see :), but that won't work for me since I will usually have an index for such a vector (like \cvect{s}_\mathrm{1}), which shall not be included in the underlining. So I'll better stick to Ulrike's suggestion. –  Christoph Nov 9 '11 at 13:28
    
@christoph.spiegel: Of course ;-) –  Marco Daniel Nov 9 '11 at 13:29
add comment

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.