I would like to create a symbols list using \makeglossaries, but, it has to be ordered and the symbols must have their respective units too.
On the quest for a solution to my issue I came across two answers that contain what I want but both only have one of the desired outcomes.
1st- Symbols with units but no sorting (ode taken from glossaries: How to customize list of symbols with additional column for units?
\documentclass{book}
\usepackage{siunitx}
\usepackage[symbols,nogroupskip,nonumberlist,automake]{glossaries-extra} % use glossaries-package
\usepackage{subfiles}
\setlength{\glsdescwidth}{15cm}
\newglossary[slg]{symbolslist}{syi}{syg}{Symbolslist} % create add. symbolslist
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}
\makeglossaries % activate glossaries-package
% ==== EXEMPLARY ENTRY FOR SYMBOLS LIST =========================================
\newglossaryentry{symb:Pi}{name=\ensuremath{\pi},
description={Geometrical value},
unit={},
type=symbolslist}
\newglossaryentry{height}{name=\ensuremath{h},
description={Height of tower},
unit={\si{m}},
type=symbolslist}
\newglossaryentry{energyconsump}{name=\ensuremath{P},
description={Energy consumption},
unit={\si{kW}},
type=symbolslist}
\newglossaryentry{Eficiency}{name=\ensuremath{\eta},
description={Useful portion of work},
unit={\si{}},
type=symbolslist}
\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{0.6\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
{\end{longtable}}%
%
\renewcommand*{\glossaryheader}{% Change the table header
\bfseries Simbolo & \bfseries Description & \bfseries Unit \\
\hline
\endhead}
\renewcommand*{\glossentry}[2]{% Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \glsunit{##1} \tabularnewline
}
}
\begin{document}
\glsaddall
%\printglossary[type=\acronymtype,style=long] % list of acronyms
\printglossary[type=symbolslist,style=symbunitlong,title={Lista de Símbolos}] % list of symbols
% \printglossary[type=main] % main glossary
\end{document}
And the second one, that sorts but I can't add units to.
How to effectively use List of Symbols for a thesis?
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\usepackage[symbols,nogroupskip,sort=none]{glossaries-extra}
\glsxtrnewsymbol[description={position}]{x}{\ensuremath{x}}
\glsxtrnewsymbol[description={velocity}]{v}{\ensuremath{v}}
\glsxtrnewsymbol[description={acceleration}]{a}{\ensuremath{a}}
\glsxtrnewsymbol[description={time}]{t}{\ensuremath{t}}
\glsxtrnewsymbol[description={force}]{F}{\ensuremath{F}}
\begin{document}
\tableofcontents
\printunsrtglossary[type=symbols,style=long]
\chapter{Sample}
Reference symbols: $\gls{x}$, $\gls{v}$, $\gls{a}$, $\gls{t}$,
$\gls{F}$.
\end{document}
Really sorry to bother, I'm new in Latex and I've been stuck with this for a while now.
Best Answer
Your second example uses the
long
glossary style (set withstyle=long
in the optional argument of\printunsrtglossary
). This only shows the term (e.g.\ensuremath{x}
) and the description (e.g.position
) but it doesn't show any other information (except the location list, which isn't present in that example). You not only need to add the units but also provide a style which will show them.Some of the predefined styles show the
symbol
field as well, so if you use this field to store the unit, then you can just use a style that shows the symbol. Table 15.1 in theglossaries
user manual indciates which styles show the symbol.For example,
This produces:
This actually has four columns, but the fourth is empty as there's no location list. The
\glssymbol
command works like\gls
but displays the symbol value (unit, in this case).If you'd rather have a custom
unit
key, instead of using the providedsymbol
key, you can add one as in your first example. There are two commands that can add a new key:\glsaddkey
and\glsaddstoragekey
. It depends whether you want to use a command like\glssymbol
in the above example. If you do, then you need:(The case-changing commands don't make much sense for units, but the syntax requires them.) If you only need the unit to show in the list of symbols then you can do:
You also need to use
\glsnoexpandfields
to avoid problems caused by expansion.You can use the glossary style in your first example, but it ought to use
\glsentryunit
instead of\glsunit
:The width of the description column is given by
\glsdescwidth
. You can change this if it's the wrong size. For example:which makes it half the available text width or you can use an absolute value:
Alternatively, you can just change all the columns to
l
if you have short descriptions:Complete example:
The list of symbols looks like:
This deals with how to display the units in the list of symbols, but the ordering is performed manually by defining each symbol in the desired order. If you want to automatically order first by Latin and then by Greek, you need to use an extra tool. The best one for this task is
bib2gls
because it recognises Greek commands such as\alpha
, but for this you need to define all your symbols in a.bib
file.For example,
symbols.bib
:The document:
If the document is called
test.tex
then the document build is:(If you need help integrating this with your text editor, see Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.)
The
sort=letter-nocase
option performs a case-insensitive character sort, so the Latin characters will naturally end up before the Greek characters. The result is:If you prefer to just use the
long4col
style, then the fourth column will now contain the location lists (where the term was used in the document). For example:The option
field-aliases={unit=symbol}
makesbib2gls
treat the customunit
field as though it was actually thesymbol
field, so there's no need to change thesymbols.bib
file. (Without this alias,bib2gls
will ignore theunit
field, since theunit
key is no longer defined in the document.)You can omit the location list with either the
nonumberlist
option. For example:or
Alternatively, you can use
save-locations=false
in the resource options:The
glossaries-extra
package now comes with a supplementary packageglossary-longextra
that provides additional glossary styles that use thelongtable
environment. These are more flexible than thelong
styles provided with the baseglossaries
package, and so are easier to adjust. There are samples of each of thelongextra
styles in theglossaries
gallery. (Ifglossary-longextra.sty
isn't found, try upgrading yourglossaries-extra
installation.)For example:
This uses the
long-name-desc-sym
style that has the name in the first column, the description in the second column and the symbol in the third column. The header text for the name and symbol columns are given by the language-sensitive commands\entryname
and\symbolname
. These are redefined in the above example. This style doesn't show the location list, so I've instructedbib2gls
to not bother saving the locations (withsave-locations=false
).The column alignments can be changed by redefining
\glslongextraNameAlign
, for the name column, and\glslongextraSymbolAlign
, for the symbol column. For example:If you want a different column ordering, you can just use one of the other styles. For example, the
long-name-sym-desc
has the name in the first column, the symbol in the second column and the description in the third column.