# Glossaries vs. Index for an index of authors?

when I started writing a longer book, I initially only felt the need for an index of authors. Hence, I set up an index via \index and \makeindex, which gave the desired result.

In the meantime, I realise that additional glossaries for the explanation of abbreviations and technical terms would be nice. Not surprisingly, I quickly came across the package glossaries, which should fulfill the requirements.

I wonder now, if it wouldn't be better to abandon my index of authors and convert it into another glossary, too, which will then yield the same list of authors, as currently by \makeindex. In fact, such an example has alrealy been proposed (Additional author information).

I see the potential benefit of using the package glossaries for all types of indices that - once the glossary entries are defined at a separate place, preferably in a separate file - the source code of the book will be easier to edit and more legible in comparison with the \index variant. Nevertheless, because of lacking the experience with the package glossaries, I'd like to ask the question to the experts here, if my idea to use glossaries for the index of authors, too, is really a good one or if I overlook some potential hiccups with that approach?

Ideally, I would have distinct glossary input files for the respective glossaries alongside my tex file in the same folder, that I edit separately (like my bib file for the literature). Is that possible?

Best regards,

Oli

• There is no clear answer to this. If you want to provide more information about authors, a glossary might be the better way. – user31729 Jan 7 '17 at 15:49
• You might want to have a look at the glossaries gallery to see what can be done with glossaries. You can certainly define all your entries in a separate file and load them either using \input or \loadglsentries. – Nicola Talbot Jan 7 '17 at 15:52
• If all you want is an index of authors, I don't see any reason to use glossaries. If you want to add details of those authors into the index, that's a different story. – cfr Jan 30 '18 at 0:33

Here's a method that's adapted from an example provided with bib2gls (described in the "Examples" chapter of the bib2gls user manual). The file people.bib contains all the author information in .bib format:

% Encoding: UTF-8

@entry{dickens,
name={\sortname{Charles}{Dickens}},
text={Dickens},
description={English writer and social critic},
born={7 February 1812},
died={9 June 1870},
identifier={person}
}

@entry{chandler,
name={\sortname{Raymond}{Chandler}},
text={Chandler},
description={American-British novelist and screenwriter},
born={23 July 1888},
died={26 March 1959},
identifier={person}
}

@entry{hammett,
name={\sortname{Samuel Dashiell}{Hammett}},
first={\sortname{Dashiell}{Hammett}},
text={Hammett},
description={American author, screenwriter and political
activist},
born={27 May 1894},
died={10 January 1961},
identifier={person}
}

@entry{christie,
name={\sortname{Dame Agatha Mary Clarissa}{Christie}},
first={\sortname{Agatha}{Christie}},
text={Christie},
description={English crime novelist and playwright},
born={15 September 1890},
died={12 January 1976},
identifier={person}
}

@entry{landon,
name={\sortname{Christopher Guy}{Landon}},
first={\sortname{Christopher}{Landon}},
text={Landon},
description={British novelist and screenwriter},
born={29 March 1911},
died={26 April 1961},
identifier={person}
}

@entry{tolkien,
name={\sortname{John Ronald Reuel}{Tolkien}},
first={\sortname{J.R.R.}{Tolkien}},
text={Tolkien},
description={English writer, poet, philologist, and
university professor},
born={3 January 1892},
died={2 September 1973},
identifier={person}
}

@entry{baum,
name={\sortname{Lyman Frank}{Baum}},
first={\sortname{L.~Frank}{Baum}},
text={Baum},
description={American author},
born={15 May 1856},
died={6 May 1919},
identifier={person}
}

@entry{mackenzie,
name={\sortname{Compton}{Mackenzie}},
text={Mackenzie},
description={English-born Scottish writer, cultural
commentator, raconteur and Scottish nationalist},
born={17 January 1883},
died={30 November 1972},
identifier={person}
}

@entry{maclean,
name={\sortname{Alistair}{MacLean}},
text={MacLean},
description={Scottish novelist},
born={21 April 1922},
died={2 February 1987},
identifier={person}
}

@entry{dick,
name={\sortname{Philip K.}{Dick}},
text={Dick},
description={American science fiction writer},
born={16 December 1928},
died={2 March 1982},
identifier={person}
}

@entry{story,
name={\sortname{Jack Trevor}{Story}},
text={Story},
description={British novelist},
born={30 March 1917},
died={5 December 1991},
identifier={person}
}

@entry{greene,
name={\sortname{Henry Graham}{Green}},
first={\sortname{Graham}{Greene}},
text={Green},
description={English novelist},
born={2 October 1904},
died={3 April 1991},
identifier={person}
}


(The encoding line isn't strictly necessary here as the file only contains ASCII characters, but it's good practice to include it anyway otherwise bib2gls will search the entire file for it before parsing the data.)

This contains a custom command \sortname which needs to be defined. If this command isn't used explicitly in the document, it can simply be provided in the .bib file using @preamble. For example:

@preamble{"\providecommand{\sortname}[2]{#2, #1}"}


(for surname, forenames) or

@preamble{"\providecommand{\sortname}[2]{#1 #2}"}


(for forenames surname). For convenience, I've decided to have two .bib files that provide the above alternatives. Here's interpret-preamble.bib:

% Encoding: UTF-8

@preamble{"\providecommand{\sortname}[2]{#2, #1}"}


