5

I'm struggling with glossaries package for a while...

I would like to change the standard alignment in the link text of \gls. I've used example code from equation variables:

\documentclass{report}

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

\newcommand{\mathgloss}[2]{
    \newglossaryentry{#1}{name={#1},description={#2}}
    \gls{#1} = #2
}

\begin{document}

Consider the equation
\begin{equation}
e = m * c^2
\end{equation}
in which\\
\mathgloss{e}{energy}\\
\mathgloss{m}{mass}\\
\mathgloss{c}{speed of light}

\printglossaries

\end{document}

..and got the results:

example

I would like to change the alignment of the all descriptions to be more like in a table. I tried putting the code in the regular table but it didn't work.

I also tried the code below, but the question is the same.

\documentclass{article}
\usepackage[nopostdot,nonumberlist]{glossaries}

 \makeglossary

  \newglossaryentry{aaaaaa}{name=aaaaaa,description={speed of light},symbol={km/s}}
  \newglossaryentry{b}{name=b,description={mass},symbol={kg}}

  \renewcommand{\glstextformat}[1]{\small{#1}}
  \renewcommand*{\glsentryfmt}{%
  \glsgenentryfmt
  \ifglsused{\glslabel}{}{\space -\space \glsentrydesc{\glslabel}}{,\space \glsentrysymbol{\glslabel}}%}

 \begin{document}
 \gls{aaaaaa} \\
 \gls{b}

 \printglossaries
 \end{document}

Do you have any suggestions how to do this ? Or maybe there is a different/better approach to have equation variables description below the equation and at the same time in the glossary ?

1 Answer 1

4

What about using a description environment used in this way (requires enumitem):

\newcommand{\mathgloss}[2]{%
    \newglossaryentry{#1}{name={#1},description={#2}}%
    \begin{description}[labelwidth=3em]%
      \item[\gls{#1}]#2%
    \end{description}%
}

MWE:

\documentclass{report}
\usepackage{enumitem}

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

\newcommand{\mathgloss}[2]{%
    \newglossaryentry{#1}{name={#1},description={#2}}%
    \begin{description}[labelwidth=3em]%
      \item[\gls{#1}]#2%
    \end{description}%
}

\begin{document}

Consider the equation
\begin{equation}
e = m * c^2
\end{equation}
in which
\mathgloss{e}{energy}
\mathgloss{m}{mass}
\mathgloss{c}{speed of light}

\printglossaries

\end{document} 

Output:

enter image description here

If you want to adjust the spacing between items, you can work on the description's parameters topsep and partopsep. For example, with the configuration partopsep=0pt,topsep=0pt, you have the spacing like in normal paragraphs

\newcommand{\mathgloss}[2]{%
    \newglossaryentry{#1}{name={#1},description={#2}}%
    \begin{description}[labelwidth=3em,partopsep=0pt,topsep=0pt]%
      \item[\gls{#1}]#2%
    \end{description}%
}

enter image description here

In my opinion, anyway, it looks better with only topsep=0pt

\newcommand{\mathgloss}[2]{%
    \newglossaryentry{#1}{name={#1},description={#2}}%
    \begin{description}[labelwidth=3em,topsep=0pt]%
      \item[\gls{#1}]#2%
    \end{description}%
}

enter image description here

6
  • This looks very nice @karlkoeller :) Do you know how to change line spacing only in the equation description ?
    – Michal
    Jan 10, 2014 at 21:30
  • @Michal Of course, see the edited question. Remember that you can accept the answer, if it solves your problem, see How do you accept an answer? Jan 11, 2014 at 6:47
  • @Michal You're welcome. Happy to help. Jan 11, 2014 at 20:18
  • Using this code I wasn't able to use as a name e_{2} or $e_{2}$ nor \ensuremath{e_{2} Do you have any suggestions how to fix this ?
    – Michal
    Jan 11, 2014 at 22:16
  • 1
    @Michal $e_{2}$ works fine for me. Try deleting the .gls file before recompiling. Jan 12, 2014 at 6:59

You must log in to answer this question.

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