0

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. Screenshot of glossaries

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
0

I managed to create a glossarystyle that fixed my issue. Had great help from the bib2gls examples directory and Dickimaw's glossary gallery.

Apart from figuring out the preamble code, I also made the glossary entries themselves easier to work with by creating a properly labelled "unit" field. Posting a question can sometimes make wonders for one's motivation to solve an issue :-)

\documentclass[draft,titles,a4paper]{LuaUUThesis}
\usepackage[english]{babel}
\usepackage[utf8]{luainputenc}
\usepackage{fontspec}
\usepackage{siunitx}

\usepackage[record,abbreviations,symbols,stylemods={longbooktabs},nomain]{glossaries-extra}
\GlsXtrLoadResources[%
   src={acronyms},% 
   type=abbreviations]
\GlsXtrLoadResources[%
   src={symbols},% 
   field-aliases={%
      unit=user1,%
      name=symbol},% because my doc is full of legacy \glssymbol
   % symbol sort should be defined *after* field-aliases
   symbol-sort-fallback={symbol},% sort by name field (alias symbol)
   type=symbols]

\setlength{\glsdescwidth}{.7\textwidth}
% define custom glossary style for symbols
\newglossarystyle{symbolswithunits}{% 
   \renewenvironment{theglossary}%
   {\begin{longtable}{lcp{\glsdescwidth}}}%
   {\end{longtable}}%
   \renewcommand*{\glossaryheader}{%
      \toprule 
      \bfseries Symbol &
      \bfseries Unit &
      \bfseries Description
      \tabularnewline\midrule\endhead
      \bottomrule\endfoot}%
   \renewcommand{\glossentry}[2]{%
      % glossary field: symbol (alias for name)
      \glsentryitem{##1}\glstarget{##1}{\glossentrysymbol{##1}} &
      % this picks up the unit field (which was aliased as user1 above)
      % glsletentryfield fetches the value associated with the field useri
      % and stores the result in the control sequence \thisunit
      \ifglshasfield{useri}{##1}{\glsletentryfield{\thisunit}{##1}{useri}\thisunit}{} &
      % glossary field: description
      \glossentrydesc{##1}\glspostdescription\tabularnewline
   }%
   % gap between letter groups (governed by nogroupskip package option):
   \ifglsnogroupskip
      \renewcommand*{\glsgroupskip}{}%
   \else
      \renewcommand*{\glsgroupskip}{ & & \tabularnewline}%
   \fi
}

\begin{document}

\printunsrtglossary[%
   type=symbols,%
   style=symbolswithunits,%
   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}

Which achieved this pretty and descriptive header (highlighted) for the Symbols list, while maintaining the look of the Abbreviations list:

enter image description here

I still haven't figured out why using \renewcommand{\entryname}{Symbol} had no effect, though. If someone wants to clarify that, I'd be happy to mark their answer instead of mine.

Here's an example of how the symbol entries look now. Much less verbose and easier to work with, I think:

@symbol{speed_of_light,
  name = {\ensuremath{c}},
  description = {speed of light},
  text = {speed of light},
  unit = {\si{\metre\per\second}},
  first = {speed of light, \ensuremath{c}}
}
@symbol{wavelength,
  name = {\ensuremath{\lambda}},
  description = {wavelength of electromagnetic radiation},
  text = {wavelength},
  unit = {\si{\nano\metre}},
  first = {wavelength, \ensuremath{\lambda}}
}

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.