2

Consider this example:

\documentclass{article}
\usepackage[record,style=alttreegroup,nomain,symbols]{glossaries-extra}

\begin{filecontents}{symbols.bib}
@symbol{alpha,
name = {\ensuremath{\alpha}},
description = {angle},
group = {greek},
}
@symbol{theta,
name = {\ensuremath{\theta}},
description = {for testing},
group = {greek},
}
@symbol{diffusion,
name = {\ensuremath{D}},
description = {diffusion factor},
group = {roman},
}
@symbol{choke,
name = {\ensuremath{\mathrm{cor}}},
description = {corrected},
group = {sub},
}
@symbol{blockage,
name = {\ensuremath{B}},
description = {blockage factor},
group = {roman},
}
\end{filecontents}

\GlsXtrLoadResources % input file created by bib2gls
[% instructions to bib2gls:
    src={symbols},
    type = symbols,
    selection = {all},%
%   symbol-sort-fallback={name},%turning off makes it worse
]

\setglossarypreamble[symbols]{\glssetwidest{MMM}}

\begin{document}
\glsxtrsetgrouptitle{roman}{Roman Letters}
\glsxtrsetgrouptitle{greek}{Greek Letters}
\glsxtrsetgrouptitle{sub}{Subscripts}

\printunsrtglossaries % iterate over all defined entries
\end{document}

It produces this results:

enter image description here

It is quickly clear what is wrong here. The sorting works globally when building the document as

pdflatex document
bib2gls document
pdflatex document

as shown here. Running bib2gls -g document did not seem to make a difference.

How can the groups be kept separate and sorting local to them, without mixing of groups?

A possible workaround I thought of would be to have different types for Roman, Greek etc. and then call them all manually (as opposed to one type for symbols). But that seems not the right way. I feel like I am very close to the solution, but the last steps I could not find help with in the doc.

Edit 1:

After this answer, the core question was solved. The solution was found in the bib2gls documentation (and not glossaries-user, glossaries-code or glossaries-extra package docs!).

While working, I found there is not a lot of novice-friendly material out there yet (aside from the excellent websites at Dickimaw). With that I mean hands-on examples that give a working baseline, and not just snippets. Therefore, I am uploading my current code for reference. It has a handful of concepts in it that might be helpful. It will have numerous issues still, but hopefully it serves people as a starting point to see what is possible, what the syntax is like, what commands there are, etc.

\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{nth}
\usepackage[abbreviations, symbols, record, nomain]{glossaries-extra}
% Record for bib2gls to work.
% Nomain, aka no default glossary
% Also see https://tex.stackexchange.com/q/477658/120853
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% New Glossary 'types'. Load data into them from *.bib-files, then run bib2gls
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Using Abbreviations/Symbols package options creates these glossaries already.
% Create the rest manually.
\newglossary*{subsuper}{Sub- and Superscripts}%

% Select all files in bib.
% Not a good approach, but bib2gls seems to have problems with 'subimport'.
\GlsXtrLoadResources[%
    src={./glossaries/abbreviations},%
    selection = {all},%
]%
\GlsXtrLoadResources[%
    src={./glossaries/symbols},%
    selection = {all},% grab all from bib-file. Using subimport currently does not work
    sort-field={group},%sort by this field first
    sort-suffix={name},%append this field as suffix to sort-field
    symbol-sort-fallback={description},% fall back to description if absolutely required
]%
\GlsXtrLoadResources[%
    src={./glossaries/subsuper},%
    type=subsuper,%
    category = subsuper,
    selection = {all},% grab all from bib-file. Using subimport currently does not work
    sort-field={group},%sort by this field first
    sort-suffix={name},%append this field as suffix to sort-field
    symbol-sort-fallback={description},% fall back to description if absolutely required
]%

% indexonlyfirst can also be a package option.
% Index only on first use for certain categories, as set manually above.
% https://tex.stackexchange.com/a/318886/120853
% Symbols has type=symbols but category=symbol (singular)
\glssetcategoryattribute{symbol}{indexonlyfirst}{true}
\glssetcategoryattribute{other}{indexonlyfirst}{true}

% Each bib-entry has a group-field.
% bib2gls is smart and would take grouptitles from there, but those are just variables.
% Give proper names for all groups here.
\glsxtrsetgrouptitle{sub}{Subscripts}
\glsxtrsetgrouptitle{super}{Superscripts}
\glsxtrsetgrouptitle{greek}{Greek}
\glsxtrsetgrouptitle{roman}{Roman}

