I have been trying to get the appearance of my list of symbols just the way I want it, but despite following the advice of several other questions/answers on this forum, and reading through the glossaries-extra and bib2gls docs, I consistently get stuck trying to rename the headers.
I have the following working document (using TeXLive 2020, a LuaLaTeX documentclass, glossaries-extra v1.45, bib2gls v2.5, siunitx v2.8b):
\documentclass[draft,titles,a4paper]{LuaUUThesis}
\usepackage[english]{babel}
\usepackage[utf8]{luainputenc}
\usepackage{fontspec}
\usepackage{siunitx}
\usepackage[record,abbreviations,symbols,stylemods=longextra,nomain]{glossaries-extra}
\GlsXtrLoadResources[%
src={acronyms},%
type=abbreviations]
\GlsXtrLoadResources[%
src={symbols},%
type=symbols]
\begin{document}
\printunsrtglossary[%
type=symbols,%
style=long-name-sym-desc,%
title={List of symbols}]
\printunsrtglossary[%
type=abbreviations,%
title={List of abbreviations}]
Example of symbols \gls{wavelength}, \gls{speed_of_light}.
Abbreviations: \gls{FTO}, \gls{TCO}.
\end{document}
along with the abbreviations and symbols bib-files:
=== symbols.bib
@entry{speed_of_light,
name = {\ensuremath{c}},
short = {speed of light},
description = {speed of light},
text = {speed of light},
long = {speed of light},
symbol={\si{\metre\per\second}},
first = {speed of light, \ensuremath{c}}
}
@entry{wavelength,
name = {\ensuremath{\lambda}},
description = {wavelength of electromagnetic radiation},
text = {wavelength},
long = {monochromatic wavelength},
symbol={\si{\nano\metre}},
first = {wavelength, \ensuremath{\lambda}}
}
=== abbreviations.bib
@entry{FTO,
see = {TCO},
name = {FTO},
description = {fluoride-doped tin oxide, a very common optically transparent and electrically conducting oxide},
text = {FTO},
long = {fluoride-doped tin oxide},
first = {fluoride-doped tin oxide (FTO)}
}
@entry{TCO,
name = {TCO},
description = {optically transparent and electrically conducting oxide},
text = {TCO},
long = {transparent conducting oxide},
first = {transparent conducting oxide (TCO)}
}
This produces a nice table of symbols and a simple list of abbreviations.
My problem is that I cannot figure out how to change the text in the Symbols header. And I should note that I'd like to stay with longtabs, since my glossary will probably span more than one page.
I've tried two approaches (in the following I show only the part of the code that changed compared to above, I hope it's not confusing):
\renewcommand{\entryname}{Symbol}
\renewcommand{\symbolname}{Units}
but that caused no changes. Document compiled without errors, though. Prepending \usepackage{glossary-longextra}
made no difference.
Next, I tried defining a new glossary style, first by copying code verbatim from other answers, and when those produced errors by making small changes:
\newglossarystyle{symbunitlong}{%
\renewenvironment{theglossary}%
{\begin{longtable}{lcl}}%
{\end{longtable}}%
\renewcommand*{\glossaryheader}{%
\bfseries Symbol & \bfseries Units & \bfseries Description\\\hline}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrysymbol{##1} &
\glossentrydesc{##1}\\%
}%
\ifglsnogroupskip
\renewcommand*{\glsgroupskip}{}%
\else
\renewcommand*{\glsgroupskip}{ & & & \tabularnewline}%
\fi
}
\begin{document}
\printunsrtglossary[%
type=symbols,%
style=symbunitlong,%
title={List of symbols}]
but this keeps failing to compile, with a typical error:
./thesis.tex:686: Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.686 title={List of symbols}]
I've eyeballed the code and cannot see any syntax errors (which I'm obviously missing), and I've also tried removing \hline
, or replacing \\
with \tabularnewline
and other such changes, but haven't managed to fix the issue (although the error message changed to extra \noalign
sometimes).
Why does the first, simple approach to change header text not work? I thought that that approach was offered by glossaries-extra
?
Does anyone have a suggestion, pointer or even a fix for the glossarystyle definition, or any other approach to edit the header when using glossaries-extra and bib2gls? Bonus point if we can replace the header hlines with booktabs rules.
And just for completeness, in case someone actually wants to recompile this MWE :-), here's the .latexmkrc
file and the build command needed to compile with LuaLaTeX and bib2gls:
# https://www.ctan.org/tex-archive/support/latexmk/example_rcfiles
$pdflatex = 'lualatex -file-line-error %O %S';
$pdf_mode = 1;
$postscript_mode = $dvi_mode = 0;
# the following code based the example rcfile bib2gls
# http://mirror.ctan.org/support/latexmk/example_rcfiles/bib2gls_latexmkrc
# https://tex.stackexchange.com/a/401979/10824
push @generated_exts, 'glstex', 'glg';
add_cus_dep('aux', 'glstex', 0, 'run_bib2gls');
sub run_bib2gls {
if ( $silent ) {
my $ret = system "bib2gls --silent --group '$_[0]'";
} else {
my $ret = system "bib2gls --group '$_[0]'";
};
my ($base, $path) = fileparse( $_[0] );
if ($path && -e "$base.glstex") {
rename "$base.glstex", "$path$base.glstex";
}
# Analyze log file.
local *LOG;
$LOG = "$_[0].glg";
if (!$ret && -e $LOG) {
open LOG, "<$LOG";
while (<LOG>) {
if (/^Reading (.*\.bib)\s$/) {
rdb_ensure_file( $rule, $1 );
}
}
close LOG;
}
return $ret;
}
=== and compile the document with:
latexmk -r .latexmkrc -pdf -bibtex thesis.tex