Command line application to convert .bib files to glossaries-extra.sty resource file
Related resources: bib2gls FAQ and bib2gls gallery.
Related TUGboat articles:
- Glossaries with bib2gls, issue 40:1, 2019. (PDF)
- bib2gls: selection, cross-references and locations, issue 41:3, 2020. (PDF)
- bib2gls: sorting, issue 42:2, 2021. (PDF)
- bib2gls: standalone entries and repeated lists (a little book of poisons), issue 43:1, 2022. (PDF)
(This application was developed as a follow-up from my answer on TeX on StackExchange.)
The bib2gls tool forms part of a LaTeX document build, performing two
functions in one: glossary information is fetched from one or
more .bib files by examining the .aux file (similar to BibTeX)
and the terms are then sorted hierarchically and the locations collated into
compact lists (similar to Makeindex/Xindy). A .glstex file
is then created containing the data defined in terms of
\longnewglossaryentry* or \newabbreviation (provided by
glossaries-extra.sty) in the appropriate order. This file
is input by \GlsXtrLoadResources (which also writes the required
settings to the .aux file for bib2gls). The glossary
can then simply by displayed with \printunsrtglossary. The
.bib files can be managed in an application like JabRef.
You may prefer to start with the introductory guide
before moving on to the main user manual.
This application requires at least Java 8 and at least v1.12 of
glossaries-extra.sty
(2017-02-03) and at least v4.04 of glossaries.sty. (Although newer versions are recommended,
and may be required for some features.)
The main home page is dickimaw-books.com/software/bib2gls.
The latest stable version of bib2gls is available from CTAN.
The code in this GitHub repository may be for an unstable version.
Stable versions have a version number in the form major.minor.
Unstable versions have a version number in the form major.minor.YYYYMMDD.
If you already have a .tex file containing lots of
definitions using \newglossaryentry,
\newacronym etc, you can convert it to a .bib
file using the supplementary command line application
convertgls2bib. For example, if the original definitions
are in entries.tex then
convertgls2bib entries.tex entries.bibwill create the file entries.bib containing all the definitions
found in entries.tex. Other information in entries.tex should be
ignored, but command definitions will be parsed. (Avoid any code
that's overly complicated. The TeX parser library isn't a
TeX engine!)
The .bib format doesn't support spaces in labels, so if your
.tex file has spaces in labels use --space-sub replacement
to substitute the spaces with replacement. For example
convertgls2bib --space-sub '-' entries.tex entries.bibwill replace spaces with hyphens or
convertgls2bib --space-sub '' entries.tex entries.bibwill strip spaces. The values of the see, seealso and
alias fields will also be adjusted, but any references using
\gls etc will have to be replaced manually (or use your
text editor's search and replace function).
As from v4.0, there is now also a similar command line tool
datatool2bib to convert datatool
databases and datagidx indexing commands to bib files.
File entries.bib:
% Encoding UTF-8
@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"}File myDoc.tex:
\documentclass{article}
\usepackage[record]{glossaries-extra}
\GlsXtrLoadResources[
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}Document build:
pdflatex myDoc
bib2gls myDoc
pdflatex myDocOr, if letter groups are required:
pdflatex myDoc
bib2gls -g myDoc
pdflatex myDocYou will need to have Java installed. (At least Java 8.)
[TODO: The TeX Java Parser Library will also need to be installed]
bib2gls is available in both TeX Live and MiKTeX,
so you can install it via your TeX package manager.
To test the installation run the following from your command prompt or terminal:
bib2gls --versionIf 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.
Create sub-directories src/lib,
src/classes/com/dickimawbooks/bib2gls and
src/classes/com/dickimawbooks/gls2bib
Requires texjavaparserlib.jar which can be compiled from
texparser.
Copy texjavaparserlib.jar and texjavaparserlib-en.xml to src/lib.
Compile from src using:
cd java/bib2gls
javac -d ../../classes -cp ../../lib/texjavaparserlib.jar *.java
cd ../classes
jar cmf ../java/bib2gls/Manifest.txt ../lib/bib2gls.jar com/dickimawbooks/bib2gls/*.classSimilarly for gls2bib. The actual .jar file is called
convertgls2bib.jar to reduce the chances of accidentally
using the wrong application.
cd java/gls2bib
javac -d ../../classes -cp ../../lib/texjavaparserlib.jar *.java
cd ../classes
jar cmf ../java/gls2bib/Manifest.txt ../lib/convertgls2bib.jar com/dickimawbooks/gls2bib/*.classLicense GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.