1

I want to have a modified page list (back-references) of my glossary, list of acronyms and symbols. With \glsaddallunused at the end of the document, I add all entries to the lists. Because of that, it appears that some entries have no page references and some do have (which is exactly what I want). The page list should be:

- if there are no page numbers, no additional text and no brackets should appear.
- if there is a reference to one page only: "(page #)"
- if there are references to more than one page: "(pages #,#-#,...,# and #)"

I achieved a similar behavior in my bibliography (which I do not understand at all) by doing:

\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]{%
    {\footnotesize\mbox{
        \ifcase #1%
            (Not directly cited)%
        \or
            (Cited on page #2)%
        \else
            (#1 cites on pages #2)%
        \fi}
    }
}

If this is absolutely not possible with glossaries, I would be happy to have:

- if there are no page numbers, no additional text should appear.
- if there is a reference to one or more pages: "(#)"

MWE that does not have a different page list depending on the references:

\documentclass{scrreprt}

\usepackage[backref=page,plainpages=false,pdfpagelabels,colorlinks]{hyperref}
\usepackage[footnote,acronym,toc,hyperfirst]{glossaries}

% acronym style (Nicola Talbot)
\newacronymstyle{ex-footnote}%
{%
  \GlsUseAcrEntryDispStyle{footnote}%
}%
{%
  \GlsUseAcrStyleDefs{hyperfirst, footnote}%
  \renewcommand*{\genacrfullformat}[2]{%
    \firstacronymfont{\glsentryshort{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
  }%
  \renewcommand*{\Genacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshort{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
  }%
  \renewcommand*{\genplacrfullformat}[2]{%
    \firstacronymfont{\glsentryshortpl{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
  }%
  \renewcommand*{\Genplacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshortpl{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
  }%
}
\setacronymstyle{ex-footnote}


% glossary stile
\makeatletter
\newglossarystyle{MyGlossaryStyle}{%
% Use longtable with two columns:
\renewenvironment{theglossary}%
  {\begin{longtable}[l]{p{.2\textwidth}p{.755\textwidth}}}%
  {\end{longtable}}%
% start of the environment:
  \renewcommand*{\glossaryheader}{}%
% Main (level 0) entries displayed in a row:
\renewcommand*{\glossaryentryfield}[5]{\hspace{-6pt}%
  \glstarget{##1}{##2}%
  & ##3\glspostdescription%
  \space\footnotesize\mbox{(##5)}\tabularnewline%
}%
% Blank row between groups:
  \renewcommand*{\glsgroupskip}{\\}%
}
\glossarystyle{MyGlossaryStyle}
\makeatother

\makeglossaries


% arconyms
\newacronym{D}{D}{Is not used}
\newacronym{DD}{DD}{\glslink{displacement damage}{Displacement Damage}}
\newacronym{DDD}{DDD}{Displacement Damage Dose}
\newacronym{FPGA}{FPGA}{Field-Programmable Gate Array}

% Gloassaries
\newglossaryentry{displacement damage}{
name = {Displacement Damage},
description = {Displacement damage description}
}
\newglossaryentry{displacement damage dose}{
name = {Displacement Damage Dose},
description = {\Gls{DD} dose description}
}
\newglossaryentry{interconnect}{
name = {Interconnect},
description = {The wiring resources in an \gls{FPGA}}
}


\begin{document}

page 1\\
What does \gls{interconnect} mean?

\clearpage
\newpage

page 2\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose} and again \gls{DDD}.\\

\clearpage
\newpage

page 3\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}

\clearpage
\newpage
page 4
\clearpage
\newpage

page 5\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}


\printglossary[type=\acronymtype, title=Abbreviations]
\printglossary[type=main, title=Glossary]

\glsaddallunused
\end{document}

Note1: Since there are cross-references in the MWE, you have to compile with makeglossaries twice, e.g.:

- pdflatex
- makeglossaries
- pdflatex
- makeglossaries
- pdflatex

Note2: A problem in the page list occours, one comma and space is added falsely, see below:

enter image description here

Note3: The 5th argument in \glossaryentryfield is the page list. It does neither work to check if the list is empty with

\ifx##5\relax

nor

\if\relax\detokenize{##5}\relax

nor

\ifthenelse{\isempty{##5}}

Note4: I don't mind to clean up the code of my glossary style =)

  • Does anybody know where to find a detailed documentation for \glossaryentryfield and how to check if the 5th parameter is empty? – Pauli Jul 21 '15 at 6:55
  • I would appreciate any help, even if it is not the solution. – Pauli Jul 30 '15 at 9:48
3

I finally managed to solve the problem.

I had a look at the output of \detokenize{##2} (where ##2is the page list in \glossentry) and found that it has a substring glsignore if there is no page number. Furthermore there is at least one substring delimRor delimNbetween page numbers (only when here is more than one page referenced).

Since \glossaryentryfield is deprecated, you should use \glossentry instead.

You are welcome to post a more elegant solution ...

\documentclass{scrreprt}

\usepackage{xstring}
\usepackage[backref=page,plainpages=false,pdfpagelabels,colorlinks]{hyperref}
\usepackage[footnote,acronym,toc,hyperfirst]{glossaries}

% acronym style (Nicola Talbot)
\newacronymstyle{ex-footnote}%
{%
  \GlsUseAcrEntryDispStyle{footnote}%
}%
{%
  \GlsUseAcrStyleDefs{hyperfirst, footnote}%
  \renewcommand*{\genacrfullformat}[2]{%
    \firstacronymfont{\glsentryshort{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
  }%
  \renewcommand*{\Genacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshort{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
  }%
  \renewcommand*{\genplacrfullformat}[2]{%
    \firstacronymfont{\glsentryshortpl{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
  }%
  \renewcommand*{\Genplacrfullformat}[2]{%
    \firstacronymfont{\Glsentryshortpl{##1}}##2%
    \expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
  }%
}
\setacronymstyle{ex-footnote}


% glossary stile
\makeatletter
\newglossarystyle{MyGlossaryStyle}{%
% Use longtable with two columns:
\renewenvironment{theglossary}%
  {\begin{longtable}[l]{p{.2\textwidth}p{.755\textwidth}}}%
  {\end{longtable}}%
% start of the environment:
  \renewcommand*{\glossaryheader}{}%
% Main (level 0) entries displayed in a row:
  \renewcommand*{\glossentry}[2]{%
    \glstarget{##1}{\glossentryname{##1}}% Name
    & \glossentrydesc{##1}% Description
    \IfSubStr*{\detokenize{##2}}{glsignore}{%
      \footnotesize\space (Not used)%
    }{%
      \IfSubStr*{\detokenize{##2}}{delim}{%
        \footnotesize\space (Pages ##2)%
      }{%
        \footnotesize\space (Page ##2)%
      }%
    }%
    \tabularnewline% end of row
  }%
% Similarly for sub-entries
  \renewcommand*{\subglossentry}[3]{%
    \glstarget{##2}{\glossentryname{##2}}% Name
    & \glossentrydesc{##2}% Description
    \IfSubStr*{\detokenize{##3}}{glsignore}{%
      \footnotesize\space (Not used)%
    }{%
      \IfSubStr*{\detokenize{##3}}{delim}{%
        \footnotesize\space (Pages ##3)%
      }{%
        \footnotesize\space (Page ##3)%
      }%
    }%
    \tabularnewline% end of row
  }%
% Blank row between groups:
  \renewcommand*{\glsgroupskip}{\\}%
}
\glossarystyle{MyGlossaryStyle}
\makeatother

\makeglossaries


% arconyms
\newacronym{D}{D}{Is not used}
\newacronym{DD}{DD}{\glslink{displacement damage}{Displacement Damage}}
\newacronym{DDD}{DDD}{Displacement Damage Dose}
\newacronym{FPGA}{FPGA}{Field-Programmable Gate Array}

% Gloassaries
\newglossaryentry{displacement damage}{
name = {Displacement Damage},
description = {Displacement damage description}
}
\newglossaryentry{displacement damage dose}{
name = {Displacement Damage Dose},
description = {\Gls{DD} dose description}
}
\newglossaryentry{interconnect}{
name = {Interconnect},
description = {The wiring resources in an \gls{FPGA}}
}


\begin{document}

page 1\\
What does \gls{interconnect} mean?

\clearpage
\newpage

page 2\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose} and again \gls{DDD}.\\

\clearpage
\newpage

page 3\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose}

\clearpage
\newpage
page 4
\clearpage
\newpage

page 5\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}


\printglossary[type=\acronymtype, title=Abbreviations]
\printglossary[type=main, title=Glossary]

\glsaddallunused
\end{document}

enter image description here enter image description here

EDIT1

I added \gls{displacement damage dose} on page 3. That is why page 3 is also added to the glossary in comparison to the original MWE in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.