[Tex/LaTex] How to get the first use of a glossary to show the full description

formattingglossaries

I am using the glossaries package with the acronym option to display multiple lists of acronyms and symbols. Using \glsresetall makes the next use of any acronym appear with the full description but this does not happen for the symbols. I can not use the acronym format for the other glossaries as they include values and units.

How can I make the first use of a glossary give the full format, as the first use of an acronym does?

MWE:

\documentclass{report}
\usepackage{siunitx}
\usepackage[nomain, acronym, section=section]{glossaries}              % use glossaries-package

\setlength{\glsdescwidth}{15cm}

\newglossary[slg]{symbolslist}{syi}{syg}{Symbolslist} % create add. symbolslist


\glsaddkey{symbolvalue}{\glsentrytext{\glslabel}}{\glsentrysymbolvalue}{\GLsentrysymbolvalue}{\glssymbolvalue}{\Glssymbolvalue}{\GLSsymbolvalue}
\glssetnoexpandfield{symbolvalue}

\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}
\glssetnoexpandfield{unit}

\makeglossaries                                   % activate glossaries-package

\newglossaryentry{lightspeed}{
  name=\ensuremath{c},
  description={speed of light},
  symbolvalue={299792432},
  unit={\si{\meter/\second}},
  type=symbolslist
}

\newacronym[longplural={Frames per Second}]{fps}{FPS}{Frame per Second}

