2

Actually, this question has been already asked here: How to effectively use List of Symbols for a thesis?

And there is a very good answer with 4 methods.

However...

Thank you very much for the post, very interesting! I am trying to implement the method 4 on Overleaf.com, but I meet some problems... Would be someone so kind to help me?

I have followed the example here above creating a file 'greek-symbols.bib' exactly as described above. Then I have a created a "symbols.tex" file:

\usepackage[symbols,nogroupskip,
     record % using 'bib2gls'
]{glossaries-extra}

\GlsXtrLoadResources[
 src={greek-symbols},% entries in 'greek-symbols.bib'
 type=symbols,% put these entries in the 'symbols' glossary
 save-locations=false% don't save locations
]

In the main.tex, I call this file, the settings, and build the document (for example):

\input{head/settings.tex}  % place your packages, etc... in this file!
\input{symbols.tex}

\begin{document}

\tableofcontents
\listoftables
% Symbols
\printunsrtglossary[type=symbols,style=long,title={List of Symbols}]

\chapter{Mathematics}
Some symbols
Reference symbols: $\gls{x}$, $\gls{v}$, $\gls{a}$, $\gls{t}$, $\gls{F}$.

\end{document}

But the problem is that I obtain the following error:

Package gloassaries-extra Warning: No file 'output.glstex' on input line 13.

If I look at line 13, it corresponds to the end of command

\GlsXtrLoadResources[
 src={greek-symbols},% entries in 'greek-symbols.bib'
 type=symbols,% put these entries in the 'symbols' glossary
 save-locations=false% don't save locations
]

What is going on? Why following strictly the example, it does not work?

I would be very thankful if someone can help me.

Best regards, Elfo

  • 1
    Unfortunately Overleaf currently doesn't support bib2gls see Problem with the Glossary+bib2gls on Overleaf. – Nicola Talbot Jan 8 at 18:56
  • Ooh Gosh! That explains a lot of things! This is the reason why the bibliography is not working then! Thanks a lot. How to do then? Did you find a way to overcome that problem? – Elfo2285 Jan 8 at 19:13
  • You could ask Overleaf if they're going to add support for bib2gls. Perhaps if enough people ask they may add it. – Nicola Talbot Jan 8 at 21:25
  • Hi Nicola, I have implemented the method 4 and it works perfectly! Thanks a lot! Would it be possible to use a similar method to create a glossary? – Elfo2285 Jan 9 at 13:54
  • Actually I was thinking that method 4 could be used to generated a glossary that would contain symbols, acronyms, definitions, etc... as you show that you can separated latin symbols from greek symbols... – Elfo2285 Jan 9 at 13:57
4

I will demonstrate using some of the example .bib files provided with bib2gls.

mathgreek.bib defines some sample symbols that are all mathematical Greek characters. The LaTeX kernel doesn't provide commands for Greek characters that look the same as Latin character. This stems back to the days of limited resources and, for example, omicron could simply be produced with $o$. Unfortunately, from a sorting point of view this would result in omicron being placed between N and P instead of between Xi and Pi.

The interpreter used by bib2gls recognises the missing commands \omicron etc and so can correctly order them with the other math-Greek commands. However, it's necessary for LaTeX to also recognise them as well. The glossaries-extra-bib2gls package (automatically loaded with \usepackage[record]{glossaries-extra}) now provides these missing commands. The mathgreek.bib example file allows for an older version that doesn't provide them and uses @preamble to provide the definition of \omicron:

@preamble{"\providecommand{\omicron}{o}"}

The entries are defined using @symbol. The identifier field is a custom field that bib2gls won't recognise by default, but it's possible to provide or alias the field on a per-document basis. This just makes the .bib file more widely useful across multiple documents. The first couple of entries are:

@symbol{alpha,
  name={\ensuremath{\alpha}},
  description={alpha},
  identifier={mathgreek}
}

@symbol{beta,
  name={\ensuremath{\beta}},
  description={beta},
  identifier={mathgreek}
}

