0

I am using the glossaries package to make a list of acronyms and a list of symbols (separately). Following this approach, I tried to make a list of symbols that has that layout, but with a separated greek and roman symbols section.

I tried to do this using the link's \newglossarystyle command:

\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {%
     \renewcommand{\arraystretch}{1.5}%
     \begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Symbol & \bfseries \descriptionname & \bfseries Unit & \bfseries First appearance \tabularnewline
    \midrule\endhead}%
    \renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1}  & \glossentrydesc{##1} & \glsentryunit{##1} 
        \tabularnewline
    }%
}

This gives me a push in the right direction in that the separation of roman and greek letters is correct. However, the units column and symbols column, except for the Roman letters and Greek letters indicators, are left entirely empty. The output of the symbols glossary, with separated Roman and Greek letters, but with the units and symbols missing or mixed up.

Taken from this question, I have defined the unit key using this command, before calling \makeglossaries:

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

I have made the distinction between Roman and Greek symbols by assigning a parent to each glossary entry, following this approach:

% Define the parent romand and greek symbols
\newglossaryentry{romanletter}{name={\textbf{Roman letters}}, description={\nopostdesc}, sort={1}, type=symbols}
\newglossaryentry{greekletter}{name={\textbf{Greek letters}}, description={\nopostdesc}, sort={2}, type=symbols}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entries
\newglossaryentry{drag}{name={\ensuremath{D}},
                     sort={drag},
                     description={drag},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{h}{name={\ensuremath{h}},
                     sort={h},
                     description={altitude},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\metre}}}
\newglossaryentry{lift}{name={\ensuremath{L}},
                     sort={lift},
                     description={lift},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{mach}{name={\ensuremath{M}},
                     sort={Mach number},
                     description={Mach number},
                     parent={romanletter},
                     type={symbols},
                     unit={[-]}}
\newglossaryentry{mass}{name={\ensuremath{m}},
                     sort={mass},
                     description={mass},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\kilogram}}}
\newglossaryentry{pitchrate}{name={\ensuremath{q}},
                     sort={q},
                     description={pitch rate},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\radian\per\second}}}
% Some greek letter
\newglossaryentry{eta}{name={\ensuremath{\eta}},
                        sort={7},
                        description={(propulsive) efficiency},
                        parent={greekletter}, 
                        type={symbols},
                        unit={[-]}}

I am probably going wrong somewhere in the \newglossarystyle command, but I've been trying to work it out reading the docs and inspecting previously posted questions, but I can't seem to work it out. I find the syntax \renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1} & \glossentrydesc{##1} & \glsentryunit{##1} quite confusing and am not able to work out all those commands from the glossaries docs.

Summarising all the above in a MWE:

\documentclass{report}
\usepackage{siunitx} \sisetup{detect-all}
\usepackage{hyperref}
\usepackage[nopostdot, toc, nogroupskip, nomain, indexonlyfirst, acronym, symbols, style=long4col, stylemods={longbooktabs}]{glossaries-extra}
\GlsXtrEnablePreLocationTag{page~}{pages~}

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

\makeglossaries

% Define the parent romand and greek symbols
\newglossaryentry{romanletter}{name={\textbf{Roman letters}}, description={\nopostdesc}, sort={1}, type=symbols}
\newglossaryentry{greekletter}{name={\textbf{Greek letters}}, description={\nopostdesc}, sort={2}, type=symbols}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entries
\newglossaryentry{drag}{name={\ensuremath{D}},
                     sort={drag},
                     description={drag},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{h}{name={\ensuremath{h}},
                     sort={h},
                     description={altitude},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\metre}}}
\newglossaryentry{lift}{name={\ensuremath{L}},
                     sort={lift},
                     description={lift},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{mach}{name={\ensuremath{M}},
                     sort={Mach number},
                     description={Mach number},
                     parent={romanletter},
                     type={symbols},
                     unit={[-]}}
\newglossaryentry{mass}{name={\ensuremath{m}},
                     sort={mass},
                     description={mass},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\kilogram}}}
\newglossaryentry{pitchrate}{name={\ensuremath{q}},
                     sort={q},
                     description={pitch rate},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\radian\per\second}}}
% Some greek letter
\newglossaryentry{eta}{name={\ensuremath{\eta}},
                        sort={7},
                        description={(propulsive) efficiency},
                        parent={greekletter}, 
                        type={symbols},
                        unit={[-]}}

% Set the new glossary style
\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {%
     \renewcommand{\arraystretch}{1.5}%
     \begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Symbol & \bfseries \descriptionname & \bfseries Unit & \bfseries First appearance \tabularnewline
    \midrule\endhead}%
    \renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1}  & \glossentrydesc{##1} & \glsentryunit{##1} 
        \tabularnewline
    }%
}

\begin{document}

\glsaddall
\printglossary[type=symbols, style=symbunitlong]

