Sunday, November 06, 2022

Making an Index of Plant Names

I'm translating a Sanskrit text full of plant names.  In a previous project of this type, I created a simple bilingual index, Sanskrit-English and English-Sanskrit.  I did not include Latin binomials and, most regrettable, I didn't include any of the source-referencing and thought that went into my translation choices.  I had compiled all this material, but I didn't share it with the public.  With the current project, I want to use a database to collect the information about each plant cumulatively and in a single place, and I want to have a straightforward way of presenting this complex data in the book.

The answer is the LaTeX package Glossaries. Glossaries is one of those packages, like BibLaTeX, that is extremely powerful and flexible, and therefore complex to learn.  The reference manual of glossaries-extra is over a thousand pages long.


  • Simple input system in the body of the translation;
  • Alphabetical glossary by plant name, with page index, for the back of the book.  Like this: 

I have  achieved this with the following system.

BibTeX and bib2gls

The Glossaries-extra (GE) package includes a subsystem that reads a BibTeX file and turns it into glossary entries.   My bib file is called plants.bib, and it lives in the same directory as all my BibTeX files (../localtexmf/bibtex/bib)
The BibTeX entry looks like this:
 The entries are called, er, @entry; and each entry has three fields, the 
  1. label, which is the Sanskrit name of the plant (with diacritical marks);
  2. description, which contains the Latin binomial and anything else I want to say about the Sanskrit plant name.
  3. name, which is the English common name of the plant, that will appear in the translation.

Note that I'm using BibLateX citations in the description field, to cite the botanical literature that I want to refer to.  

What you write in the main text

In the text of my translation, I use the \gls{} command to cite the Sanskrit plant name, like this: 

 And so, he should burn \gls{dhava} and ...

 After running LaTeX foobar and bib2gls foobar, I get the output,

and at the back of the book, by using the command \printunsrtglossaries, I get 

TLDR: as I write, I just use the Sanskrit name of the plant, and the GE package replaces it with the English translation from my bib file and also constructs the alphabetical glossary entries at the back of the book.  

Close readers will have seen that the word "axlewood" in the translation is in a different colour: it's a clickable hot link to the right page of the index.  The index entries have clickable page-references back to the body of the text.  The glossary has clickable links to the bibliography.

The TeX macros that make this happen are in the package xelatex-glossaries.sty that you are most welcome to copy from GitHub.

Special thanks to Nicola L. C. Talbot, author of the remarkable Glossaries package.