I am looking at some thesis templates online, and virtually all of them have a line that says:
\chapter*{List of Symbols}
\addcontentsline{toc}{chapter}{List of Symbols}
For example:
https://groups.google.com/forum/#!topic/latexusersgroup/tfHpC9MvpsI
https://gist.github.com/FuzzyWuzzie/4678259
But absolutely no instruction as to how to add symbols onto this list! How do I start adding symbols to this list?
One source online said the way to add new symbols to this page is to create a table under this chapter:
\chapter*{List of Symbols}
\addcontentsline{toc}{chapter}{List of Symbols}
\begin{tabular}{cp{0.6\textwidth}}
$x$ & position \\
$v$ & velocity \\
$a$ & acceleration \\
$t$ & time \\
$F$ & force
\end{tabular}\\
But I would like to add symbols as I go so the symbols on different chapters are "hyperlinked" with the list of symbols when they are defined.
I wish to achieve this using something like \addsymbol{\beta: name of a cat}
.
Is there a way to do that without creating a separate table of symbols?
Best Answer
Both the
glossaries
package and theglossaries-extra
extension package provide the package optionsymbols
, which creates a new list labelledsymbols
with the default title given by the language-sensitive\glssymbolsgroupname
("Symbols"). This list can be referenced withtype=symbols
. If you don't use this package option then you can use the defaultmain
glossary instead but the default title will be obtained from\glossaryname
("Glossary").Table 1.1: Glossary Options: Pros and Cons in the
glossaries
manual summarises the key differences between the various options described below, and theglossaries
performance page evaluates the performance (build time and sorting) of the various methods.Method 1 (no external tools required, manual sorting)
This is the simplest method as it doesn't require any addition to the build process. Requires at least v1.08 of the
glossaries-extra
package.Pros and Cons:
The first three points also apply to the manual method in your question that uses the
tabular
environment. The fourth point is automatically ensured byglossaries-extra
's default behaviour, which prohibits entries from being defined in thedocument
environment. (If you have a lot of symbols, I recommend you put the definitions in a separate file and load it in the preamble using\input
or\loadglsentries
.)Each symbol must first be defined. If the
symbols
package option is used, this can be done with\glsxtrnewsymbol[
options]{
label}{
symbol}
. The symbol can then be referenced in the document using\gls{
label}
. For example, the symbol$t$
can be defined with the labelt
using:It can then be referenced using
\gls{t}
. An alternative way of defining this symbol is:or (if the
symbols
glossary has been defined):The
\glsxtrnewsymbol
command is more compact and is more appropriate for symbols, but thesymbols
package option is required to provide it.With this method, I recommend the
sort=none
package option, as this switches off the redundant construction of thesort
key. (This option may not be available if you have an old version ofglossaries
.)If the file is called
mydoc.tex
, then the build process is:(Replace
pdflatex
withxelatex
etc as appropriate.) The second instance ofpdflatex
is only needed here to ensure the table of contents and the PDF bookmarks are up-to-date.This produces the symbol list:
The list of symbols is automatically added to the table of contents:
You can change the title using the
title
key:I've used the
long
style, which is the closest match to yourtabular
example, but there are many predefined styles to choose from.Make sure
hyperref
is loaded beforeglossaries-extra
. (This is contrary to the general rule thathyperref
should be loaded last.) This will allow commands like\gls
to link to the relevant entry in the list of symbols.It is possible to include a location, but as with all manual methods, this can be tiresome an error-prone. The following example only includes a location for the first symbol:
The
record
option (amongst other things), creates a field calledlocation
which\printunsrtglossary
checks for. The list of symbols now looks like:Method 2 (using an external tool to sort)
This method is more complicated as it requires an extra step in the build process. It's much like the previous example, but there are a few modifications:
nonumberlist
option is added to suppress the location list that would automatically appear after each entry in the symbol list. (Remove this option if you actually want the locations.)\makeglossaries
must be added to the preamble (before the symbols are defined).\printunsrtglossary
must be replaced with\printglossary
.Pros and Cons:
sort
value);\gls
) in the document;\gls
) in the document are included in the list;docdef=restricted
ordocdef=true
package option, which has some potentially problematic issues);Modified example:
Assuming the file is called
mydoc.tex
, the build process is:makeglossaries
is a Perl script, so you need Perl installed to use it. If you don't have Perl, there's a light-weight Lua alternative calledmakeglossaries-lite
which you can use instead. (Since modern TeX distributions come with LuaTeX, you should have a Lua interpreter already available.) The build process in this case is:(
makeglossaries-lite
is actually distributed asmakeglossaries-lite.lua
, but TeX Live on Unix-like systems strip the.lua
extension. I don't use Windows, but I think the extension can be omitted there as I believe the Windows distributions convert the Lua script to an executablemakeglossaries-lite.exe
.)This produces an ordered list of symbols where the sort order is obtained from the first required argument of
\glsxtrnewsymbol
, which is also the label used to identify the term. If\newglossaryentry
is used instead, the sort defaults to thename
field, which causes problems for symbols that are defined in terms of LaTeX commands, such as\alpha
or\sum
. (This is why\glsxtrnewsymbol
uses the label instead.)Without the
nonumberlist
option the list includes a location list:In this case, each location list consists of the number 3, which is the page on which all instances of
\gls
occur. You can switch to another counter if you prefer (for example, using thecounter
package option). Thepostpunc
option allows a way of automatically inserting a punctuation character after the description but it's best used with thestylemods
option. For example:You can change the sort value using the
sort
key in the optional argument of\glsxtrnewsymbol
. For example:How you actually run
makeglossaries
/makeglossaries-lite
depends on your setup. See, for example:If you're really stuck you can use the
automake
package option:This doesn't have the diagnostic tools provided by
makeglossaries
and requires the shell escape.Both
makeglossaries
andmakeglossaries-lite
call an indexing application. You can call it directly, but you need to know all the necessary switches and file extensions. (The Perl and Lua scripts provided with theglossaries
package find the necessary information in the.aux
file.) The default behaviour is to usemakeindex
. You can switch toxindy
by addingxindy
to the list of package options:(Note that
xindy
is a Perl script, so you need Perl installed to use it.) In the above example, there's no difference since\glsxtrnewsymbol
sets thesort
field to the label, which only contains ASCII characters.Things become much more complicated if you directly use
\newglossaryentry
and thename
field contains commands. For example:In this case, the
sort
field is obtained from thename
field, but neithermakeindex
norxindy
understand LaTeX commands. In the case ofmakeindex
, it treats\ensuremath{\alpha}
as a string containing 19 characters, starting with\
so the result is:This doesn't follow the natural ordering of Greek letters (which should be α δ ζ λ χ) and will position the Greek symbols before Latin symbols (since
\
is ordered beforea
bymakeindex
).This example fails completely with
xindy
. If you use themakeglossaries-lite
script, it fails with a cryptic message. If I just modify the document so that it includes thexindy
package option:then
makeglossaries-lite
reports:This is because the document doesn't have the codepage set. This needs to be added:
(This isn't necessary with
makeglossaries
which falls back on-L english -C utf8
if this information is omitted.) However, even with this information,makeglossaries-lite
fails withxindy
's rather cryptic message:Switching to
makeglossaries
provides a more intelligible explanation:So with
xindy
you must supply a sensiblesort
value (or use\glsxtrnewsymbol
to default to the label) for entries that only contain commands in thename
field.Method 3 (no external tools required, order by use in the document)
To order the symbol list according to the first time the symbol is used in the document, you need to make the following changes:
sort=use
\makeglossaries
with\makenoidxglossaries
\printglossary
with\printnoidxglossary
Pros and Cons:
sort=use
, as in this example) or by order of definition (sort=def
);\gls
) in the document;\gls
) in the document are included in the list;As you might be able to gather from the first point, you can also use this method as a substitute for the other two methods. However, when sorting alphabetically, Method 2 is far more efficient and can support various locales (when used with the
xindy
option), although this may not be applicable for symbols (especially when they just contain ASCII characters). For a large list, this method can take a long time when sorting alphabetically. When sorting by definition (sort=def
), this method differs from Method 1 as it only includes those entries that have been used in the document (whereas Method 1 lists all defined entries).Adjusted example (third page modified to show effect):
The build process is back to:
The list of symbols now looks like:
Again, removing the
nonumberlist
option makes the location list appear:Things go badly wrong if you use this method with the default alphabetical sorting when the sort value contains commands. Adjusting the earlier example with Greek symbols:
During sorting, the following error occurs:
This method is only designed for ASCII sorting. With this method, you must ensure that the
sort
value doesn't contain any commands (for example, use\glsxtrnewsymbol
which obtains the sort value from the label) or usesort=def
orsort=use
.Method 4 (external tool and
.bib
file(s) required)This is a fairly new method. Instead of using
makeindex
orxindy
(viamakeglossaries
ormakeglossaries-lite
), it requiresbib2gls
, which performs two functions:.aux
file (similar tobibtex
);makeindex
orxindy
).Pros and Cons:
.bib
file (not in the document);bib2gls
allows any location format or you may instruct it to omit the location list;bib2gls
to select all defined entries or only recorded entries (and optionally their dependencies);The symbols are now defined in a
.bib
file. For example, instead of:the symbol is defined as:
Alternatively, instead of
use
(The
type
field has been omitted, as it's more flexible to assign it in the document.) As with\glsxtrnewsymbol
, the@symbol
definition uses the label as the fall back for thesort
field, whereas the@entry
definition uses thename
as the fall back.For example, the file
greek-symbols.bib
may contain:The document needs the
record
package option. Instead ofnonumberlist
I can instructbib2gls
to not save the location list (which is more efficient). Instead of\makeglossaries
/\makenoidxglossaries
you need to use\GlsXtrLoadResources
:This uses
\printunsrtglossary
from the earlier Method 1. Unlike the other methods,bib2gls
works by selecting only those entries that are required and then writes the definition (\newglossaryentry
) to the file input by\GlsXtrLoadResources
in the appropriate order. This means that\printunsrtglossary
automatically lists the entries in the requested order (since that's the order of definition fromglossaries-extra
's point of view).The build process is now
This produces:
(Remove
save-locations=false
if you want the location list.)Since
bib2gls
recognises commands like\ensuremath{\alpha}
, it's used the correct Greek order. Alternatively you can instructbib2gls
to sort by the description instead:If the file
latin-symbols.bib
similarly contains the Latin symbols:Then they can be combined:
or separated into two distinct groups within the same glossary:
The
group
setting requires the--group
(or-g
) switch when callingbib2gls
:This setting also requires a style that supports group headings, which is why I changed to the style to
altlistgroup
.