Go to page:

Search:   Help

Edit

# Biblatex

Categories: Bibliography, Biblatex
<< | Page list | >>

How to use biblatex with LyX (or How to fool biblatex and LyX in order to let them cooperate)

## What is biblatex?

Biblatex follows a completely new approach to bibliography management insofar as it reimplements almost everything on the LaTeX side. It originally used bibtex for preprocessing but now biber is the preferred preprocessor for biblatex. Please refer to this page for more information.

## Using biblatex with LyX

LyX doesn't provide native support for biblatex yet. However, it is possible to use it with some effort, as described here. Note that you will need at least version 0.7 of biblatex. The biblatex manual strongly advises to use biber or at least bibtex8 instead of the traditional bibtex to process the data, because the capacities of traditional bibtex are too limited for biblatex. The best choice is definitely biber, a bibliography processor written in Perl and specifically designed for biblatex as a bibtex replacement. Biber has no resource limits, it can deal with unicode any many other encodings, and it provides some extra hooks that allow biblatex to perform some complex tasks. Even though biblatex still can be used with bibtex8 and even traditional bibtex, some complex things only work with biber.

To use biblatex with LyX and have the possibility of inserting citations from the standard LyX citation dialog, follow these steps:

1. Make sure you have biber package installed.
2. To change from bibtex to biber, go to Document→Settings→Bibliography and change the Processor field from default or bibtex to biber (you can also input biber options here, if you need them). The citation style will be governed by the biblatex style option, and should be set to Default (numerical) here unless the natbib compatibility mode is used, as described below.
The default bibliography processor can also be changed globally in Tools→Preferences→Output→LaTeX.
3. In the document preamble (Document→Settings→LaTeX Preamble), load biblatex manually:
\usepackage[style=authoryear,backend=biber]{biblatex}
or, somewhat more fancy
\usepackage[style=philosophy-modern,backend=biber]{biblatex}
For a numeric or alpha-numeric style, you just need something like:
\usepackage[style=numeric,backend=biber]{biblatex}
or, for example,
\usepackage[style=phys,backend=biber]{biblatex}
Passing the option backend=biber (instead of backend=bibtex) to the \usepackage[...]{biblatex} call is not necessary in recent biblatex releases, as biber is used by default if no other option has been given.
Please refer to the biblatex documentation for further options.
• Note that the bib file must either be located in your texmf tree (do not forget to run texhash in the terminal to tell LaTeX where to find the new file unless you put it in your personal directory), or you must enter the absolute path in the command above:
in Windows \addbibresource{C:/Documents and Settings/My Name/Documents/Dissertation/Dissertation.bib}
The latter can be automated, making the document portable, for .bib files in the (sub)folder of the main document by the following set of commands in the document preamble (replace name_of_your_bib_file.bib with the proper database name):
\ifcsname input@path\endcsname\else\def\input@path{{./}}\fi
\def\@@setabsolutebibname#1#2{\edef\@@absolutebibname{#1#2}}
\expandafter\@@setabsolutebibname\input@path{name_of_your_bib_file.bib}

LyX, namely, defines the \input@path macro as the path to the document directory. The path is enclosed in curly braces that have to be stripped. The first line is here only to assure that even after exporting to latex and compiling from the command line, the \input@path macro is still properly defined (LyX adds this macro only when compiling in the temp dir)
5. In the document, insert the BibTeX inset (Insert→List/TOC→BibTeX Bibliography...) in a LyX note or comment, such that LyX finds the citations, but no \bibliography command is output to LaTeX. It does not matter which style you chose here, so you can stick to plain. However, in order to use the citation dialog, you'll have to choose the correct databases (i.e. those you loaded above in item (4)).
6. In the document, enter \printbibliography in ERT (TeX mode) at the point in the text where you want the bibliography to occur.

Note on the natbib compatibility mode: The natbib=true option in the call of biblatex loads a natbib compatibility module. The module defines aliases for the citation commands provided by the natbib package. This includes aliases for the core citation commands \citet and \citep as well as the variants \citealt and \citealp.

\usepackage[style=authoryear,natbib=true,backend=biber]{biblatex}

These citation commands (or styles) can be invoked from the drop-down menu in Insert→Citation... if the Citation Style is set to natbib in Document→Settings→Bibliography. LyX, however, has to be tricked into not exporting the actual call to the natbib package by the following line in the document's local layout Document→Settings→Local Layout

Provides natbib 1

Make sure you press the Validate button before applying the change.

Same can be accomplished by:

• Putting the file biblatex.module in the layouts folder in your user directory (Help→About LyX tells you where you can find this directory).
• Running Tools→Reconfigure, restarting LyX and selecting the module "Biblatex-citation-styles" from Document→Settings→Modules.

Note on using bibtex (or bibtex8) instead of biber: Biblatex originally used bibtex for for pre-processing but now biber is the preferred pre-processor for biblatex. If you want to use biblatex with classic bibtex nonetheless, you must pass the option backend=bibtex to the \usepackage[...]{biblatex} command (see above).

To change from bibtex to bibtex8 instead, go to Preferences→Settings→Output→LaTeX and change the bibtex command from bibtex to bibtex8 --wolfgang --csfile latin9.csf or something similar. Please refer to the biblatex manual, section 2.4.2 (BibTeX capacity issues) for further explanations on the --wolfgang switch, and to section 2.4.3 (BibTeX sorting and encoding issues) for explanations on the --csfile switch, which need to be adapted to your bib file encoding. Also note that you will need to pass the option backend=bibtex8 (instead of backend=bibtex) to the \usepackage[...]{biblatex} call if you use bibtex8.

Note on XeTeX and polyglossia: If you use XeTeX with the polyglossia language package, you will need to manually load the polyglossia package in the preamble just before the above call to biblatex, and set the default language, as follows:

\usepackage{polyglossia}
\setdefaultlanguage{english}

Otherwise, you'll get LaTeX errors of the following kind:

! Undefined control sequence.
<argument> blx@lng@\bbl@main@language


## Known problems

• If biber doesn't work or stops working suddenly (with or without an error being reported) resulting in the failure of citations and / or bibliography, you may get it going (again) by following the instructions from this blog post or this stackexchange entry.
In short, you need to delete an invalid temporary cache folder which irritates biber. You can find out the par cache by checking either by inserting biber --cache in a terminal window or by inspecting Document→LaTeX Log→BibTeX (watch out for an error message looking like this: data source /some/path/par-<some number>/cache-<some number>/[...]/recode_data.xml not found; the folder to delete is the one starting with cache-).