Method 1:
(I've simplified your example a little.) Rather than redefining \glsnumberformat
, I think it's better to make the modification to your new glossary style:
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[hyperindex, breaklinks,
linktoc=all,
pdfborder={0 0 0}]{hyperref}
% List of abbreviations
\usepackage[acronym,toc]{glossaries}
\makeglossaries
\glsnoexpandfields
% Enable entry counting
\glsenableentrycount
% Columns in acronym table
\newglossarystyle{mylong}{%
\setglossarystyle{long}%
\renewenvironment{theglossary}%
{\begin{longtable}[l]{@{}p{\dimexpr 2cm-\tabcolsep}p{0.8\hsize}}}% <-- change the value here
{\end{longtable}}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription\space
\ifnum\glsentryprevcount{##1}=1\relax
page
\else
pages
\fi
##2\tabularnewline
}%
}
\newacronym{TLS}{TLS}{Transport Layer Security}
\newacronym{aa}{AA}{Another Abbreviation}
\begin{document}
\frontmatter
\tableofcontents
\printglossary[type=\acronymtype,style=mylong,title=Abbreviations]
\mainmatter
\chapter{Sample Chapter}
\section[\glsentryshort{TLS}]{\acrshort{TLS}}
\gls{aa}.
\newpage
\subsection{Section}
\chapter{Other chapter}
\acrfull{TLS}
\backmatter
\appendix
\setcounter{page}{1}
\renewcommand{\thepage}{A\arabic{page}}
\chapter{Sample Appendix}
\acrlong{TLS}
\end{document}
Using latex
, makeglossaries
, latex
, latex
(or pdflatex
, makeglossaries
, pdflatex
, pdflatex
) this produces

You can change page
/pages
to Page
/Pages
or suppress the post description dot using the nopostdot
package option, if required.
Things that will cause this method to fail:
- Resetting the entries: this will reset the counter for the entry back to 0
- Using an entries more than once on one page but not on any other. For example, if
\gls{aa}
is used three times on page 1 but not on any other page, then the location list will just consist of page 1 but because the entry has been used three times the conditional \ifnum\glsentryprevcount{##1}=1
will be false.
- The entry counting is intended for counting the number of times an entry has been marked as used. This means that the count is only incremented whenever
\glsunset
is used. This is done internally by commands like \gls
, but not for commands like \acrfull
, so this method will only be useful if you just use the \gls
-like commands.
Method 2:
As in the answer you linked to in your question, this second method assumes that the presence of \delimN
or \delimR
in the location list means that there's more than one page in the list. The other answer tries to parse the location list for instances of those commands, but this is tricky as they may be enclosed in an argument. This alternative approach defines a new conditional \ifpages
and redefines \delimN
and \delimR
to switch it to true. This of course means that we only know the required information after the location list has been typeset, so the information needs to be written to the auxiliary file so it can be picked up on the next (pdf|xe|lua)latex
run.
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[hyperindex, breaklinks,
linktoc=all,
pdfborder={0 0 0}]{hyperref}
% List of abbreviations
\usepackage[acronym,toc]{glossaries}
\makeglossaries
\glsnoexpandfields
\newif\ifpages
\renewcommand*{\delimN}{\pagestrue, }
\renewcommand*{\delimR}{\pagestrue--}
\makeatletter
\newcommand*{\savepagestag}[2]{%
\protected@write\@auxout{}{\string\pages@tag{#1}{#2}}}
\newcommand*{\pages@tag}[2]{\csgdef{pages@tag@#1}{#2}}
\newcommand*{\usepagestag}[1]{\csuse{pages@tag@#1}}
\makeatother
% Columns in acronym table
\newglossarystyle{mylong}{%
\setglossarystyle{long}%
\renewenvironment{theglossary}%
{\begin{longtable}[l]{@{}p{\dimexpr 2cm-\tabcolsep}p{0.8\hsize}}}%
{\end{longtable}}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription\space
\pagesfalse
\usepagestag{##1}\space
##2%
\ifpages
\savepagestag{##1}{pages}%
\else
\savepagestag{##1}{page}%
\fi
\tabularnewline
}%
}
\newacronym{TLS}{TLS}{Transport Layer Security}
\newacronym{CLV}{CLV}{Some Acronym}
\begin{document}
\frontmatter
\printglossary[type=\acronymtype,style=mylong,title=Abbreviations]
\mainmatter
\chapter{Sample Chapter}
\section[\glsentryshort{TLS}]{\acrshort{TLS}}
\newpage
\subsection{Section}
\chapter{Other chapter}
\acrfull{TLS}
\acrfull{CLV}
\backmatter
\appendix
\setcounter{page}{1}
\renewcommand{\thepage}{A\arabic{page}}
\chapter{Sample Appendix}
\acrlong{TLS}
\end{document}
Method 3
This method uses the glossaries-extra
extension package:
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[colorlinks]{hyperref}
% List of abbreviations
\usepackage[acronym,postdot]{glossaries-extra}
\makeglossaries
\setabbreviationstyle[acronym]{long-short}
\newacronym{TLS}{TLS}{Transport Layer Security}
\newacronym{aa}{AA}{Another Abbreviation}
\begin{document}
\frontmatter
\tableofcontents
\printglossary[type=\acronymtype,style=long,title=Abbreviations]
\mainmatter
\chapter{Sample Chapter}
\section{\glsfmtshort{TLS}}
\gls{aa}.
\newpage
\subsection{Section}
\chapter{Other chapter}
\glsxtrfull{TLS}
\backmatter
\appendix
\setcounter{page}{1}
\renewcommand{\thepage}{A\arabic{page}}
\chapter{Sample Appendix}
\glsxtrlong{TLS}
\end{document}

p.
orpp.
.