The Manual of MPybtex


Using Pybtex

Pybtex is compatible with BibTeX — just type pybtex instead of bibtex:

latex foo
pybtex foo
latex foo
latex foo

Unlike BibTeX, Pybtex supports multiple bibliography data formats. If you run

pybtex -f bibtexml foo

Pybtex will read bibliography data in BibTeXML format from foo.bibtexml file instead of foo.bib.

Using MPybtex

MPybtex is an extended version of Pybtex, which supports bibliography files in following formats:

  • Reference Manager - .ris
  • EPrints3 XML - .epr
  • METS/MODS - .mets

Basic usage is the same as Pybtex:

latex foo
mpybtex foo
latex foo
latex foo

If (in current directory) there is more than one bibliography file with known to MPybtex extension, then all that files are imported in a following order: .ris, .mets, .mods, .epr, .bibtexml, .bibyaml, .bib.

Then, MPybtex tries to load any existing file with suffix .local and any of known extensions listed above. The .local files are produced by MRefTeX software.

Using (M)Pybtex with (experimental) pythonic bibliography styles

Pybtex supports bibliography styles written in Python, although this feature is still in development. If you want to give it a try, first examine the sources in the pybtex/style subdirectory, then run:

pybtex -l python foo

If you want to use MPybtex you cannot work with BibTeX style language - mpybtex always uses python styles.

As of now there are only two styles available in pybtex/style/formatting/. and which are partial and very incomplete port of BibTeX .bst files.

The good news for MPybtex user is that style files can also be defined in directory with LaTeX document. See Style API description for details.

Pythonic styles are markup-independent, it is possible to format the bibliography as HTML or plain text:

pybtex -e pybtex -b html foo
pybtex -e pybtex -b plaintext foo

Label and name styles are also configurable:

pybtex -e pybtex --label-style number --name-style last_first foo

Label and name styles are defined in pybtex/style/ and pybtex/style/, look there for details. MPybtex users can also define label and name styles in user style file in directory with LaTeX document.

Using Pybtex as a bibliography files converter

Pybtex has a simple pybtex-convert utility, which can convert bibliography files between supported formats:

pybtex-convert foo.bib foo.yaml

The conversion is not always lossless due to limitations of storage formats:

  • Native BibTeX format stores personal names as single strings, while BibTexML and Pybtex' YAML format store first name, last name, and other name parts seprately.
  • BibTeXML format does not support LaTeX preambles.
  • The order of keys is not preserved during the conversion (this may be fixed some day).

Unfortunately, there is no analogous script for MPybtex.

Using Pybtex programmatically

Using the BibTeX parser

>>> from pybtex.database.input import bibtex
>>> parser = bibtex.Parser()
>>> bib_data = parser.parse_file('examples/foo.bib')
>>> bib_data.entries.keys()
[u'ruckenstein-diffusion', u'viktorov-metodoj', u'test-inbook', u'test-booklet']
>>> print bib_data.entries['ruckenstein-diffusion'].fields['title']
Predicting the Diffusion Coefficient in Supercritical Fluids

(to be continued)