[Tex/LaTex] glossaries: display `see` reference but not page numbers

cross-referencingglossariespage-numbering

I am trying to display the see cross references but not the page numbers in my document.

I understood that it's impossible with the means provided by standard, so I tried to use
\renewcommand*{\glossaryentrynumbers}[1]{XXX}
(replace XXX with various things that I tried)

to fit my code. Unfortunately my lack of Latex knowledge is not very helpful.

What do I have to put instead of XXX to display the cross references, but not the page numbers?


Here is an example (sorry, I thought it was clear what I meant):

file: glossary.tex

\newacronym[see={{cutg}}]{cut}{CUT}{Code Under Test}
\newglossaryentry{cutg}{name={CUT},
    description={\acrfull{cut} refers to the part of the source code that is actually tested. It is a part of the entire source ode and modified before test generation. The tests are generated for the CUT, rather than the original source code. The CUT can be a function, a file or an entire component}
}

file: report.tex

\documentclass[twoside]{article}


%Glossary
\usepackage[xindy,acronym]{glossaries} % nomain, if you define glossaries in a file, and you use \include{INP-00-glossary}
\setacronymstyle{long-short}
\makeglossaries
\usepackage[xindy]{imakeidx}
\makeindex[title=List of Terms]
\loadglsentries[main]{../../glossary}
\renewcommand{\acronymfont}[1]{\textit{#1}} % make acronms italics
\renewcommand{\firstacronymfont}[1]{\textit{#1}}
\renewcommand*{\seename}{Glossary:} % What text should be used for the see-field
%\renewcommand*{\glossaryentrynumbers}[1]{\glsseelist} % turn off ugly numbers (don't use the option for usepackage, otherwise see doesn't work)
\begin{document}

\glsaddall
\printglossaries

\end{document}

When I compile, I produce this: Example with highlight

How can I get rid of the page numbers (highlighted through red rectangles in the image)?
I tried renewing the command that creates \glossaryentrynumbers, since the option [nonumberlist] apparently does the same (as far as I know, it calls

\renewcommand*{\glossaryentrynumbers}[1]{}

so my though process was that if I redefine it myself to only contain the see-list, then I should be sorted.

Best Answer

The seeautonumberlist package option is designed for use with the nonumberlist option to enable the location list for entries with the see key, but this is only intended when the entry with the see key is a synonym that's not used in the document (otherwise you get the rest of the location list appearing as well for that entry).

For example:

\documentclass{report}

\usepackage[nonumberlist,seeautonumberlist]{glossaries}

\makeglossaries

\newglossaryentry{sample1}{name={sample},description={an example}}
\newglossaryentry{sample2}{name={another sample},
 description={another example},
 see={sample1}}

\begin{document}
\chapter{Sample}

A \gls{sample1}.

\printglossaries
\end{document}

This produces:

image of glossary with no location list but cross-reference is present

If I add a reference to sample2 in the document like this:

\documentclass{report}

\usepackage[nonumberlist,seeautonumberlist]{glossaries}

\makeglossaries

\newglossaryentry{sample1}{name={sample},description={an example}}
\newglossaryentry{sample2}{name={another sample},
 description={another example},
 see={sample1}}

\begin{document}
\chapter{Sample}

A \gls{sample1} and \gls{sample2}.

\printglossaries
\end{document}

Then the page number also appears for sample2:

image of glossary with page number appearing before cross-reference

In this case, it's simpler to move the cross-reference into the description:

\documentclass{report}

\usepackage[nonumberlist]{glossaries}

\makeglossaries

\newglossaryentry{sample1}{name={sample},description={an example}}
\newglossaryentry{sample2}{name={another sample},
 description={another example, \emph{see} \gls{sample1}}}

\begin{document}
\chapter{Sample}

A \gls{sample1} and \gls{sample2}.

\printglossaries
\end{document}

This produces:

image of glossary with no location lists

(The glossaries user manual uses \gls in the description field in a similar manner.)

Another possibility is to use \glsseeformat which can accept a comma-separated list of labels and is the way the cross-reference is displayed in the location list when using the see key. If you use this command, remember that there are two mandatory arguments. The last one is provided for the benefit of makeindex and, although ignored by LaTeX, must be present.

\documentclass{report}

\usepackage[nonumberlist]{glossaries}

\makeglossaries

\newglossaryentry{sample1}{name={sample},description={an example}}

\newglossaryentry{sample2}{name={another sample},
 description={another example, \glsseeformat{sample1,sample3}{}}}

\newglossaryentry{sample3}{name={third sample},
 description={yet another example}}

\begin{document}
\chapter{Sample}

A \gls{sample1} and \gls{sample2}.

\printglossaries
\end{document}

This produces:

image of resulting glossary

The optional argument allows you to override the "see" tag:

\glsseeformat[see also]{sample1,sample3}{}

For abbreviations, you'll need to override the default description for styles like long-short. For example:

\setacronymstyle{long-short}
\newacronym[description={an example, see \gls{sample1}}]{anex}{anex}{an example}

Edit: Another possibility is to use the glossaries-extra extension package which stores the value of the see key (the base glossaries package doesn't do this). This means that the value of the see key can be accessed in the glossary when the number list has been suppressed. Version 1.06 of glossaries-extra adds a convenient to use command \glsxtrusesee{label} which makes it easier to access the value. This command does nothing if the see key is empty for label, otherwise it does \glsseeformat[tag]{xr list}{}, where the tag and cross-reference list are obtained from the see field.

The post-description hook can be modified to add this. For example:

\documentclass{report}

\usepackage[nonumberlist,nopostdot=false]{glossaries-extra}

\makeglossaries

\newglossaryentry{sample1}{name={sample},description={an example}}
\newglossaryentry{sample2}{name={another sample},
 description={another example},
 see={sample1}}

\renewcommand*{\glsxtrpostdescgeneral}{%
 \ifglshasfield{see}{\glscurrententrylabel}
 {, \glsxtrusesee{\glscurrententrylabel}}%
 {}%
}

\begin{document}
\chapter{Sample}

A \gls{sample1} and \gls{sample2}.

\printglossaries
\end{document}

This produces:

image of example

The glossaries-extra package also conveniently lets the see key trigger the automatic use of \glsxtraddallcrossrefs at the end of the document. This means that the following only requires the build sequence latex, makeglossaries, latex to include all the cross-references in the document:

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[nonumberlist,nopostdot=false]{glossaries-extra}

\makeglossaries

\renewcommand*{\glsxtrpostdescgeneral}{%
 \ifglshasfield{see}{\glscurrententrylabel}
 {, \glsxtrusesee{\glscurrententrylabel}}%
 {}%
}

\newglossaryentry{sample1}{name={sample 1},description={an example}}
\newglossaryentry{sample2}{name={sample 2},description={an
example},see={sample1}}
\newglossaryentry{sample3}{name={sample 3},description={an
example},see={sample2}}
\newglossaryentry{sample4}{name={sample 4},description={an
example},see=[see also]{sample2,sample3}}

\begin{document}
\gls{sample4}.

\printglossaries

\end{document}

This produces:

image of glossary