The other entries follow the same format.

mathsobjects.bib is rather more complicated. It first provides some semantic commands to format the notation:

@preamble{"\providecommand{\setfmt}[1]{\mathcal{#1}}
\providecommand{\setcontentsfmt}[1]{\{#1\}}
\providecommand{\setmembershipfmt}[2]{\setcontentsfmt{#1: #2}}
\providecommand{\setmembershiponeargfmt}[1]{\setmembershipfmt#1}
\providecommand{\setcardfmt}[1]{\lvert#1\rvert}
\providecommand{\numspacefmt}[1]{\mathbb{#1}}
\providecommand{\transposefmt}[1]{#1^T}
\providecommand{\invfmt}[1]{#1^{-1}}
\providecommand{\vecfmt}[1]{\boldsymbol{#1}}
\providecommand{\mtxfmt}[1]{\boldsymbol{#1}}"}

So, for example, \setfmt formats its argument in a calligraphic font to denote a set. The first three entries are defined as:

@symbol{set,
  name={\ensuremath{\setfmt{S}}},
  description={\sortart{a}{set}},
  format={setfmt},
  identifier={set}
}

@symbol{setcontents,
  name={\ensuremath{\setcontentsfmt{\ldots}}},
  description={set contents},
  format={setcontentsfmt},
  identifier={set}
}

@symbol{setmembership,
  name={\ensuremath{\setmembershipfmt{\vecfmt{x}}{\ldots}}},
  description={set membership},
  format={setmembershiponeargfmt},
  identifier={set}
}

The other entries are defined in a similar way. Again the custom identifier field is used, which bib2gls will ignore by default. There's also another custom field called format that's used to store the name of a control sequence that takes a single argument that applies the appropriate format. This will also be ignored by default.

baseunits.bib uses a custom entry type (@unit), so bib2gls will ignore all entries in this file unless an alias is set up. This means that different documents using the same .bib file can use whatever's the most appropriate entry type. For example, if a document needs @unit to be treated as @symbol, then the document needs to set up the alias:

entry-type-aliases={unit=symbol}

or if @unit should be treated as @entry:

entry-type-aliases={unit=entry}

The first few entries are defined as:

@unit{ampere,
  unitname={ampere},
  unitsymbol={\si{\ampere}},
  measurement={electric current},
  identifier={baseunit}
}

@unit{kilogram,
  unitname={kilogram},
  unitsymbol={\si{\kilogram}},
  measurement={mass},
  identifier={baseunit}
}

@unit{metre,
  unitname={metre},
  unitsymbol={\si{\metre}},
  measurement={length},
  identifier={baseunit}
}

The other entries all follow the same format. In this case all the fields are custom fields that bib2gls will ignore by default, so they will need to be aliased. This again allows greater flexibility across multiple documents that use the same .bib file.

makruplanguages.bib has a mixture of normal entries (@entry) and abbreviations (@abbreviation). This provides a custom command used to tag the abbreviation initials. This just does its argument by default:

@preamble{"\providecommand{\abbrvtag}[1]{#1}"}

The .bib file also defines a bib variable for convenience:

@string{markuplang="\abbrvtag{m}arkup \abbrvtag{l}anguage"}

This variable is just for use in the .bib file. String concatenation is performed with # in a .bib file. For example:

long = {e\abbrvtag{x}tensible } # markuplang

is equivalent to:

long = {e\abbrvtag{x}tensible \abbrvtag{m}arkup \abbrvtag{l}anguage}

The first few entries are:

@entry{TeX,
  name={{}\TeX},
  description={a format for describing complex type and page layout
    often used for mathematics, technical, and academic publications},
  identifier={markuplanguage}
}

@entry{LaTeX,
  name={{}\LaTeX},
  description={a format of \glstext{TeX} designed to separate
   content from style},
  identifier={markuplanguage}
}

@entry{markdown,
  name={markdown},
  description={a lightweight markup language with plain text
    formatting syntax},
  identifier={markuplanguage}
}

@abbreviation{xml,
  short={XML},
  long={e\abbrvtag{x}tensible }#markuplang,
  description={a markup language that defines a set of rules for
    encoding documents},
  identifier={markuplanguage}
}

@abbreviation{html,
  short={HTML},
  long={\abbrvtag{h}yper\abbrvtag{t}ext }#markuplang,
  description={the standard markup language for creating web pages},
  identifier={markuplanguage}
}

The empty group {} in front of \TeX and \LaTeX is in case any automated first letter upper-casing command is applied, as it's not appropriate for these commands.

Some of the sample .bib files use custom commands such as \sortart. There are three different .bib files that provide these commands: no-interpret-preamble.bib, interpret-preamble.bib and interpret-preamble2.bib. For now, I'm just going to use no-interpret-preamble.bib which contains:

@preamble{"\providecommand{\sortname}[2]{#1 #2}
\providecommand{\sortvonname}[3]{#1 #2 #3}
\providecommand{\sortart}[2]{#1 #2}
\providecommand{\sortmediacreator}[2]{#1 #2}"}

The first example document just has a single list to get started. The mathsobjects.bib file includes commands that are provided by amssymb, and the baseunits.bib file includes commands that are provided by siunitx, so those packages will need to be loaded:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

\GlsXtrLoadResources[
  src={no-interpret-preamble,mathgreek,mathsobjects,baseunits,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

If the file is called test.tex then the document build is:

pdflatex test
bib2gls test
pdflatex test

(Replace pdflatex with xelatex etc, as appropriate.)

This creates a single glossary that starts as follows:

image of start of glossary

This places beta (β) between "ampere" and "candela". The sort values are determined by the entry type. For example, if an entry is defined with @entry then the sort value is obtained from the name field, if an entry is defined with @abbreviation then the sort value is obtained from the short field, and if an entry is defined with @symbol then the sort value is obtained from the label. So β is actually sorted by its label beta.

You can change the field used to obtain the default sort value for the @symbol entries using the symbol-sort-fallback option. For example, to use the name field instead:

symbol-sort-fallback=name

(For abbreviations, you can use abbreviation-sort-fallback.) Below is a modified version of the above MWE that sorts symbols according to the name field:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

\GlsXtrLoadResources[
  src={no-interpret-preamble,mathgreek,mathsobjects,baseunits,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

The start of the glossary now looks like:

image of start of glossary

The Greek letters now come after Z:

image of glossary from X to lambda

There are a number of ways of splitting the data up into separate glossaries. This first method prevents the creation of the default main glossary (using the nomain package option) and defines three glossaries with labels that correspond to the entry type (without the initial @). This means that the type can easily be assigned using:

type={same as entry}

Here's the updated MWE:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record,nomain]{glossaries-extra}

\newglossary*{entry}{Glossary}
\newglossary*{abbreviation}{Abbreviations}
\newglossary*{symbol}{Symbols}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

\GlsXtrLoadResources[
  src={no-interpret-preamble,mathgreek,mathsobjects,baseunits,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  type={same as entry},
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

The document now has three lists. The first is the entry glossary:

image of glossary

The second is the abbreviation glossary:

image of list of abbreviations

The third is the symbol glossary, which starts:

image of start of symbol list

The Greek characters again come after Z.

Unlike the \makeglossaries approach (using makeindex or xindy), this method only has two associated glossary files: the .glstex which is input by \GlsXtrLoadResources and the .glg transcript file (which contains messages from bib2gls). With makeindex/xindy a document that has three glossary lists would have 10 corresponding glossary files (3 per glossary plus the style file).

With bib2gls, it's not the number of glossaries but the number of \GlsXtrLoadResources commands that determines the number of associated glossary files. Here's an alternative to the above that uses two resource commands:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record,abbreviations,symbols]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

\GlsXtrLoadResources[
  src={no-interpret-preamble,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathgreek,mathsobjects,baseunits},% bib files
  sort={letter-case},% sort according Unicode value
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  type=symbols,
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

In this case, I've used the abbreviations and symbols package option to create the glossaries labelled abbreviations and symbols. Package options that are provided by the base glossaries package are processed before options that are only provided by glossaries-extra, so \printunsrtglossaries will now list the glossaries in the order: main (default), symbols, abbreviations. You can change the order by using \printunsrtglossary for each individual glossary. For example:

\printunsrtglossary[type=abbreviations]
\printunsrtglossary % default main glossary
\printunsrtglossary[type=symbols]

This method has the advantage that a different sort method can be used for the symbols list (sort=letter-case). The first resource command doesn't set the glossary with the type option, so the default type is used. This is the default main for normal entries, but the entries defined with @abbreviation in the .bib file are defined using \newabbreviation in the .glstex file, so they will end up in the abbreviations glossary, since the abbreviations package option has been used.

A glossary list can be sub-sorted in blocks by splitting the entries across multiple resource commands. For example:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record,abbreviations,symbols]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

\GlsXtrLoadResources[
  src={no-interpret-preamble,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={baseunits},% bib file
  sort={letter-case},% sort according Unicode value
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  type=symbols,
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathsobjects},% bib file
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathgreek},% bib file
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

The symbols list now starts with the units:

image of symbols list with units at the start

In this case I've used sort=letter-case for all the sub-blocks, but it's possible to use different sort methods for each block.

Let's suppose I now want to switch to a glossary style that displays letter group headings, for example the treegroup style:

\usepackage[record,abbreviations,symbols,stylemods={tree},style=treegroup]{glossaries-extra}

Now bib2gls needs to be run with the --group (or -g) switch:

bib2gls --group test

If the above change is made to the MWE, this will result in errors like:

! Package inputenc Error: Unicode character 𝛼 (U+1D6FC)
(inputenc)                not set up for use with LaTeX.

This is because bib2gls tries to put the alpha entry into the "𝛼" letter group, but that Unicode character isn't supported by the document. However, in this case it isn't appropriate for each Greek letter to be in its own letter group. Instead the entire block can be assigned to its own group using the group option. The value must be a label. A title can be assigned using \glsxtrsetgrouptitle{label}{title}. For example:

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record,abbreviations,symbols,stylemods={tree},style=treegroup]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

% Assign group titles:
\glsxtrsetgrouptitle{units}{SI Units}
\glsxtrsetgrouptitle{latin}{Latin Symbols}
\glsxtrsetgrouptitle{greek}{Greek Symbols}

\GlsXtrLoadResources[
  src={no-interpret-preamble,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={baseunits},% bib file
  sort={letter-case},% sort according Unicode value
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  type=symbols,
  group=units,
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathsobjects},% bib file
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  group=latin,
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathgreek},% bib file
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  group=greek,
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

The symbols list now starts:

image of start of symbol list with group headings

The custom identifier fields all have values that can be used as labels. It's possible to convert identifier into group using the option:

field-aliases={identifier=group}

The titles need to be supplied:

\glsxtrsetgrouptitle{set}{Sets}
\glsxtrsetgrouptitle{numberspace}{Number Spaces}
\glsxtrsetgrouptitle{matrix}{Matrices and Vectors}

It's now necessary to sort according to the group field in order to keep the members of each group together. This can be done with the option:

sort-field={group}

Entries within the same group then need to be sorted according to the name field. There are two ways to do this.

  1. Set identical-sort-action={name} which will perform a character code comparison on the name field when the compared sort values (obtained from the field identified by sort-field) are identical.
  2. Use sort-suffix={name} which will append the value of the name field to the sort value.

I've used the first option below with sort=en-GB, which means that the sort value (obtained from the group) field will be sorted according to the en-GB collation rules and the name fields will be sorted according to character code (which makes more sense for symbols).

\documentclass{report}

\usepackage{amssymb}
\usepackage{siunitx}
\usepackage[record,abbreviations,symbols,stylemods={tree},style=treegroup]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{long-short-desc}

% Assign group titles:
\glsxtrsetgrouptitle{units}{SI Units}
\glsxtrsetgrouptitle{set}{Sets}
\glsxtrsetgrouptitle{numberspace}{Number Spaces}
\glsxtrsetgrouptitle{matrix}{Matrices and Vectors}
\glsxtrsetgrouptitle{greek}{Greek Symbols}

\GlsXtrLoadResources[
  src={no-interpret-preamble,markuplanguages},% bib files
  sort={en-GB},% sort according to this locale
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={baseunits},% bib file
  sort={letter-case},% sort according Unicode value
  entry-type-aliases={unit=entry},% make @unit behave like @entry
  field-aliases={
    unitname=name,
    unitsymbol=symbol,
    measurement=description
  },
  symbol-sort-fallback=name,
  type=symbols,
  group=units,
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathsobjects},% bib file
  sort={en-GB},% sort according to this locale
  sort-field={group},% sort according to this field
  identical-sort-action={name},% sort using letter case comparison by this field when sort-field values are identical
  symbol-sort-fallback=name,
  type=symbols,
  field-aliases={identifier=group},
  selection=all% select all entries in the .bib files
]

\GlsXtrLoadResources[
  src={mathgreek},% bib file
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  group=greek,
  selection=all% select all entries in the .bib files
]

\begin{document}
\printunsrtglossaries
\end{document}

The start of the symbols list now looks like:

image of first page of symbols list

There are many predefined styles to choose from.

Acronyms vs Abbreviations

The base glossaries package provides the command \newacronym which may be used to define acronyms or other forms of abbreviations. The package options acronyms or acronym create a new glossary acronym. You can reference it explicitly with that label or use \acronymtype.

The glossaries-extra extension package provides a completely new abbreviation handling system that's more flexible than the one used by the base package. The \newabbreviation command is provided to define all forms of abbreviations (including acronyms) using this new mechanism.

To assist with migrating from just using the base package to using the glossaries-extra package, \newacronym is redefined in terms of \newabbreviation, but it also sets category=acronym (which overrides the default category=abbreviation set by \newabbreviation). It is possible to switch \newacronym back to using the base glossaries package's abbreviation handling, although I don't recommend this.

The glossaries-extra package also permits the acronyms or acronym package option, which can be used as well as or instead of the abbreviations package option. If you use both acronyms/acronym and abbreviations then (if no type is explicitly set) \newacronym will put the entry in the acronym (\acronymtype) glossary and \newabbreviation will put the entry in the abbreviations (\glsxtrabbrvtype) glossary. If you only use the abbreviations package option then \acronymtype is redefined to \glsxtrabbrvtype.

Within the .bib files, you may use either @abbreviation (which will define the entry using \newabbreviation) or @acronym (which will define the entry using \newacronym). Since \newacronym sets category=acronym by default, you need to use the optional argument of \setabbreviationstyle to set the abbreviation style. For example:

\setabbreviationstyle[acronym]{long-short}
  • Hi Nicola, thank you very much for the answer! I will implement that in the following days (today I am busy), and let you know! – Elfo2285 Jan 10 at 8:26
  • Could you define a list of acronyms in a .bib file instead of abbreviations? Can you define acronyms instead of abbreviations using this method? It would be more accurate to speak about acronyms instead of abbreviations... – Elfo2285 Mar 14 at 15:16
  • @Elfo2285 Use @acronym instead of abbreviation – Nicola Talbot Mar 15 at 10:27
  • Thanks a lot for your feedback. I've learned a lot following these methods. I am almost there, but I still have some errors in the result. I've created test files to test what I would like to achieve. For that, I've opened a new post to finalize the glossary. Can you please help me? – Elfo2285 Mar 18 at 16:33

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.