# Symbols as glossary entry indicators?

Concerning the book I am about to write, I brood over another subject, which merits in my view a separate thread.

As the book will be a classical paper book and not an e-book, I would like to mark any technical term in the text, which is explained in a glossary, so that the reader is aware whenever further explanation is available at the end of the book. Of course, the labelling shall be done in an unobtrusive way, so that the decent text layout will not be spoilt.

The use of different text styles (like italics, bold, different fonts, etc.) is not an option, as they are already applied for other highlighting purposes. Hence, I thought of some symbols alongside the technical term to be marked, like a \leftpointright after the term or a superscripted \diamond.

How can I realise that concretely with the package glossaries?

I think \defglsentryfmt is one way to define a prefix to the gls entry as shown in the text.

Since a 'classical' paper book is being designed, hyperref is not needed and as such no ugly splitted links occur.

\documentclass{article}

\usepackage{blindtext}
\usepackage{glossaries}

\makeglossaries
\newglossaryentry{foo}{%
name={Foo},
description={Foo is the Foo, nothing more}
}

\defglsentryfmt{$\rightarrow$\glsname{\glslabel}}

\begin{document}
\blindtext

\gls{foo}

\blindtext

\printglossaries

\end{document}

• Thank you very much. In order to test the code, I copied it into a new tex file. However the compilation fails with this error message: ERROR - Cannot find control file 'Glossary-Symbol-Test.bcf'! - did you pass the "backend=biber" option to BibLaTeX? INFO - ERRORS: 1 Is the package glossaries perhaps incompatible with the backend biber? – Oli Jan 8 '17 at 15:19
• @Oli: I don't have biblatex included, so your error is not related to my solution, since I don't use biber here – user31729 Jan 8 '17 at 15:20
• Great, it works - thanks! The symbol can also be placed after the term as a sufix. For those who are - like me - not so familiar with the compilation in a terminal, cf. [link] (texwelt.de/wissen/fragen/3461/…). – Oli Jan 8 '17 at 15:44
• Try adding \GLS{foo}, \glspl{foo}, \glsdisp{foo}{bar}. ;-) It's much better to do \defglsentryfmt{$\rightarrow$\glsgenentryfmt} instead. – Nicola Talbot Jan 9 '17 at 13:33
• @Oli The commands \gls, \Gls, \GLS, \glspl, \Glspl, \GLSpl and \glsdisp all use the same underlying code to determine what text is displayed when they're used (e.g. \gls shows the singular and \glspl shows the plural, alternate text may be supplied for first use, the upper case versions capitalise the text). This code is given by \defglsentryfmt for a particular glossary type, but the code given here forces it to always display the value of the name key regardless of the calling command (\gls, \GLS etc), so the variants no longer work as advertised. – Nicola Talbot Jan 11 '17 at 10:32

There are a number of different ways of changing the format used to display terms defined by the glossaries package. It depends on exactly which commands you want to affect.

Let's start with a MWE that has three glossary types: main (the default), acronyms and symbols:

\documentclass{article}

\usepackage[symbols,acronyms]{glossaries}

\makeglossaries

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.

\printglossaries
\end{document}


This produces:

The commands in the form \glsentry... (such as \glsentrytext) simply expand to the value of the appropriate key, without any formatting or indexing etc.

The \gls-like commands \gls, \Gls, \GLS, \glspl, \Glspl, \GLSpl and \glsdisp all have their format governed by \glsentryfmt by default, but the format for a particular glossary can be overridden using \defglsentryfmt, but any change to this format must apply various tests to determine the calling command and whether or not this is the first time the entry has been used. (See section 6.3 Changing the format of the link text of the user manual.) There's a convenient command \glsgenentryfmt which can be used for generic terms if only minor modifications are required. There are various different approaches if you want to change the format for abbreviations.

The \glstext-like commands such as \glstext and \glsname don't use this special display format, since the text to display is that supplied by the corresponding key when the entry was defined (possibly with any text inserted via the final optional argument, as in \glstext{matrix}['s]). So any change to \glsentryfmt or use of \defglsentryfmt won't make any difference to the way these commands are displayed.

Both the \gls-like and \glstext-like commands have their text wrapped with \glstextformat which by default just does its argument. The simplest way of showing how a change in this command modifies the document is to add some colour:

\documentclass{article}

\usepackage{color}
\usepackage[symbols,acronyms]{glossaries}

