Gallery: Aliases

If you have a small screen, you may prefer to switch on the small image setting.

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 in \glshyperlink which was fixed in version 1.14.)

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.

For example:

\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{heracles}{%
category={mythical},%
name={Heracles},
description={divine hero in Greek mythology}
}


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.

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


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.

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


In this case, it’s a one-off, but if this should happen for all the entries in the mythical category, 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 initial 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


Download: PDF (61.30K), source code (1.95K).

The example below is a minor variation. The post-description hook for the person category inserts the full stop (period) and adjusts the space factor.

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


A post-description hook for the mythical category is also provided that checks if the alias field has been set. If it has, then a comma is added otherwise a full stop followed by a space factor adjustment is inserted.

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


This means that the comma and \nopostdesc can be removed from the hercules definition, which makes it much neater. The complete code for this variation is as follows:

% 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 (61.29K), source code (2.19K).