\end{document}

Thanks in advance!

P.S. I would also like each column's width to be adapted to the widest entry in that column. For example, the last column should be made wider to display First appearance in one line. Moreover, the entries should be left-aligned instead of centered. This is of secondary importance, though.

1

Okaaaay ... i'm no expert in glossary styles, so i tried my best.

First of all your biggest mistake was not to use the full possibilities of the glossaries-extra package ^_~ See this link for more, but take your awe & time because you will need it. That aside, there you will find the longextra stylemod as well as the long-loc-sym-desc-name style. It is a perfect start for your style choice.

By defining a symbol using the symbol key you have everything you need for the style modification. I copied most of it from the original style file (after package installation: MiKTeX->tex->latex->glossaries-extra). Last but not least define your column order and of course the use of the unit key.

\documentclass{report}
\usepackage{blindtext}
\usepackage{siunitx}    \sisetup{detect-all}
\usepackage{hyperref}
\usepackage[nopostdot, toc, nogroupskip, nomain, indexonlyfirst, acronym, symbols, style=long4col, stylemods={longextra}]{glossaries-extra}
\GlsXtrEnablePreLocationTag{page~}{pages~}

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

\makeglossaries

% Define the parent roman and greek symbols
\newglossaryentry{romanletter}{
    name={\textbf{Roman letters}},
    description={\nopostdesc}, 
    sort={1}, 
    type=symbols,
}
\newglossaryentry{greekletter}{
    name={\textbf{Greek letters}},
    description={\nopostdesc}, 
    sort={2}, 
    type=symbols,
}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entry with roman letter ...
\newglossaryentry{mass}{
    name={mass},
    symbol={\ensuremath{m}},
    unit={\si{\kilogram}},
    description={mass},
    parent={romanletter},
    type={symbols},
    sort={mass},
}
% ... and also with some greek letter
\newglossaryentry{eta}{
    name={eta},
    symbol={\ensuremath{\eta}},
    unit={[-]},
    description={(propulsive) efficiency},
    parent={greekletter}, 
    type={symbols},
    sort={eta},
}

% Inform glossary about your own key (see manual v1.41, p.60 about its original definition)
\renewcommand{\glslongextraSubNameFmt}[2]{
    \glssubentryitem{#2}\glstarget{#2}{\glsentryunit{#2}\strut}
}
% Set the new glossary style
\newglossarystyle{long-sym-desc-unit-loc}{%
    \setglossarystyle{long-loc-sym-desc-name}%
    \renewenvironment{theglossary}%
    {%
    \glspatchLToutput
    \glslongextraSymLocSetDescWidth
    \edef\@glslongextra@begintab{%
        \noexpand\begin{longtable}{%
                \expandonce\glslongextraSymbolAlign
                \expandonce\glslongextraDescAlign
                \expandonce\glslongextraNameAlign
                \expandonce\glslongextraLocationAlign
        }}%
        \@glslongextra@begintab
    }%
    {\end{longtable}
    }%
    \renewcommand*{\glossaryheader}{%
        \bfseries Symbol%
        & \bfseries \descriptionname %
        & \bfseries Unit %
        & \bfseries \mbox{1st page}%
        \tabularnewline%
        \midrule%
        \endhead%
    }%
    \renewcommand*{\glsgroupheading}[1]{\glslongextraGroupHeading{4}{##1}}%
    \renewcommand{\glossentry}[2]{%
        \glslongextraNameFmt{##1} & & &%
        \tabularnewline
    }% 
    \renewcommand{\subglossentry}[3]{%
        \glslongextraSubSymbolFmt{##1}{##2} &
        \glslongextraSubDescFmt{##1}{##2} &
        \glslongextraSubNameFmt{##1}{##2} &
        \glslongextraSubLocationFmt{##1}{##2}{##3}%
        \tabularnewline
    }%
}

\begin{document}
\blindtext
\gls{eta} 

\Blindtext
\gls{mass}

\printglossary[type=symbols, style=long-sym-desc-unit-loc]
\end{document}
| improve this answer | |
  • Let me start by thanking you for your help, it is much appreciated! The layout of the list of symbols is exactly how I want it. However, because some of the field uses have been shuffled w.r.t. my example, using \gls{eta} in the main text makes the text "eta" show, instead of the symbol \ensuremath{\eta}. I could change this by referring to the symbol using \glsentrysymbol{eta}, but then the symbol appearing in the text is non-clickable and doesn't show in the list of symbols. Long story short, is there a way to make the \gls{} command work as it did previously? – Sam Apr 10 at 15:42
  • P.S. Just changing the contents of the name field to the contents of the symbol field does the trick. Thanks again! – Sam Apr 10 at 15:50
  • Happy to help ... and i learned something for myself, so win-win ^_~ – Venez Apr 10 at 17:42

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.