3

I wonder how to use \gls or the package glossaries in general in a proper way in case of symbols and subscripts. For instance without glossaries, I'd just write

F_{trac}

or in case of in-text usage

$F_{trac}$

Using glossaries, I defined a symbol for force (sym:F) and the subscript for tractive (sub:trac) and write

\gls{sym:F}[_{\gls{sub:trac}}]

or in case of in-text usage

$\gls{sym:F}[_{\gls{sub:trac}}]$

I can't even spare the $$ here, which I do for alone standing symbols, which are surrounded by an \ensuremath{} in the definition. If two or more subscripts are required I use

\gls{sym:F}[_{\gls{sub:trac},\gls{sub:max}}]

Also, if one defines an

\gls{sym:F_trac}

there is no way of adding the \gls{sub:max} anymore, is there?

The quite short form

v_k

becomes

\gls{sym:v}[_{\gls{sub:k}}]

So my point is:

What is the way the package is intended to be used?

5
  • oh, my, nothing to do with glossaries, but "trac" in the usual math font is quite dreadful. \mathit{trac} is the proper thing if that should be italic, or \mathrm{trac} if it's better roman, indicating a short form of a term. Mar 12, 2015 at 18:58
  • Is it, @barbarabeeton? What's the difference? Can't see any, at least when it comes to appearance...
    – embert
    Mar 12, 2015 at 19:29
  • the kerning of the letters meant as math variables (which is what you get by default in math mode) is such that they more clearly appear as individual letters than as a word. replace "trac" by "effect" and you'll see what i am referring to. Mar 12, 2015 at 19:31
  • @barbarabeeton Interesting. Never thought about it.
    – embert
    Mar 12, 2015 at 19:51
  • Isn't one of the benefits of the glossaries package that your label inside \gls{} doesn't have to contain a formatted command on it's own? The name, first, and description can accept a wide variety of macro expansions simplifying the process and generating the proper formatting. I generate sub and superscripts all the time with the siunitx package inside the name entity of a glossary entry and I have never observed a problem with spacing or formatting consistency.
    – EngBIRD
    Jun 20, 2015 at 3:39

1 Answer 1

1

The manual (in section 6.1) states:

Don’t use any of the \gls-like or \glstext-like commands in the ⟨insert⟩ argument.

(where ⟨insert⟩ refers to the final optional argument) so it's not intended to be used in the form \gls{sym:v}[_{\gls{sub:k}}]. The main reason for this is because it causes nested links (if hyperref is used). The problem of nested links is mentioned in the glossaries FAQ entry Why shouldn't I use commands like \gls in \section, \chapter, \caption etc? but it can be demonstrated using the following MWE:

\documentclass[12pt]{article}

\usepackage[colorlinks]{hyperref}

\begin{document}

Targets: \hypertarget{k}{$k$}, \hypertarget{v}{$v$}.

Links: $\hyperlink{v}{v}_{\hyperlink{k}{k}}$.
$\hyperlink{v}{v_{\hyperlink{k}{k}}}$.

No links: $v_k$

\end{document} 

Image of output

The first case $\hyperlink{v}{v}_{\hyperlink{k}{k}}$ is analogous to \gls{v}_{\gls{k}}. Here there are two separate hyperlinks, but the spacing between the v and its subscript is slightly wider than the no links version.

The second case $\hyperlink{v}{v_{\hyperlink{k}{k}}}$ is analogous to \gls{v}[_{\gls{k}}]. This has a better spacing between the v and its subscript, but there is now a nested hyperlink. If you click on the k it may take you to the k target (\hypertarget{k}{$k$}) or it may take you to the v target (\hypertarget{v}{$v$}), depending on your PDF viewer.

(In either case you will need to use pdflatex rather than latex for the hyperlinked subscript to appear the correct size.)

Going back to glossaries, the usage really depends on how important it is to place each symbol in a hyperlink. If they all need to be hyperlinked, then it's best just to do \gls{k}_{\gls{v}}. If you're happy for k_v to just hyperlink to the entry for k then you can do $\gls{k}[_{\glsentrytext{v}}]$, which has better spacing between the k and the v:

\documentclass[12pt]{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries}

\makeglossaries

\newglossaryentry{k}{name={k},description={}}
\newglossaryentry{v}{name={v},description={}}

\begin{document}

$\gls{k}_{\gls{v}}$

$\gls{k}[_{\glsentrytext{v}}]$

\printglossaries

\end{document} 

Remember that you can define a command if this is too cumbersome to type. For example:

\newcommand*{\gsub}[2]{\gls{#1}[_{\glsentrytext{#2}}]}
\newcommand*{\gsubs}[3]{\gls{#1}[_{\glsentrytext{#2},\glsentrytext{#3}}]}

Now you can just do \gsub{v}{k} or \gsubs{v}{k}{j}. This won't add the subscript entries to the glossary, but this can be done by adjusting the definitions:

\newcommand*{\gsub}[2]{\gls{#1}[_{\glsentrytext{#2}}]\glsadd{#2}}
\newcommand*{\gsubs}[3]{\gls{#1}[_{\glsentrytext{#2},\glsentrytext{#3}}]\glsadd{#2}\glsadd{#3}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .