6

I'd like to be able to print e.g. "p. 1" if an acronym is only used on one page and e.g. "pp. 1, 2" if it is used on multiple pages. I have tried to define a new counter and use its value in the ifthenelse but I don't know where to hook up the incrementing code. There is probably a less complicated solution anyway... :)

The MWE below needs to be built with pdflatex mwe.tex ; makeglossaries mwe ; pdflatex mwe.tex.

\documentclass{article}
\usepackage[
    shortcuts,
]{glossaries}

\newglossarystyle{mylist}{
    \renewenvironment{theglossary}{\begin{description}}{\end{description}}

    \renewcommand*{\glossaryentryfield}[5]{%
        \item[\glsentryitem{##1}\glstarget{##1}{##2}] ##3\glspostdescription \space \footnotesize (%
        \ifthenelse{\equal{1}{1}}{p}{pp}. ##5)%
    }
}

\makeglossaries

\newacronym{bt}{BT}{Bluetooth}
\newacronym{usb}{USB}{Universal Serial Bus}
\begin{document}

\ac{bt}
\ac{usb}
\clearpage
\ac{usb}

\printglossary[type=\acronymtype,style=mylist]

\end{document}

1 Answer 1

5

This can be a solution.

I've used the command \IfSubStr* from the xstring package to see if inside the 5th argument we have the words "delimN" or "delimR" (in the number list, \delimN is a command that expands to , and \delimR expands to --) which, with the help of a new \if, determines where to print pp and where to print p.

If "delimN" or "delimR" are not present, this means that we have only one page number in the number list.

Note that I've also put \footnotesize inside a group...

MWE

\documentclass{article}
\usepackage{xstring}
\usepackage[shortcuts]{glossaries}

\newif\ifmulti

\newglossarystyle{mylist}{%
    \renewenvironment{theglossary}{\begin{description}}{\end{description}}%
    \renewcommand*{\glossaryentryfield}[5]{%
        \multifalse%
        \IfSubStr*{\detokenize{##5}}{delimN}{\multitrue}{\relax}%
        \IfSubStr*{\detokenize{##5}}{delimR}{\multitrue}{\relax}%
        \item[\glsentryitem{##1}\glstarget{##1}{##2}] ##3\glspostdescription \space {\footnotesize (%
        \ifmulti pp\else p\fi. ##5)}%
    }%
}

\makeglossaries

\newacronym{bt}{BT}{Bluetooth}
\newacronym{usb}{USB}{Universal Serial Bus}
\newacronym{sata}{SATA}{Serial Advanced Technology Attachment}
\begin{document}

\ac{bt}
\ac{usb}
\ac{sata}
\clearpage
\ac{usb}
\ac{sata}
\clearpage
\ac{sata}
\clearpage

\printglossary[type=\acronymtype,style=mylist]

\end{document} 

Output

enter image description here

3
  • this fails of course for number ranges (those include \delimR). i had the idea to count the characters instead (with \StrLen), but i can't get that to work at all
    – stefanct
    Dec 21, 2013 at 15:19
  • @stefanct You're right. I simply forgot about number ranges... Now it should be OK. Dec 21, 2013 at 15:40
  • yes, that works, thank you. (I had no idea about ifmulti yet, but a simple if-then-if-then-else works (with a bit of redundancy) too). I would rather see a more elegant solution, but so far this is definitely the best answer ;)
    – stefanct
    Dec 21, 2013 at 15:56

You must log in to answer this question.

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