\renewcommand{\glstextformat}[1]{\textcolor{blue}{#1}}

\makeglossaries

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.

\printglossaries
\end{document}


This produces:

Note that \glsentrytext{matrix} hasn't been changed, nor have the names in the glossaries (except for the instance of \gls{matrix} which occurs in the description for the M entry).

So if you want an indicator for every use of the \gls-like or \glstext-like commands, you simply need to redefine \glstextformat as appropriate.

This get a little more complicated if you only want to change the format for certain types of entries or for certain types of commands. If you only want to change the format for the \gls-like commands, you can redefine \glsentryfmt or use \defglsentryfmt for a specific glossary.

Let's first try redefining \glsentryfmt to insert a prefix symbol:

\documentclass{article}

\usepackage{color}
\usepackage[symbols,acronyms]{glossaries}

\renewcommand{\glstextformat}[1]{\textcolor{blue}{#1}}
\renewcommand{\glsentryfmt}{$\rightarrow$\glsgenentryfmt}

\makeglossaries

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.

\printglossaries
\end{document}


This produces:

Note that the prefix doesn't appear for the acronym because the abbreviation mechanism has overridden the format for the acronym glossary using \defglsentryfmt, so \glsentryfmt isn't used for entries in that glossary.

Now let's suppose I remove the acronym package option so that the entries defined using \newacronym are placed in the main glossary instead of having their separate list:

\documentclass{article}

\usepackage{color}
\usepackage[symbols]{glossaries}

\renewcommand{\glstextformat}[1]{\textcolor{blue}{#1}}
\renewcommand{\glsentryfmt}{$\rightarrow$\glsgenentryfmt}

\makeglossaries

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.

\printglossaries
\end{document}


The document now looks like:

Now the only entry with a prefix is the M entry in the symbols glossary. This is because \newacronym has again triggered \defglsentryfmt for the glossary associated with its entry, which is now the main glossary.

This use of \defglsentryfmt by \newacronym can be overridden by adding another \defglsentryfmt after \newacronym, which I've done below. I've also added \glsname{filo} (which is a \glstext-like command that uses the text supplied by the name field).

\documentclass{article}

\usepackage{color}
\usepackage[symbols]{glossaries}

\renewcommand{\glstextformat}[1]{\textcolor{blue}{#1}}
\renewcommand{\glsentryfmt}{$\rightarrow$\glsgenentryfmt}

\makeglossaries

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\defglsentryfmt{\glsentryfmt}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.
Name: \glsname{filo}.

\printglossaries
\end{document}


This now produces:

This doesn't use the prefix for \glsname but rather confusingly has the prefix twice in \acrfull in front of the long form and then in front of the short form.

Setting the acronym style using \setacronymstyle drops both prefixes from \acrfull but the use of \defglsentryfmt has broken the acronym style, which relies on the entry format using \glsgenacfmt for abbreviations and \glsgenentryfmt for non-abbreviations:

\documentclass{article}

\usepackage{color}
\usepackage[symbols]{glossaries}

\renewcommand{\glstextformat}[1]{\textcolor{blue}{#1}}
\renewcommand{\glsentryfmt}{$\rightarrow$\glsgenentryfmt}

\makeglossaries

\setacronymstyle{long-short}

\newglossaryentry{matrix}{name={matrix},plural={matrices},
description={rectangular array of quantities}}

\newglossaryentry{M}{type=symbols,name={\ensuremath{\boldsymbol{M}}},sort=M,
description={a \gls{matrix}}}

\newacronym{filo}{FILO}{first in last out}

\defglsentryfmt{\glsentryfmt}

\begin{document}
A \gls{matrix}, denoted \gls{M}. Lots of \glspl{matrix}.
\Glspl{matrix} are a rectangular array of quantities.
The identity \gls{matrix}['s] diagonal consists of ones.

First use: \gls{filo}. Next use: \gls{filo}.
Full form: \acrfull{filo}.
Name: \glsname{filo}.

\printglossaries
\end{document}


Instead, the entry format must check for abbreviations which can be done with \ifglshasshort:

\renewcommand{\glsentryfmt}{%
$\rightarrow$\ifglshasshort{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}}


This modification produces:

This has corrected the first use of the abbreviation, but there's still no prefix in front of \glsname since that command isn't governed by \glsentryfmt (or \defglsentryfmt).

You can introduce some variations. For example, only prefix regular terms (not abbreviations):

\renewcommand{\glsentryfmt}{%
\ifglshasshort{\glslabel}{\glsgenacfmt}{$\rightarrow$\glsgenentryfmt}}


Or only prefix on first use:

\renewcommand{\glsentryfmt}{%
\ifglshasshort{\glslabel}
{\glsgenacfmt}% abbreviation
{\ifglsused{\glslabel}{}{$\rightarrow$}\glsgenentryfmt}% regular term
}


There's even more flexibility with the glossaries-extra package where entries can be assigned categories, and minor adjustments can be made according to the category or the category's attributes. (See this example from the glossaries-extra gallery.)

When redefining \glsentryfmt or using \defglsentryfmt, it's important to remember not to break the checks that determine the calling command (\gls, \glspl etc) which are performed by \glsgenentryfmt and \glsgenacfmt.

For example, the following modification breaks the document:

\renewcommand{\glsentryfmt}{$\rightarrow$\glsentryname{\glslabel}}


This produces:

The plural form \glspl{matrix} has been rendered as singular. The case change in \Glspl{matrix} has been lost (as well as being reduced to the singular form). The inserted material in the optional argument of \gls{matrix}['s] has been lost. The abbreviation no longer shows the long form on first use. Using \glsname rather than \glsentryname makes things even worse as it nests the rather complicated internal command used by both \gls and \glsname, and anyone adding hyperref to the document may encounter problems caused by nested hyperlinks.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8643929362297058, "perplexity": 3961.777136761521}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579250589861.0/warc/CC-MAIN-20200117152059-20200117180059-00125.warc.gz"}