About
Shop
LaTeX
Free Software
Books
News
Contact
Blog
Recent news (2017-04-18): glossaries-extra v1.14 released.

Gallery (glossaries): Aliases Sample

Image of aliases sample

This example uses the alias key provided by glossaries-extra (new to version 1.12). This works much like the see key, but automatically switches on noindex for terms with the alias field set so the aliased references don't have locations (just the cross-reference). When used with hyperref this also modifies the target used when referencing the aliased terms with \gls. (If the see hyperlinks in the glossary are misdirected, then this is due to a known bug with \glshyperlink which will be fixed in version 1.14. Follow that link to the bug report for a patch.)

The bib2gls application (which can be used instead of makeindex/xindy) allows finer control of the aliased entry location lists.

There are two categories used in this example:

  1. person for a real person with a birth date (stored in the user1 field) and optional death date (stored in the user2 field);
  2. mythical for a mythical character.
The person category has a post-description hook \glsxtrpostdescperson that checks the user1 and user2 fields. The datetime2 package allows for a convenient way of formatting the date. The en-GB date/time locale is used, which means the datetime2-english module is required.

The person entries with the alias key have the description field simply set to \nopostdesc which suppresses the post-description hook. This not only suppresses the use of \glsxtrpostdescperson but also suppresses the automatic sentence terminator that's triggered by the postdot package option.

The hercules aliased entry has a description. In this case the automatic sentence terminator is undesirable, so it's been suppressed with \nopostdesc. In this case, it's a one-off, but if this should happen for all the mythical categories, it would be better to remove the postdot option and transfer the sentence terminator to the post-description hook. This is illustrated in the second example below.

(The comment lines below are arara directives. You can remove them if you don't use arara.)

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

\usepackage[T1]{fontenc}
\usepackage[en-GB]{datetime2}
\usepackage[colorlinks]{hyperref}
\usepackage[style=indexgroup,postdot]{glossaries-extra}

\makeglossaries

\newcommand*{\glsxtrpostdescperson}{%
 \ifglshasfield{user1}{\glscurrententrylabel}
 {% born
   \space(\expandafter\DTMdate\expandafter{\glscurrentfieldvalue}\,--\,%
     \ifglshasfield{user2}{\glscurrententrylabel}
     {% died
        \expandafter\DTMdate\expandafter{\glscurrentfieldvalue}%
     }%
     {}%
   )%
 }%
 {}%
}

\newglossaryentry{wellesley}{%
  category={person},
  name={Arthur Wellesley, 1st Duke of Wellington},
  sort={Wellesley, Arthur},
  first={Arthur Wellesley, 1st Duke of Wellington},
  text={Wellesley},
  description={Anglo-Irish soldier and statesman},
  user1={1769-05-01},% born
  user2={1852-09-14}% died
}

\newglossaryentry{wellington}{%
  category={person},
  name={Duke of Wellington},
  text={Wellington},
  description={\nopostdesc},
  alias={wellesley}
}

\newglossaryentry{heracles}{%
  category={mythical},%
  name={Heracles},
  description={divine hero in Greek mythology}
} 

\newglossaryentry{hercules}{%
  category={mythical},%
  name={Hercules},
  description={Roman adaptation of Greek hero, \nopostdesc},
  alias={heracles}
}

\newglossaryentry{bonaparte}{%
  category={person},
  name={Napoleon Bonaparte},
  sort={Bonaparte, Napoleon},
  description={French military and political leader},
  first={Napoleon Bonaparte},
  text={Bonaparte},
  user1={1769-07-15},% born
  user2={1821-05-05}% died
}

\newglossaryentry{diBuonaparte}{%
  category={person},
  name={Napoleone di Buonaparte},
  description={\nopostdesc},
  alias={bonaparte}
}

\renewcommand*{\glsseeitemformat}[1]{\glsentryname{#1}}

\begin{document}
\gls{wellesley}.
\gls{heracles}.
\gls{bonaparte}.

\newpage

\gls{wellesley}.
\gls{hercules}.
\gls{diBuonaparte}.

\newpage

\gls{wellington}.

\newpage

\printglossaries
\end{document}

If you don't use arara, you need to run the following commands:

pdflatex aliases
makeglossaries aliases
pdflatex aliases
These commands can be run from a terminal or command prompt or you might be able to run them by clicking on a button in your text editor.

Download: PDF, document source.

The example below is a minor variation:

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

\usepackage[T1]{fontenc}
\usepackage[en-GB]{datetime2}
\usepackage[colorlinks]{hyperref}
\usepackage[style=indexgroup]{glossaries-extra}

\makeglossaries

\newcommand*{\glsxtrpostdescperson}{%
 \ifglshasdesc{\glscurrententrylabel}%
 {%
   \ifglshasfield{user1}{\glscurrententrylabel}
   {% born
     \space(\expandafter\DTMdate\expandafter{\glscurrentfieldvalue}\,--\,%
       \ifglshasfield{user2}{\glscurrententrylabel}
       {% died
          \expandafter\DTMdate\expandafter{\glscurrentfieldvalue}%
       }%
       {}%
     )%
   }%
   {}%
   .\spacefactor\sfcode`\.
 }%
 {}%
}

\newcommand*{\glsxtrpostdescmythical}{%
 \ifglshasdesc{\glscurrententrylabel}%
 {%
   \ifglshasfield{alias}{\glscurrententrylabel}%
   {, }%
   {.\spacefactor\sfcode`\. }%
 }%
 {%
 }%
}

\newglossaryentry{wellesley}{%
  category={person},
  name={Arthur Wellesley, 1st Duke of Wellington},
  sort={Wellesley, Arthur},
  first={Arthur Wellesley, 1st Duke of Wellington},
  text={Wellesley},
  description={Anglo-Irish soldier and statesman},
  user1={1769-05-01},% born
  user2={1852-09-14}% died
}

\newglossaryentry{wellington}{%
  category={person},
  name={Duke of Wellington},
  text={Wellington},
  description={},
  alias={wellesley}
}

\newglossaryentry{heracles}{%
  category={mythical},%
  name={Heracles},
  description={divine hero in Greek mythology}
} 

\newglossaryentry{hercules}{%
  category={mythical},%
  name={Hercules},
  description={Roman adaptation of Greek hero},
  alias={heracles}
}

\newglossaryentry{bonaparte}{%
  category={person},
  name={Napoleon Bonaparte},
  sort={Bonaparte, Napoleon},
  description={French military and political leader},
  first={Napoleon Bonaparte},
  text={Bonaparte},
  user1={1769-07-15},% born
  user2={1821-05-05}% died
}

\newglossaryentry{diBuonaparte}{%
  category={person},
  name={Napoleone di Buonaparte},
  description={},
  alias={bonaparte}
}

\renewcommand*{\glsseeitemformat}[1]{\glsentryname{#1}}

\begin{document}
\gls{wellesley}.
\gls{heracles}.
\gls{bonaparte}.

\newpage

\gls{wellesley}.
\gls{hercules}.
\gls{diBuonaparte}.

\newpage

\gls{wellington}.

\newpage

\printglossaries
\end{document}

Download: PDF, document source.


Last modified: 2017-02-08.

The free resources on this site are funded by book sales, not by adverts. If you would like to help keep this site free of annoying third-party ads, please consider buying a book.

© 2017 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Site Map FAQs