(Additional command definitions may be added to @preamble, but there are no entries in this file.) Similarly, here's nointerpret-preamble.bib:

% Encoding: UTF-8

@preamble{"\providecommand{\sortname}[2]{#1 #2}"}


Here's a simple document that uses glossaries-extra and bib2gls to list all the authors defined in people.bib:

\documentclass{article}

\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}

% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
selection=all% select all entries
]

\begin{document}
\printunsrtglossary[title={Authors}]
\end{document}


If the document is called myDoc.tex, then the build process is much like with bibtex, but bib2gls is used instead:

pdflatex myDoc
bib2gls myDoc
pdflatex myDoc


The document looks like:

Although I've used indexgroup, no letter groups are showing. To support this glossary style, bib2gls needs the --group (or -g) option:

pdflatex myDoc
bib2gls -g myDoc
pdflatex myDoc


bib2gls has a primitive LaTeX interpreter that's used to parse @preamble, which is how it managed to sort by surname (since \sortname is defined so that it expands to surname, forenames.) bib2gls can be instructed not to parse @preamble, which provides a useful way of defining \sortname for the document but providing a different definition for bib2gls:

\documentclass{article}

\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=index
]{glossaries-extra}

% provide definition of \sortname for the document
src={nointerpret-preamble},
interpret-preamble=false
]

% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
selection=all% select all entries
]

\begin{document}
\printunsrtglossary[title={Authors}]
\end{document}


So the authors are still sorted alphabetically by surname but are displayed forenames surname.

Some of the information from the people.bib file has been ignored, as bib2gls always ignores unknown fields (in this case, born, died, othername and identifier). These fields will be recognised if they are defined in the document before the first use of \GlsXtrLoadResources or they can be aliased to existing fields:

\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
selection=all% select all entries
]


With these aliases set, it's possible to hook into the glossary style to display extra information:

\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}

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


It's also possible to have a secondary list that's ordered by date of birth using the options:

secondary={date:user1:bybirth},
date-field-locale=en-GB


Complete MWE:

\documentclass{article}

\usepackage[a4paper]{geometry}

\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}

% provide definition of \sortname for the document
src={nointerpret-preamble},
interpret-preamble=false
]

% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
secondary={date:user1:bybirth},
date-field-locale=en-GB,
selection=all% select all entries
]

\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}

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

\begin{document}
\printunsrtglossary[title={Authors (by name)}]

\printunsrtglossary[title={Authors (by birth)},type=bybirth]
\end{document}


With bib2gls --group, the first page is:

and the second page is:

The group titles default to YYYY-MM when sorting by date. This can be changed. For example, to just use the year (define before \GlsXtrLoadResources):

\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}


The authors can be referenced in the document. In the modified MWE below, I've removed selection=all, so the selection criteria is now the default selection=recorded and deps which means to select all recorded entries (referenced using commands like \gls) and their dependencies.

\documentclass{article}

\usepackage[a4paper]{geometry}

\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}

\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}

% provide definition of \sortname for the document
src={nointerpret-preamble},
interpret-preamble=false
]

% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
secondary={date:user1:bybirth},
date-field-locale=en-GB
]

\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}

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

\begin{document}
\section{First Use}

\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.

\section{Next Use}

\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.

\printunsrtglossary[title={Authors (by name)}]

\printunsrtglossary[title={Authors (by birth)},type=bybirth]
\end{document}


There's an inconsistency here in the first use. This is because only some of the entries have a first field. For example:

@entry{christie,
name={\sortname{Dame Agatha Mary Clarissa}{Christie}},
first={\sortname{Agatha}{Christie}},
text={Christie},
description={English crime novelist and playwright},
born={15 September 1890},
died={12 January 1976},
identifier={person}
}


So this value is displayed on first use, but others only have the text field but not first. For example:

@entry{dickens,
name={\sortname{Charles}{Dickens}},
text={Dickens},
description={English writer and social critic},
born={7 February 1812},
died={9 June 1870},
identifier={person}
}


So in this case the first use value is obtained from the text field. It would look more consistent if it was obtained from the name field instead. This can be achieved with the option:

replicate-fields={name={first}}


The person's other name (if provided) can be appended on first use by defining a post-link hook:

\newcommand*{\glsxtrpostlinkperson}{%
\glsxtrifwasfirstuse
{%
\ifglshasfield{user3}{\glslabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}%
{}%
}


Complete MWE:

\documentclass{article}

\usepackage[a4paper]{geometry}

\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}

\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}

% provide definition of \sortname for the document
src={nointerpret-preamble},
interpret-preamble=false
]

% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
replicate-fields={name={first}},
secondary={date:user1:bybirth},
date-field-locale=en-GB
]

\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}

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

\glsxtrifwasfirstuse
{%
\ifglshasfield{user3}{\glslabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}%
{}%
}

\begin{document}
\section{First Use}

\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.

\section{Next Use}

\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.

\printunsrtglossary[title={Authors (by name)}]

\printunsrtglossary[title={Authors (by birth)},type=bybirth,
target=false% don't create hypertargets
]
\end{document}


The locations are now present in both glossaries (corresponding to the records created by \gls). If you don't want these, just add the option

save-locations=false


to the option list for \GlsXtrLoadResources.

• Wow - you've answered with a manual! – cfr Jan 30 '18 at 0:32