2

I am currently exploring the tools given by glossaires-extra when combined with bib2gls. But I get stuck on some points.

I have to work with multiple glossaries, so I declare my glossaries notation and symbols. I know that symbols can be define automatically with a proper package option, but I keep it like this for my example as a trial. I would like to have (if possible) all the definition in a single file, that I named test-entries.bib. Here comes my first problem, I can not use the command type=notation for example, because it affects all the entries to this type. So, I tried with entry-type-aliases, but I did not succeeded to redirect each entry to its glossary. This is confirmed by the warning : No entries defined in glossary 'notation' on line 33.

The second point is that I would like to sort the symbols type by category then by group then by name, and I do not really know how to do so, and specially when its in the same file that other entries.

Here is a MWE. The test-entries.bib:

@acronym{html,
    short= {HTML}, 
    long= {hypertext markup language},
    category={inline},
}

@acronym{shtml,
    short= {SHTML}, 
    long= {server-parsed HTML},
    category={footer},
}

@notation{mesh,
    name={tesh},
    description={this is a lattice network},
    sort={m}, 
}

@symbol{f, %
    name={\ensuremath{ f }}, %
    description={a given function}, %
    unit= {$\varnothing$}, %
    category= {operator},
    group={latin}
}

@symbol{xi, %
    name={\ensuremath{ \xi }}, %
    description={a space variable}, %
    unit= {m}, %
    category= {variable},
    group={greek}
}

@symbol{fi, %
    name={\ensuremath{ f_i }}, %
    description={another function}, %
    unit= {$\varnothing$}, %
    category= {operator},
    group={latin}
}

@symbol{xii, %
    name={\ensuremath{ \xi_i }}, %
    description={a discretized space variable}, %
    unit= {m}, %
    category= {variable},
    group={greek}
}

@symbol{t, %
    name={\ensuremath{ t }}, %
    description={a time variable}, %
    unit= {s}, %
    category= {variable},
    group={latin}
}

then the main.tex :

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath,amsfonts,amssymb}

    \usepackage[nomain, abbreviations, record, automake]{glossaries-extra}

    %Newglossaries
    \newglossary[ntg]{notation}{not}{ntn}{Notation} 
    \newglossary[slg]{symbols}{sym}{sbl}{Nomenclature}

    % new keys must be defined before \GlsXtrLoadResources    
    \glsaddstoragekey{unit}{}{\glsentryunit}
    % name the group greek letter
    \glsxtrsetgrouptitle{greek}{Greek Symbols}

\GlsXtrLoadResources[
        src={../test-entries}, % entries in symbols.bib
        entry-type-aliases={symbol=symbols},
        entry-type-aliases={notation=notation},
        sort-field={group},% sort @symbol entries by name field
        symbol-sort-fallback=name,% sort @symbol entries by name field
        identical-sort-action=description,% sort by description if sort value identical
        selection=all,
%       type=symbols,% put these entries in the symbols glossary
        save-locations=false,% location list not needed
    ]

\begin{document}

    \printunsrtglossary[type=\glsxtrabbrvtype]
    \printunsrtglossary[type=notation]
    \printunsrtglossary[type=symbols]

\end{document}
3

Most of the resource options aren't cumulative. That is, if used multiple times the last option usually overrides the previous option of the same name. This means that:

    entry-type-aliases={symbol=symbols},
    entry-type-aliases={notation=notation},

is equivalent to just:

    entry-type-aliases={notation=notation},

You need to have all the aliases in one setting. For example:

    entry-type-aliases={symbol=symbols,notation=notation},

However, neither of these aliases work. The first (symbol=symbols) makes @symbol behave as though it was @symbols, but that bib entry type doesn't exist (whereas @symbol does). The second alias (notation=notation) makes @notation behave as though it was @notation, which is a redundant instruction, but also that bib entry type doesn't exist.

The only unknown entry type in your bib file is @notation so that's the only one that needs aliasing. I recommend you alias it to @entry:

  entry-type-aliases=
  {
    notation=entry,% make @notation behave like @entry
  },

When you have a single bib file that contains entries in multiple glossaries, there are several ways of assigning the type.

The first method is to ensure that the original entry type matches the required glossary type. This would mean having glossaries labelled acronym (to match @acronym), symbol (to match @symbol) and notation (to match @notation). This can be done with:

\usepackage[nomain, record, automake]{glossaries-extra}

\newglossary*{acronym}{Abbreviations}
\newglossary*{notation}{Notation}
\newglossary*{symbol}{Nomenclature}

and use the resource option:

  type={same as original entry},

The type option in \printunsrtglossary also needs to be adjusted to match:

\printunsrtglossary[type=acronym]
\printunsrtglossary[type=notation]
\printunsrtglossary[type=symbol]

The second method is to filter the entries and have one \GlsXtrLoadResources per glossary type and set the type. For example:

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  type=\glsxtrabbrvtype,
  match={entrytype=acronym},% only consider @acronym for selection
%... other options
]

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  entry-type-aliases=
  {
    notation=entry,% make @notation behave like @entry
  },
  type=notation,
  match={entrytype=entry},% only consider @entry for selection
%... other options
]

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  type=symbols,
  match={entrytype=symbol},% only consider @symbol for selection
%... other options
]

The third method is to adjust the helper commands used to define the entries in the .glstex file that's created by bib2gls. The entries defined using @acronym in the .bib file are defined in the .glstex file using \bibglsnewacronym. This is defined to use \newacronym, so if you have used the abbreviations package option (as in your MWE) then you don't need to worry about it (as long as you don't override the default type).

Entries that are defined in the .bib file using @symbol are defined in the .glstex file using \bibglsnewsymbol. The definition of this command is provided in the .glstex file as:

\providecommand{\bibglsnewsymbol}[4]{%
 \longnewglossaryentry*{#1}{name={#3},sort={#1},category={symbol},#2}{#4}}

So you could define this command before \GlsXtrLoadResources so that it explicitly sets the type in the second argument of \longnewglossaryentry*. For example:

\newcommand{\bibglsnewsymbol}[4]{%
 \longnewglossaryentry*{#1}{name={#3},sort={#1},category={symbol},type={symbols},#2}{#4}}

This will put the entries defined with @symbol into the symbols glossary (unless explicitly overridden).

The entries defined using @notation were aliased to @entry so they are defined in the .glstex file using \bibglsnewentry. This command is provided in the .glstex file as:

\providecommand{\bibglsnewentry}[4]{%
 \longnewglossaryentry*{#1}{name={#3},#2}{#4}%
}

Again, you can define this command before \GlsXtrLoadResources so that the glossary type is explicitly set:

\newcommand{\bibglsnewentry}[4]{%
 \longnewglossaryentry*{#1}{name={#3},type={notation},#2}{#4}%
}

This method means that you don't need to change your glossary definitions (\newglossary) and you don't use the type option in the \GlsXtrLoadResources option list.

Regarding the sorting, you can have a main field that provides the sort value (sort-field) and you can have a fallback field where the sort values are identical (identical-sort-action) but you can't have a second fallback field if the first fallback field is also identical.

You've changed the sort field to group with:

sort-field={group}

and supplied a group field for some but not all of the entries in the .bib file. It's present for all the @symbol entries, which means that the sort value is never missing for any @symbol entries and so the option:

symbol-sort-fallback=name

is redundant, because there is never a need to fallback on another field.

The change in sort-field means that no entries are sorted according to the sort field (as the default sort-field=sort has been switched to sort-field=group). This means that the sort field set in your entry:

@notation{mesh,
    name={tesh},
    description={this is a lattice network},
    sort={m},
}

does nothing. (Incidentally, did you mean "mesh" rather than "tesh"?) The field used for sorting is now group but this field hasn't been set and there's no fallback field to use in its place. (@notation was aliased to @entry so symbol-sort-fallback doesn't apply.)

I recommend a different approach. You can filter out the symbols from the other entries and apply different sorting and group formations. The first resource set can just deal with the entries that use normal alphabetic sorting with the default sort-field=sort, where missing sort fields fallback on the name field for entries defined with @entry (@notation with the notation=entry alias) and the short field for entries defined with @acronym:

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  entry-type-aliases=
  {
    notation=entry,% make @notation behave like @entry
  },
  type={same as original entry},
  selection=all,
  match={entrytype=(acronym|entry)},% only select @acronym and @entry
  save-locations=false,% location list not needed
]

This filters out the entries so that it only selects the @acronym and @entry entries using:

  match={entrytype=(acronym|entry)},% only select @acronym and @entry

In this example, an alternative is to filter out @symbol instead using:

  not-match={entrytype=symbol},% don't select @symbol

This is simpler. The second resource set can then use:

  match={entrytype=symbol},% only select @symbol

to only select @symbol and filter out all the other entries.

You have a group title assigned using:

\glsxtrsetgrouptitle{greek}{Greek Symbols}

but you're not actually using a glossary style that shows the group title. Even if you do use a group style, the result will be strange if you don't ensure that the sorting will result in entries blocked according to group. The group field is normally assigned by the sort method to ensure this, but if you explicitly set the group field, then there's no guarantee that you won't have the groups scattered.

I would like to sort the symbols type by category then by group then by name

As I already mentioned, you can't sort by three fields but if your group fields are all latin and greek then a character code sort on the name field will automatically separate the Latin and Greek characters, so I don't think you actually need the group field set in the .bib file (especially if you're not using a group glossary style).

Let's suppose the file test-entries.bib is now:

@acronym{html,
    short= {HTML}, 
    long= {hypertext markup language},
    category={inline}
}

@acronym{shtml,
    short= {SHTML}, 
    long= {server-parsed HTML},
    category={footer}
}

@notation{mesh,
    name={mesh},
    description={this is a lattice network}
}

@symbol{f, %
    name={\ensuremath{ f }}, %
    description={a given function}, %
    unit= {$\varnothing$}, %
    category= {operator}
}

@symbol{xi, %
    name={\ensuremath{ \xi }}, %
    description={a space variable}, %
    unit= {m}, %
    category= {variable}
}

@symbol{fi, %
    name={\ensuremath{ f_i }}, %
    description={another function}, %
    unit= {$\varnothing$}, %
    category= {operator}
}

@symbol{xii, %
    name={\ensuremath{ \xi_i }}, %
    description={a discretized space variable}, %
    unit= {m}, %
    category= {variable}
}

@symbol{t, %
    name={\ensuremath{ t }}, %
    description={a time variable}, %
    unit= {s}, %
    category= {variable}
}

Then complete MWE (using the first method of assigning the type) is:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath,amsfonts,amssymb}

\usepackage[nomain, record, automake]{glossaries-extra}

\newglossary*{acronym}{Abbreviations} 
\newglossary*{notation}{Notation} 
\newglossary*{symbol}{Nomenclature}

% new keys must be defined before \GlsXtrLoadResources    
\glsaddstoragekey{unit}{}{\glsentryunit}

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  entry-type-aliases=
  {
    notation=entry,% make @notation behave like @entry
  },
  type={same as original entry},
  selection=all,
  not-match={entrytype=symbol},% don't select @symbol
  save-locations=false,% location list not needed
]

\GlsXtrLoadResources[
  src={test-entries}, % entries in test-entries.bib
  type={same as original entry},
  sort-field=category,
  identical-sort-action=name,% sort by name if category is identical
  selection=all,
  save-locations=false,% location list not needed
  match={entrytype=symbol},% only select @symbol
  sort={letter-nocase}
]

\begin{document}

\printunsrtglossary[type=acronym]
\printunsrtglossary[type=notation]
\printunsrtglossary[type=symbol]

\end{document}

The list of abbreviations looks like:

Abbreviations HTML hypertext markup language SHTML server-parsed HTML

The notation list looks like:

Notation mesh this is a lattice network

The symbols list looks like:

Nomenclature f a given function fi another function t a time variable ξ a space variable ξi a discretized space variable

If you want to sub-divide this with titles, then it's better to use the category field rather than the group field (since sort-field=category ensures unbroken category blocks). This can be done by replacing:

\printunsrtglossary[type=symbol]

with:

\printunsrtglossary*[type=symbol,style=indexgroup]
{%
  \renewcommand{\glsxtrgroupfield}{category}%
}

which now produces:

Nomenclature operator f a given function fi another function variable t a time variable ξ a space variable ξi a discretized space variable

You can still use \glsxtrsetgrouptitle to set the group titles:

\printunsrtglossary*[type=symbol,style=indexgroup]
{%
  \glsxtrsetgrouptitle{operator}{Operators}%
  \glsxtrsetgrouptitle{variable}{Variables}%
  \renewcommand{\glsxtrgroupfield}{category}%
}

which produces:

Nomenclature Operators f a given function fi another function Variables t a time variable ξ a space variable ξi a discretized space variable

1
  • I like very much your solutions + explanations and your work in general. I just found more handy to use the command match={type=notation} rather that match={entrytype=entry} or not-match={entrytype=symbol}. I hope it has not counterpart or unexpected affects. – R. N Feb 8 '19 at 14:09

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.