\newglossarystyle{mylist}{%
% put the glossary in the itemize environment:
\renewenvironment{theglossary}{\setlength{\LTleft}{0pt}\begin{longtable}{l>{\raggedright}p{.4\textwidth}>{\raggedleft}p{0.3\textwidth}r}}{\end{longtable}}%
% have nothing after \begin{theglossary}:
\renewcommand*{\glossaryheader}{%  Change the table header
   Sign &  Description & Value & Unit \\
  \endhead}
% have nothing between glossary groups:
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glsgroupskip}{}%
% set how each entry should appear:
\renewcommand*{\glossentry}[2]{%  Change the displayed items
  \glstarget{##1}{\glossentryname{##1}} %
  & \glossentrydesc{##1}% Description
  & \glssymbolvalue{##1}
  & \glsunit{##1}%
  \tabularnewline
}
}

\begin{document}

\glsaddall
\printglossary[type=symbolslist,style=mylist]   % list of symbols
\printglossary[type=\acronymtype] % prints just the list of acronyms

\glsresetall

Now the first use of the acronym gives \gls{fps}

But the first use of the symbol gives \gls{lightspeed}, whereas I want it to give \glsdesc{lightspeed} (\glsname{lightspeed})

\end{document}

Result:

Result

Best Answer

The basic behaviour of \gls is to show the value of the first key on first use and the value of the text key on subsequent use. If the text key isn't set explicitly, it's assumed to be the same as the name key. If the first key isn't set, it's assumed to be the same as the text key.

So, with

\newglossaryentry{lightspeed}{
  name=\ensuremath{c},
  description={speed of light},
  symbolvalue={299792432},
  unit={\si{\meter/\second}},
  type=symbolslist
}

there's an implied text={\ensuremath{c}} and first={\ensuremath{c}}, which is why only the symbol is shown on first use.

The original \newacronym used by the base glossaries package without using \setacronymstyle automatically sets the first key to the long form followed by the short for in parentheses and the text key is set to the short form, so

\newacronym[longplural={Frames per Second}]{fps}{FPS}{Frame per Second}

is basically doing

\newglossaryentry{fps}{
  name={fps},
  description={Frame per Second},
  first={Frame per Second (FPS)},
  firstplural={Frames per Second (FPSs)},
  text={FPS},
  plural={FPSs}
}

which is why on first use the description is shown.

(This is quite a simplistic way of dealing with abbreviations and doesn't allow much flexibility in style, so \newacronymstyle alters the way that \gls behaves so that entries defined using \newacronym are treated differently to entries that are defined directly with \newglossaryentry.)

One possible solution is to define a command for symbols that sets up the first key in much the same way that the original \newacronym works. This helps to maintain a consistent style for all your symbols.

For example:

\documentclass{report}
\usepackage{siunitx}
\usepackage[nomain, acronym, section=section]{glossaries}              % use glossaries-package

\setlength{\glsdescwidth}{15cm}

\newglossary[slg]{symbolslist}{syi}{syg}{Symbolslist} % create add. symbolslist


\glsaddkey{symbolvalue}{\glsentrytext{\glslabel}}{\glsentrysymbolvalue}{\GLsentrysymbolvalue}{\glssymbolvalue}{\Glssymbolvalue}{\GLSsymbolvalue}
\glssetnoexpandfield{symbolvalue}

\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}
\glssetnoexpandfield{unit}

\makeglossaries                                   % activate glossaries-package

% \newsymbol[options]{label}{symbol}{unit}{symbolvalue}{description}
\newcommand*{\newsymbol}[6][]{%
  \newglossaryentry{#2}{name={#3},% symbol
   first={#6 (#3)},% description (symbol)
   symbolvalue={#5},
   unit={#4},
   type={symbolslist},
   description={#6},#1}%
}

\newsymbol{lightspeed}{\ensuremath{c}}{\si{\meter/\second}}{299792432}
{speed of light}

\newacronym[longplural={Frames per Second}]{fps}{FPS}{Frame per Second}

\newglossarystyle{mylist}{%
% put the glossary in the itemize environment:
\renewenvironment{theglossary}{\setlength{\LTleft}{0pt}\begin{longtable}{l>{\raggedright}p{.4\textwidth}>{\raggedleft}p{0.3\textwidth}r}}{\end{longtable}}%
% have nothing after \begin{theglossary}:
\renewcommand*{\glossaryheader}{%  Change the table header
   Sign &  Description & Value & Unit \\
  \endhead}
% have nothing between glossary groups:
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glsgroupskip}{}%
% set how each entry should appear:
\renewcommand*{\glossentry}[2]{%  Change the displayed items
  \glstarget{##1}{\glossentryname{##1}} %
  & \glossentrydesc{##1}% Description
  & \glssymbolvalue{##1}
  & \glsunit{##1}%
  \tabularnewline
}
}

\begin{document}

\glsaddall
\printglossary[type=symbolslist,style=mylist]   % list of symbols
\printglossary[type=\acronymtype] % prints just the list of acronyms

\glsresetall

Now the first use of the acronym gives \gls{fps}

First use of \gls{lightspeed}.

Next use of \gls{lightspeed}.
\end{document}

This produces:

image of document

You might also want to consider overriding the default sort value as makeindex doesn't recognise LaTeX markup and so will see \ensuremath{c} as the sequence of characters \ e n s u r e m a t h { c }.

There are several methods depending on what the other symbols are likely to be. If they're mostly just Latin characters in maths mode, then you could so something like:

\newcommand*{\newsymbol}[6][]{%
  \newglossaryentry{#2}{name={$#3$},% symbol
   sort={#3},
   first={#6 ($#3$)},% description (symbol)
   text={\ensuremath{#3}},
   symbolvalue={#5},
   unit={#4},
   type={symbolslist},
   description={#6},#1}%
}

\newsymbol{lightspeed}{c}{\si{\meter/\second}}{299792432} {speed of light}

In this case, the sort value is now just c.

Alternatively, you could sort by the symbol value if they're all constants:

\newcommand*{\newsymbol}[6][]{%
  \newglossaryentry{#2}{name={$#3$},% symbol
   sort={#5},
   first={#6 ($#3$)},% description (symbol)
   text={\ensuremath{#3}},
   symbolvalue={#5},
   unit={#4},
   type={symbolslist},
   description={#6},#1}%
}

\newsymbol{lightspeed}{c}{\si{\meter/\second}}{299792432} {speed of light}

In this case, the sort value is 299792432 which makeindex recognises as a number rather than a string.