% One down in rprt/book
\setglossarysection{section}

% More Width
\setglossarypreamble[subsuper]{\glssetwidest{MMM}}%

% Remove from ToC (doing this manually).
% Default is true.
\glstocfalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% New Styles as longtables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{glossary-mcols}%multi-column styles
\usepackage{glossary-longextra}

\newcommand*{\glshdrfont}[1]{\sffamily\large\textbf{#1}}% font for gls table heads
\makeatletter
\newcommand*{\mltcolspan}[2]{\multicolumn{\numexpr\LT@cols}{#1}{#2}} % multicolumn spanning all columns automatically. https://tex.stackexchange.com/a/168358/120853
\makeatother

\newglossarystyle{symbunitlong}{%https://tex.stackexchange.com/a/269571/120853
    \setglossarystyle{long-name-desc}% base new style on existing one

    \renewcommand{\glsgroupheading}[1]{%
        \glshdrfont{\glsgetgrouptitle{##1}} & \glshdrfont{Description} & \glshdrfont{\nth{1} Use} & \glshdrfont{Unit}\tabularnewline
    }%

    \renewenvironment{theglossary}{% Change the table type
    \begin{longtable}{rp{0.8\glsdescwidth}rl}}%
    {\end{longtable}}

    \renewcommand*{\glossaryheader}{%
        %empty first header
        \endfirsthead
        \mltcolspan{c}{\textit{(\expandafter\MakeUppercase\currentglossary{} continued)}}\\
        \endhead
    }%
    \renewcommand{\glossentry}[2]{%
        \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
        \glossentrydesc{##1}\glspostdescription & ##2 & \glsentryuseri{##1}\tabularnewline
    }%use glsentryuseri to access entry, not glsuseri https://tex.stackexchange.com/a/281772/120853
}

\newglossarystyle{myacr}{%https://tex.stackexchange.com/a/269571/120853
    \setglossarystyle{long3col}% base this style on the list style
    \renewenvironment{theglossary}{% Change the table type
    \begin{longtable}{lp{0.9\glsdescwidth}l}}%
    {\end{longtable}}
    \renewcommand*{\glossaryheader}{%  Change the table header
        \glshdrfont{Short} & \glshdrfont{Description} & \glshdrfont{Pages}\\
        \endfirsthead
        \mltcolspan{c}{\textit{(\expandafter\MakeUppercase\currentglossary{} continued)}}\\
        \glshdrfont{Short} & \glshdrfont{Description} & \glshdrfont{Pages}\\
        \endhead%
    }%
    \renewcommand*{\glossentry}[2]{%
        \glstarget{##1}{\glossentryname{##1}}%
        & \glossentrydesc{##1} & ##2 \tabularnewline % Description
%       & ##2 \tabularnewline
    }%
}

\begin{filecontents}{symbols.bib}
@symbol{density,
name = {\ensuremath{\rho}},
description = {density},
group = {greek},
user1 = {\si{\kilogram\per\meter\cubed}},
}
@symbol{viscosity,
name = {\ensuremath{\mu}},
description = {(dynamic) viscosity},
group = {greek},
user1 = {\si{\pascal\second}},
}
@symbol{work,
name = {\ensuremath{W}},
description = {work},
group = {roman},
user1 = {\si{\joule}},
}
@symbol{specwork,
name = {\ensuremath{w}},
description = {specific work},
group = {roman},
user1 = {\si{\joule\per\kilogram}},
}
@symbol{heatingvalue,
name = {\ensuremath{H}},
description = {(specific) heating value},
group = {roman},
user1 = {\si{\joule\per\kilogram}},
}
@symbol{molarmass,
name = {\ensuremath{M}},
description = {molar mass},
group = {roman},
user1 = {\si{\kilogram\per\mole}},
}
@symbol{torque,
name = {\ensuremath{M}},
description = {torque},
group = {roman},
user1 = {\si{\newton\meter}},
}
@symbol{substance,
name = {\ensuremath{n}},
description = {amount of substance},
group = {roman},
user1 = {\si{\mole}},
}
@symbol{rotspeed,
name = {\ensuremath{n}},
description = {rotational speed},
group = {roman},
user1 = {\si{\per\second}},
}
@symbol{shearstress,
name = {\ensuremath{\tau}},
description = {shear stress},
group = {greek},
user1 = {\si{\newton\per\meter\squared}},
}
@symbol{boundarythickness,
name = {\ensuremath{\delta}},
description = {boundary layer thickness},
group = {greek},
user1 = {\si{\meter}},
}
\end{filecontents}

\begin{filecontents}{abbreviations.bib}
@abbreviation{ode,
  short = {ODE},
  long = {Ordinary Differential Equation}
}

@abbreviation{rms,
  short = {RMS},
  long = {Root Mean Square}
}

@abbreviation{mad,
  short = {MAD},
  long = {Median Absolute Deviation}
}

@abbreviation{cv,
  short = {CV},
  long = {Coefficient of Variation}
}

@abbreviation{cfd,
  short = {CFD},
  long = {Computational Fluid Dynamics}
}

@abbreviation{cht,
  short = {CHT},
  long = {Computational Heat Transfer}
}
\end{filecontents}

\begin{filecontents}{subsuper.bib}
@symbol{mean,
name = {\ensuremath{\bar{X}}},
description = {mean},
group = {super},
user1 = {varies},
}
@symbol{median,
name = {\ensuremath{\widetilde{X}}},
description = {median},
group = {super},
user1 = {varies},
}
@symbol{total,
name = {tot},
description = {total conditions},
group = {sub},
user1 = {--},
}
@symbol{molar,
name = {mol},
description = {molar},
group = {sub},
user1 = {--},
}
\end{filecontents}

\begin{document}
% In KOMA, create chapter+ToC entry but unnumbered
\addchap{Nomenclature}
\textit{The most commonly used symbols are listed here, alongside their location of first occurrence. Symbols used but not listed here are clarified in their respective contexts.}
\printunsrtglossary[type = symbols, style = symbunitlong]
\printunsrtglossary[type = subsuper, style = mcolalttreegroup]
\printunsrtglossary[type = abbreviations, style = myacr]
\end{document}

It looks like: enter image description here

I would be happy to receive feedback. Perhaps, this question hits enough keywords to help people lost on Google in the future (like I was). Note that the generation requires

pdflatex
bib2gls
pdflatex
1
  • For reference, I indeed ended up splitting the one *.bib-file into all respective parts. Each is then invoked using a newly defined type via e.g. \newglossary*{greek}{Greek}. I then \printunsrtglossary[type = greek, style = mystyle]. This has disadvantages (mainly more manual work), but also gives good control. Symbols can receive their own style (using mystyle) which can involve units, and abbreviations receive a different style. This would not be possible with just \printunsrtglossaries.
    – Alex Povel
    Commented Mar 4, 2019 at 18:36

1 Answer 1

1
+50

I won't claim that the docu is very clear here. But it seems to work if you set the sort-field to group and perhaps a second field as sort-suffix. The bib2gls-call was bib2gls --group file (the --group option isn't really needed in this example, but if you have entries without group field, it will create a title for them).

\documentclass{article}
\usepackage[record,style=alttreegroup,nomain,symbols]{glossaries-extra}

\begin{filecontents}{symbols.bib}
@symbol{alpha,
name = {\ensuremath{\alpha}},
description = {angle},
group = {greek},
}
@symbol{theta,
name = {\ensuremath{\theta}},
description = {for testing},
group = {greek},
}
@symbol{test,
name = {test},
description = {aaa for testing},
group = {greek},
}
@symbol{diffusion,
name = {\ensuremath{D}},
description = {diffusion factor},
group = {roman},
}
@symbol{choke,
name = {\ensuremath{\mathrm{cor}}},
description = {corrected},
group = {sub},
}
@symbol{blockage,
name = {\ensuremath{B}},
description = {blockage factor},
group = {roman},
}
\end{filecontents}

\GlsXtrLoadResources % input file created by bib2gls
[% instructions to bib2gls:
    src={symbols},
    type = symbols,
    selection = {all},%
    sort-field={group}, 
    sort-suffix={description}   
]


\setglossarypreamble[symbols]{\glssetwidest{MMM}}

\begin{document}
\glsxtrsetgrouptitle{roman}{Roman Letters}
\glsxtrsetgrouptitle{greek}{Greek Letters}
\glsxtrsetgrouptitle{sub}{Subscripts}

\printunsrtglossaries % iterate over all defined entries
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .