Recent news (2017-04-18): glossaries-extra v1.14 released.

# bib2gls

bib2gls is a Java command line application to convert .bib files to glossaries-extra.sty resource files and simultaneously perform the indexing step. It's currently still experimental, but is available for testing.

## Details

 Latest Version: 0.7a (Experimental) Java Runtime Environment (at least JRE 7) and at least v1.12 of the glossaries-extra package (ideally v1.13, to avoid the bug in \glsdisp). GPLv3+ User Manual (PDF)

## Example Usage

The glossary entries are stored in a bib file. For example, the file entries.bib might contain:

@entry{bird,
name={bird},
description = {feathered animal}
}

@abbreviation{html,
short="html",
long={hypertext markup language}
}

@symbol{v,
name={$\vec{v}$},
text={\vec{v}},
description={a vector}
}

@index{goose,plural="geese"}

Here's an example document that uses this data:
\documentclass{article}

\usepackage[record]{glossaries-extra}

src={entries},% data in entries.bib
sort={en-GB},% sort according to 'en-GB' locale
]

\begin{document}
\Gls{bird} and \gls{goose}.

\printunsrtglossaries
\end{document}


If this document is called myDoc.tex, the build process is:

pdflatex myDoc
bib2gls myDoc
pdflatex myDoc


Note that there's no makeglossaries (or makeindex/xindy) invocation, since bib2gls not only fetches the references used in the document, it also sorts the entries and collates the location lists. The information is written to a temporary file with the extension .glstex which is input by \GlsXtrLoadResources. Since the entries are defined in that file according to their sorted order, the glossary can simply be displayed using \printunsrtglossary (or the iterative \printunsrtglossaries).

You may have multiple resources with different sort methods. For example:

\GlsXtrLoadResources[
src={terms},% data in terms.bib
sort={en-GB},% sort according to 'en-GB' locale
type={main}% put the entries in the 'main' glossary
]
src={symbols},% data in symbols.bib
sort={use},% sort according to use
type={symbols}% put the entries in the 'symbols' glossary
]


There are a variety of sorting methods: locale (e.g. en for English or de-CH-1996 for Swiss-German using the new orthography), use (order of use within the document), definition (order of definition in the bib file), letter (case or case-insensitive), numerical (integer, hexadecimal, octal, binary, float, double). You can also select the field to sort by.

Note that, although bib2gls functions as an indexing application, if you really need to use makeindex or xindy (for example, you need a custom xindy rule that can't be replicated by bib2gls), then you can switch off bib2gls's indexing functions (sort={none}, save-locations={false}) and simply use it to fetch the data from the .bib file. In order to do this, you'll need the record=alsoindex package option instead of just record (along with the xindy package option for xindy syntax) and use \makeglossaries and \printglossaries as usual. (Put \makeglossaries before \GlsXtrLoadResources[src={bib-files}, sort={none}, save-locations={false}].) The build process will then need to be

pdflatex myDoc
bib2gls myDoc
pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc


This is because the indexing in the makeglossaries step can't be performed until the entries have been defined, and the entries can't be defined until they've been fetched by bib2gls, but bib2gls can't fetch them until the entry use has been recorded in the .aux file. In this case, the only benefits to using bib2gls is the ability to manage the entries in a system such as JabRef and the ability to pick up dependent entries that haven't been referenced in the document.

The last file above is the English resource file. If you would like to translate it, your file should be named bib2gls-lang-id.xml where lang-id is the language or locale code. This can simply be the language code (for example, fr) or a language and script combination (for example, sr-Latn) or a full locale language tag (although it's best not to be too specific, otherwise the resource won't be available for the same language in a different region).

## Manual Installation

The files should be installed as follows where TEXMF indicates your local or home TEXMF path (for example, ~/texmf/):

• TEXMF/scripts/bib2gls/bib2gls.sh (Unix-like systems only)
• TEXMF/scripts/bib2gls/bib2gls.jar
• TEXMF/scripts/bib2gls/texparserlib.jar
• TEXMF/scripts/bib2gls/resources/bib2gls-en.xml
• TEXMF/doc/support/bib2gls/bib2gls.pdf
cd ~/bin
ln -s ~/texmf/scripts/bib2gls/bib2gls.sh bib2gls

To test the installation run the following from your command prompt or terminal:
bib2gls --version

If you get the following message:
Fatal error: Can't find language resource file.
then check that the resources sub-directory has been correctly copied over.

Windows users can create a batch script analogous to bib2gls.sh called bib2gls.bat that contains the following:

@ECHO OFF
FOR /F %%I IN ('kpsewhich --progname=bib2gls --format=texmfscripts bib2gls.jar') DO SET JARPATH=%%I
java -Djava.locale.providers=CLDR,JRE -jar "%JARPATH%" %*


If bib2gls is later added to the TeX distributions for Windows, the distribution will probably provide an executable file that you can use instead.

Source code is available on GitHub.

Top

© 2017 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.