pybtex - Man Page

Pybtex Documentation

Command Line Interface

Making bibliographies with pybtex

The pybtex executable is used in the same way as the original bibtex command and accepts the same command line options. The only difference is that you type pybtex instead of bibtex.

For example, to compile the bibliography for a LaTeX file named book.tex, you need to type:

$ latex book
$ pybtex book
$ latex book
$ latex book  # to get cross-references right

See the BibTeX tutorial by Andrew Roberts for a basic explanation of how to use BibTeX.

Bibliography formats other then BibTeX

Pybtex is fully compatible with BibTeX’ .bib files. Besides that, Pybtex supports other bibliography formats. The list of supported formats can be seen in the output of pybtex --help.

By default, the BibTeX format is used. If a LaTeX file book.tex contains:

\bibliography{mybook}

Then this command:

$ pybtex book

will expect to find the bibliography data in a BibTeX-formatted file mybook.bib.

Pybtex can be instructed to use a different format with the --format option. For example this command:

$ pybtex --format yaml book

will tell Pybtex to look for a YAML-formatted file mybook.yaml instead of mybook.bib.

Support for additional bibliography formats can be added by plugins.

Pythonic bibliography styles

BibTeX has a built-in stack oriented programming language for defining bibliography formatting styles.  This language is used in .bst style files.  Pybtex is fully compatible with BibTeX’ .bst style files.

Additionally, Pybtex allows to write bibliography styles in Python. Some base BibTeX styles, including plain, alpha, unsrt, have been ported to Python already.  They can be found in pybtex/style/formatting subdirectory.  Additional styles can be added as plugins.

By default, Pybtex uses BibTeX’ .bst styles.  You can switch the style language from BibTeX to Python with the --style-language option:

$ pybtex --style-language python book

One of the advantage of using Pythonic styles is that they can produce HTML, Markdown or plain text output besides the usual LaTeX markup. To change the output backend from LaTeX to something else, use the --output-backend option:

$ pybtex --style-language python --output-backend html book
$ pybtex --style-language python --output-backend plaintext book

(In this case Pybtex will write the bibliography to book.html or book.txt instead of book.bbl.)

Support for other markup formats can be added by plugins.

Additionally, Pythonic styles are configurable with command line options to some extent.  For example, the --name-style option tells Pybtex to use a different name formatting style, --abbreviate-names forces Pybtex to use the abbreviated name format, etc.  See pybtex --help for more options.

Converting bibliography databases with bibtex-convert

Pybtex comes with an additional utility called pybtex-convert. It converts bibliography databases between supported formats:

$ pybtex-convert book.bib book.yaml

Be aware that the conversion is not always lossless. For example:

  • BibTeX’ string macros are substituted by their values during conversion.
  • BibTeXML does not support LaTeX preambles.
  • In the standard BibTeX format, names are stored as single strings.  BibTexML and Pybtex’ Yaml format store first name, last name, and other name parts separately.

Pretty-printing bibliography databases with bibtex-format

Sometimes you may want to convert a bibliography database to a human-readable format.  Pybtex has another utility called pybtex-format for that:

$ pybtex-format book.bib book.txt
$ pybtex-format book.bib book.html

By default, the unsrt style is used for formatting.  This can be changed with the --style option:

$ pybtex-format --style alpha book.bib book.txt

Supported Formats

Bibliography formats

BibTeX

BibTeX is the default bibliography format used by Pybtex:

@BOOK{strunk-and-white,
    author = "Strunk, Jr., William and E. B. White",
    title = "The Elements of Style",
    publisher = "Macmillan",
    edition = "Third",
    year = 1979
}

Some links:

  • A basic description of the BibTeX format.
  • An in-depth description of the quirky BibTeX syntax.

BibTeXML

BibTeXML is an attempt to translate the BibTeX format into XML. The above BibTeX snippet translates into this XML:

<bibtex:entry id="strunk-and-white">
    <bibtex:book>
        <bibtex:author>
            <bibtex:person>
                <bibtex:first>William</bibtex:first>
                <bibtex:last>Strunk</bibtex:last>
                <bibtex:lineage>Jr.</bibtex:lineage>
            </bibtex:person>
            <bibtex:person>
                <bibtex:first>E.</bibtex:first>
                <bibtex:middle>B.</bibtex:first>
                <bibtex:last>White</bibtex:last>
            </bibtex:person>
        </bibtex:author>
        <bibtex:title>The Elements of Style</bibtex:title>
        <bibtex:publisher>Macmillan<bibtex:publisher>
        <bibtex:edition>Third</bibtex:edition>
        <bibtex:year>1979</bibtex:year>
    </bibtex:book>
</bibtex:entry>

Yaml

We added our own experimental YAML-based bibliography format to Pybtex. It is mostly a straightforward translation of BibTeXML into YAML:

strunk-and-white:
    type: book
    author:
        - first: William
          last: Strunk
          lineage: Jr.
        - first: E.
          middle: B.
          last: White
    title: The Elements of Style
    publisher: Macmillan
    edition: Third
    year: 1979

Bibliography style formats

Pybtex currently supports bibliography styles in two formats:

  • BibTeX’ .bst files
  • Pybtex’ Pythonic styles

Output formats

BibTeX’s .bst styles usually contain hardcoded LaTeX markup and are LaTeX-only. Pythonic styles in Pybtex are markup-independent and can output multiple formats, including:

  • LaTeX
  • Markdown
  • HTML
  • plain text

There is also pybtex-docutils by Matthias Troffaes that integrates Pybtex with Docutils, and sphinxcontrib-bibtex by the same author, integrating Pybtex with Sphinx.

Python API

Reading and writing bibliography data

  • Reading bibliography data
  • Writing bibliography data
  • Bibliography data classes

Reading bibliography data

One of the most common things to do with Pybtex API is parsing BibTeX files. There are several high level functions in the pybtex.database module for reading bibliography databases.

pybtex.database.parse_string(value, bib_format, **kwargs)

Parse a Unicode string containing bibliography data and return a BibliographyData object.

Parameters
  • value – Unicode string.
  • bib_format – Data format (“bibtex”, “yaml”, etc.).

New in version 0.19.

pybtex.database.parse_bytes(value, bib_format, **kwargs)

Parse a byte string containing bibliography data and return a BibliographyData object.

Parameters
  • value – Byte string.
  • bib_format – Data format (for example, “bibtexml”).

New in version 0.19.

pybtex.database.parse_file(file, bib_format=None, **kwargs)

Read bibliography data from file and return a BibliographyData object.

Parameters
  • file – A file name or a file-like object.
  • bib_format – Data format (“bibtex”, “yaml”, etc.). If not specified, Pybtex will try to guess by the file name.

New in version 0.19.

Each of these functions does basically the same thing. It reads the bibliography data from a string or a file and returns a BibliographyData object containing all the bibliography data.

Here is a quick example:

>>> from pybtex.database import parse_file
>>> bib_data = parse_file('../examples/tugboat/tugboat.bib')
>>> print(bib_data.entries['Knuth:TB8-1-14'].fields['title'])
Mixing right-to-left texts with left-to-right texts
>>> for author in bib_data.entries['Knuth:TB8-1-14'].persons['author']:
...     print(unicode(author))
Knuth, Donald
MacKay, Pierre

Writing bibliography data

The BibliographyData class has several methods that are symmetrical to the functions described above:

  • BibliographyData.to_string() formats the bibliograhy data into a string,
  • BibliographyData.to_bytes() formats the bibliograhy data into a byte string,
  • BibliographyData.to_file() writes the bibliograhy data to a file.

    >>> from pybtex.database import BibliographyData, Entry
    >>> bib_data = BibliographyData({
    ...     'article-minimal': Entry('article', [
    ...         ('author', 'L[eslie] B. Lamport'),
    ...         ('title', 'The Gnats and Gnus Document Preparation System'),
    ...         ('journal', "G-Animal's Journal"),
    ...         ('year', '1986'),
    ...     ]),
    ... })
    >>> print(bib_data.to_string('bibtex'))
    @article{article-minimal,
        author = "L[eslie] B. Lamport",
        title = "The Gnats and Gnus Document Preparation System",
        journal = "G-Animal's Journal",
        year = "1986"
    }

Bibliography data classes

Pybtex uses several classes to represent bibligraphy databases:

  • BibliographyData is a collection of individual bibliography entries and some additional metadata.
  • Entry is a single bibliography entry (a book, an article, etc.).

    An entry has a key (like "knuth74"), a type ("book", "article", etc.), and a number of key-value fields ("author", "title", etc.).

  • Person is a person related to a bibliography entry (usually as an author or an editor).
class pybtex.database.BibliographyData(entries=None, preamble=None, wanted_entries=None, min_crossrefs=2)
entries

A dictionary of bibliography entries referenced by their keys.

The dictionary is case insensitive:

>>> bib_data = parse_string("""
...     @ARTICLE{gnats,
...         author = {L[eslie] A. Aamport},
...         title = {The Gnats and Gnus Document Preparation System},
...     }
... """, 'bibtex')
>>> bib_data.entries['gnats'] == bib_data.entries['GNATS']
True
property preamble

LaTeX preamble.

>>> bib_data = parse_string(r"""
...     @PREAMBLE{"\newcommand{\noopsort}[1]{}"}
... """, 'bibtex')
>>> print(bib_data.preamble)
\newcommand{\noopsort}[1]{}

New in version 0.19: Earlier versions used get_preamble(), which is now deprecated.

get_preamble()

Deprecated since version 0.19: Use preamble instead.

to_string(bib_format, **kwargs)

Return the data as a unicode string in the given format.

Parameters

bib_format – Data format (“bibtex”, “yaml”, etc.).

New in version 0.19.

classmethod from_string(value, bib_format, **kwargs)

Return the data from a unicode string in the given format.

Parameters

bib_format – Data format (“bibtex”, “yaml”, etc.).

New in version 0.22.2.

to_bytes(bib_format, **kwargs)

Return the data as a byte string in the given format.

Parameters

bib_format – Data format (“bibtex”, “yaml”, etc.).

New in version 0.19.

to_file(file, bib_format=None, **kwargs)

Save the data to a file.

Parameters
  • file – A file name or a file-like object.
  • bib_format – Data format (“bibtex”, “yaml”, etc.). If not specified, Pybtex will try to guess by the file name.

New in version 0.19.

lower()

Return another BibliographyData with all identifiers converted to lowercase.

>>> data = parse_string("""
...     @BOOK{Obrazy,
...         title = "Obrazy z Rus",
...         author = "Karel Havlíček Borovský",
...     }
...     @BOOK{Elegie,
...         title = "Tirolské elegie",
...         author = "Karel Havlíček Borovský",
...     }
... """, 'bibtex')
>>> data_lower = data.lower()
>>> list(data_lower.entries.keys())
['obrazy', 'elegie']
>>> for entry in data_lower.entries.values():
...     entry.key
...     list(entry.persons.keys())
...     list(entry.fields.keys())
'obrazy'
['author']
['title']
'elegie'
['author']
['title']
class pybtex.database.Entry(type_, fields=None, persons=None)

A bibliography entry.

key = None

Entry key (for example, 'fukushima1980neocognitron').

type = None

Entry type ('book', 'article', etc.).

fields = None

A dictionary of entry fields. The dictionary is ordered and case-insensitive.

persons = None

A dictionary of entry persons, by their roles.

The most often used roles are 'author' and 'editor'.

to_string(bib_format, **kwargs)

Return the data as a unicode string in the given format.

Parameters

bib_format – Data format (“bibtex”, “yaml”, etc.).

classmethod from_string(value, bib_format, entry_number=0, **kwargs)

Return the data from a unicode string in the given format.

Parameters
  • bib_format – Data format (“bibtex”, “yaml”, etc.).
  • entry_number – entry number if the string has more than one.

New in version 0.22.2.

class pybtex.database.Person(string='', first='', middle='', prelast='', last='', lineage='')

A person or some other person-like entity.

>>> knuth = Person('Donald E. Knuth')
>>> knuth.first_names
['Donald']
>>> knuth.middle_names
['E.']
>>> knuth.last_names
['Knuth']
first_names = None

A list of first names.

New in version 0.19: Earlier versions used first(), which is now deprecated.

middle_names = None

A list of middle names.

New in version 0.19: Earlier versions used middle(), which is now deprecated.

prelast_names = None

A list of pre-last (aka von) name parts.

New in version 0.19: Earlier versions used middle(), which is now deprecated.

last_names = None

A list of last names.

New in version 0.19: Earlier versions used last(), which is now deprecated.

lineage_names = None

A list of linage (aka Jr) name parts.

New in version 0.19: Earlier versions used lineage(), which is now deprecated.

property bibtex_first_names

A list of first and middle names together. (BibTeX treats all middle names as first.)

New in version 0.19: Earlier versions used Person.bibtex_first(), which is now deprecated.

>>> knuth = Person('Donald E. Knuth')
>>> knuth.bibtex_first_names
['Donald', 'E.']
get_part(type, abbr=False)

Get a list of name parts by type.

>>> knuth = Person('Donald E. Knuth')
>>> knuth.get_part('first')
['Donald']
>>> knuth.get_part('last')
['Knuth']
property rich_first_names

A list of first names converted to rich text.

New in version 0.20.

property rich_middle_names

A list of middle names converted to rich text.

New in version 0.20.

property rich_prelast_names

A list of pre-last (aka von) name parts converted to rich text.

New in version 0.20.

property rich_last_names

A list of last names converted to rich text.

New in version 0.20.

property rich_lineage_names

A list of lineage (aka Jr) name parts converted to rich text.

New in version 0.20.

first(abbr=False)

Deprecated since version 0.19: Use first_names instead.

middle(abbr=False)

Deprecated since version 0.19: Use middle_names instead.

prelast(abbr=False)

Deprecated since version 0.19: Use prelast_names instead.

last(abbr=False)

Deprecated since version 0.19: Use last_names instead.

lineage(abbr=False)

Deprecated since version 0.19: Use lineage_names instead.

bibtex_first()

Deprecated since version 0.19: Use bibtex_first_names instead.

Formatting bibliographies

  • BibTeX engine

    • How it works
  • Python engine

    • Differences from the BibTeX engine
    • How it works
  • Python API

    • The base interface
    • The BibTeXEngine class
    • The PybtexEngine class

The main purpose of Pybtex is turning machine-readable bibliography data into human-readable bibliographies formatted in a specific style. Pybtex reads bibliography data that looks like this:

@book{graham1989concrete,
    title = "Concrete mathematics: a foundation for computer science",
    author = "Graham, Ronald Lewis and Knuth, Donald Ervin and Patashnik, Oren",
    year = "1989",
    publisher = "Addison-Wesley"
}

and formats it like this:

R. L. Graham, D. E. Knuth, and O. Patashnik. Concrete mathematics: a foundation for computer science. Addison-Wesley, 1989.

Pybtex contains two different formatting engines:

  • The BibTeX engine uses BibTeX .bst styles.
  • The Python engine uses styles written in Python.

BibTeX engine

The BibTeX engine is fully compatible with BibTeX style files and is used by default.

How it works

When you type pybtex mydocument, the following things happen:

  1. Pybtex reads the file mydocument.aux in the current directory. This file is normally created by LaTeX and contains all sorts of auxiliary information collected during processing of the LaTeX document.

    Pybtex is interested in these three pieces of information:

    Bibliography style:

    First, Pybtex searches the .aux file for a \bibstyle command that specifies which formatting style will be used.

    For example, \bibstyle{unsrt} instructs Pybtex to use formatting style defined in the file unsrt.bst.

    Bibliography data:

    Next, Pybtex expects to find at least one \bibdata command in the .aux file that tells where to look for the bibliography data.

    For example, \bibdata{mydocument} means “use the bibliography data from mydocument.bib”.

    Citations:

    Finally, Pybtex needs to know which entries to put into the resulting bibliography.  Pybtex gets the list of citation keys from \citation commands in the .aux file.

    For example, \citation{graham1989concrete} means “include the entry with the key graham1989concrete into the resulting bibliograhy”.

    A wildcard citation \citation{*} tells Pybtex to format the bibliography for all entries from all data files specified by all \bibdata commands.

  2. Pybtex executes the style program in the .bst file specified by the \bibstyle command in the .aux file. As a result, a .bbl file containing the resulting formatted bibliography is created.

    A .bst style file is a program in a domain-specific stack-based language. A typical piece of the .bst code looks like this:

    FUNCTION {format.bvolume}
    { volume empty$
        { "" }
        { "volume" volume tie.or.space.connect
        series empty$
            'skip$
            { " of " * series emphasize * }
        if$
        "volume and number" number either.or.check
        }
    if$
    }

    The code in a .bst file contains the complete step-by-step instructions on how to create the formatted bibliography from the given bibliography data and citation keys.  For example, a READ command tells Pybtex to read the bibliography data from all files specified by \bibdata commands in the .aux file, an ITERATE command tells Pybtex to execute a piece of code for each citation key specified by \citation commands, and so on.  The built-in write$ function tells Pybtex to write the given string into the resulting .bbl file. Pybtex implements all these commands and built-in functions and simply executes the .bst program step by step.

    A complete reference of the .bst language can be found in the BibTeX hacking guide by Oren Patashnik.  It is available by running texdoc btxhak in most TeX distributions.

Python engine

The Python engine is enabled by running pybtex with  the -l python option.

Differences from the BibTeX engine

  • Formatting styles are written in Python instead of the .bst language.
  • Formatting styles are not tied to LaTeX and do not use hardcoded LaTeX markup. Instead of that they produce format-agnostic pybtex.richtext.Text objects that can be converted to any markup format (LaTeX, Markdown, HTML, etc.).
  • Name formatting, label formatting, and sorting styles are defined separately from the main style.

How it works

When you type pybtex -l python mydocument, this things happen:

  1. Pybtex reads the file mydocument.aux in the current directory and extracts the name of the the bibliography style, the list of bibliography data files and the list of citation keys. This step is exactly the same as with the BibTeX engine.
  2. Pybtex reads the biliography data from all data files specified in the .aux file into a single BibliographyData object.
  3. Then the formatting style is loaded. The formatting style is a Python class with a format_bibliography() method.  Pybtex passes the bibliography data (a BibliographyData object) and the list of citation keys to format_bibliography().
  4. The formatting style formats each of the requested bibliography entries in a style-specific way.

    When it comes to formatting names, a name formatting style is loaded and used. A name formatting style is also a Python class with a specific interface.  Similarly, a label formatting style is used to format entry labels, and a sorting style is used to sort the resulting style.  Each formatting style has a default name style, a default label style and a default sorting style. The defaults can be overridden with options passed to the main style class.

    Each formatted entry is put into a FormattedEntry object which is just a container for the formatted label, the formatted entry text (a pybtex.richtext.Text object) and the entry key.  The reason that the label, the key and the main text are stored separately is to give the output backend more flexibility when converting the FormattedEntry object to the actual markup. For example, the HTML backend may want to format the bibliography as a definition list, the LaTeX backend would use \bibitem[label]{key} text constructs, etc.

    Formatted entries are put into a FormattedBibliography object—it simply contains a list of FormattedEntry objects and some additional metadata.

  5. The resulting FormattedBibliography is passed to the output backend. The default backend is LaTeX. It can be changed with the pybtex --output-backend option. The output backend converts the formatted bibliography to the specific markup format and writes it to the output file.

Python API

The base interface

Both the Python engine and the BibTeX engine use the same interface defined in pybtex.Engine.

pybtex.Engine has a handful of methods but most of them are just convenience wrappers for Engine.format_from_files() that does the actual job.

class pybtex.Engine
make_bibliography(aux_filename, style=None, output_encoding=None, bib_format=None, **kwargs)

Read the given .aux file and produce a formatted bibliography using format_from_files().

Parameters

style – If not None, use this style instead of specified in the .aux file.

format_from_string(bib_string, *args, **kwargs)

Parse the bigliography data from the given string and produce a formated bibliography using format_from_files().

This is a convenience method that calls format_from_strings() with a single string.

format_from_strings(bib_strings, *args, **kwargs)

Parse the bigliography data from the given strings and produce a formated bibliography.

This is a convenience method that wraps each string into a StringIO, then calls format_from_files().

format_from_file(filename, *args, **kwargs)

Read the bigliography data from the given file and produce a formated bibliography.

This is a convenience method that calls format_from_files() with a single file. All extra arguments are passed to format_from_files().

format_from_files(**kwargs)

Read the bigliography data from the given files and produce a formated bibliography.

This is an abstract method overridden by both pybtex.PybtexEngine and pybtex.bibtex.BibTeXEngine.

The BibTeXEngine class

The BibTeX engine lives in the pybtex.bibtex module. The public interface consists of the BibTeXEngine class and a couple of convenience functions.

class pybtex.bibtex.BibTeXEngine

The Python fomatting engine.

See pybtex.Engine for inherited methods.

format_from_files(bib_files_or_filenames, style, citations=['*'], bib_format=None, bib_encoding=None, output_encoding=None, bst_encoding=None, min_crossrefs=2, output_filename=None, add_output_suffix=False, **kwargs)

Read the bigliography data from the given files and produce a formated bibliography.

Parameters
  • bib_files_or_filenames – A list of file names or file objects.
  • style – The name of the formatting style.
  • citations – A list of citation keys.
  • bib_format – The name of the bibliography format. The default format is bibtex.
  • bib_encoding – Encoding of bibliography files.
  • output_encoding – Encoding that will be used by the output backend.
  • bst_encoding – Encoding of the .bst file.
  • min_crossrefs – Include cross-referenced entries after this many crossrefs. See BibTeX manual for details.
  • output_filename – If None, the result will be returned as a string. Else, the result will be written to the specified file.
  • add_output_suffix – Append a .bbl suffix to the output file name.
pybtex.bibtex.make_bibliography(*args, **kwargs)

A convenience function that calls BibTeXEngine.make_bibliography().

pybtex.bibtex.format_from_string(*args, **kwargs)

A convenience function that calls BibTeXEngine.format_from_string().

pybtex.bibtex.format_from_strings(*args, **kwargs)

A convenience function that calls BibTeXEngine.format_from_strings().

pybtex.bibtex.format_from_file(*args, **kwargs)

A convenience function that calls BibTeXEngine.format_from_file().

pybtex.bibtex.format_from_files(*args, **kwargs)

A convenience function that calls BibTeXEngine.format_from_files().

The PybtexEngine class

The Python engine resides in the pybtex module and uses an interface similar to the BibTeX engine. There is the PybtexEngine class and some convenience functions.

class pybtex.PybtexEngine

The Python fomatting engine.

See pybtex.Engine for inherited methods.

format_from_files(bib_files_or_filenames, style, citations=['*'], bib_format=None, bib_encoding=None, output_backend=None, output_encoding=None, min_crossrefs=2, output_filename=None, add_output_suffix=False, **kwargs)

Read the bigliography data from the given files and produce a formated bibliography.

Parameters
  • bib_files_or_filenames – A list of file names or file objects.
  • style – The name of the formatting style.
  • citations – A list of citation keys.
  • bib_format – The name of the bibliography format. The default format is bibtex.
  • bib_encoding – Encoding of bibliography files.
  • output_backend – Which output backend to use. The default is latex.
  • output_encoding – Encoding that will be used by the output backend.
  • bst_encoding – Encoding of the .bst file.
  • min_crossrefs – Include cross-referenced entries after this many crossrefs. See BibTeX manual for details.
  • output_filename – If None, the result will be returned as a string. Else, the result will be written to the specified file.
  • add_output_suffix – Append default suffix to the output file name (.bbl for LaTeX, .html for HTML, etc.).
pybtex.make_bibliography(*args, **kwargs)

A convenience function that calls PybtexEngine.make_bibliography().

pybtex.format_from_string(*args, **kwargs)

A convenience function that calls PybtexEngine.format_from_string().

pybtex.format_from_strings(*args, **kwargs)

A convenience function that calls PybtexEngine.format_from_strings().

pybtex.format_from_file(*args, **kwargs)

A convenience function that calls PybtexEngine.format_from_file().

pybtex.format_from_files(*args, **kwargs)

A convenience function that calls PybtexEngine.format_from_files().

Designing styles

  • Rich text

    • Rich text classes
  • Style API
  • Template language

Rich text

Pybtex has a set of classes for working with formatted text and producing formatted output. A piece of formatted text in Pybtex is represented by a Text object. A Text is basically a container that holds a list of

  • plain text parts, represented by String objects,
  • formatted parts, represented by Tag and HRef objects.

The basic workflow is:

  1. Construct a Text object.
  2. Render it as LaTeX, HTML or other markup.

    >>> from pybtex.richtext import Text, Tag
    >>> text = Text('How to be ', Tag('em', 'a cat'), '.')
    >>> print(text.render_as('html'))
    How to be <em>a cat</em>.
    >>> print(text.render_as('latex'))
    How to be \emph{a cat}.

Rich text classes

There are several rich text classes in Pybtex:

  • Text
  • String
  • Tag
  • HRef
  • Protected

Text is the top level container that may contain String, Tag, and HRef objects. When a Text object is rendered into markup, it renders all of its child objects, then concatenates the result.

String is just a wrapper for a single Python string.

Tag and HRef are also containers that may contain other String, Tag, and HRef objects. This makes nested formatting possible.  For example, this stupidly formatted text:

Comprehensive TeX Archive Network is comprehensive.

is represented by this object tree:

>>> text = Text(
...     HRef('https://ctan.org/', Tag('em', 'Comprehensive'), ' TeX Archive Network'),
...     ' is ',
...     Tag('em', 'comprehensive'),
...     '.',
... )
>>> print(text.render_as('html'))
<a href="https://ctan.org/"><em>Comprehensive</em> TeX Archive Network</a> is <em>comprehensive</em>.

Protected represents a “protected” piece of text, something like {braced text} in BibTeX. It is not affected by case-changing operations, like Text.upper() or Text.lower(), and is not splittable by Text.split().

All rich text classes share the same API which is more or less similar to plain Python strings.

Like Python strings, rich text objects are supposed to be immutable. Methods like Text.append() or Text.upper() return a new Text object instead of modifying the data in place. Attempting to modify the contents of an existing Text object is not supported and may lead to weird results.

Here we document the methods of the Text class. The other classes have the same methods.

class pybtex.richtext.Text(*parts)

The Text class is the top level container that may contain String, Tag or HRef objects.

__init__(*parts)

Create a text object consisting of one or more parts.

Empty parts are ignored:

>>> Text() == Text('') == Text('', '', '')
True
>>> Text('Word', '') == Text('Word')
True

Text() objects are unpacked and their children are included directly:

>>> Text(Text('Multi', ' '), Tag('em', 'part'), Text(' ', Text('text!')))
Text('Multi ', Tag('em', 'part'), ' text!')
>>> Tag('strong', Text('Multi', ' '), Tag('em', 'part'), Text(' ', 'text!'))
Tag('strong', 'Multi ', Tag('em', 'part'), ' text!')

Similar objects are merged together:

>>> Text('Multi', Tag('em', 'part'), Text(Tag('em', ' ', 'text!')))
Text('Multi', Tag('em', 'part text!'))
>>> Text('Please ', HRef('/', 'click'), HRef('/', ' here'), '.')
Text('Please ', HRef('/', 'click here'), '.')
__eq__(other)

Rich text objects support equality comparison:

>>> Text('Cat') == Text('cat')
False
>>> Text('Cat') == Text('Cat')
True
__len__()

len(text) returns the number of characters in the text, ignoring the markup:

>>> len(Text('Long cat'))
8
>>> len(Text(Tag('em', 'Long'), ' cat'))
8
>>> len(Text(HRef('http://example.com/', 'Long'), ' cat'))
8
__contains__(item)

value in text returns True if any part of the text contains the substring value:

>>> 'Long cat' in Text('Long cat!')
True

Substrings splitted across multiple text parts are not matched:

>>> 'Long cat' in Text(Tag('em', 'Long'), 'cat!')
False
__getitem__(key)

Slicing and extracting characters works like with regular strings, formatting is preserved.

>>> Text('Longcat is ', Tag('em', 'looooooong!'))[:15]
Text('Longcat is ', Tag('em', 'looo'))
>>> Text('Longcat is ', Tag('em', 'looooooong!'))[-1]
Text(Tag('em', '!'))
__add__(other)

Concatenate this Text with another Text or string.

>>> Text('Longcat is ') + Tag('em', 'long')
Text('Longcat is ', Tag('em', 'long'))
add_period(period='.')

Add a period to the end of text, if the last character is not “.”, “!” or “?”.

>>> text = Text("That's all, folks")
>>> print(six.text_type(text.add_period()))
That's all, folks.
>>> text = Text("That's all, folks!")
>>> print(six.text_type(text.add_period()))
That's all, folks!
append(text)

Append text to the end of this text.

For Tags, HRefs, etc. the appended text is placed inside the tag.

>>> text = Tag('strong', 'Chuck Norris')
>>> print((text +  ' wins!').render_as('html'))
<strong>Chuck Norris</strong> wins!
>>> print(text.append(' wins!').render_as('html'))
<strong>Chuck Norris wins!</strong>
capfirst()

Capitalize the first letter of the text.

>>> Text(Tag('em', 'long Cat')).capfirst()
Text(Tag('em', 'Long Cat'))
capitalize()

Capitalize the first letter of the text and lowercase the rest.

>>> Text(Tag('em', 'LONG CAT')).capitalize()
Text(Tag('em', 'Long cat'))
endswith(suffix)

Return True if the text ends with the given suffix.

>>> Text('Longcat!').endswith('cat!')
True

Suffixes split across multiple parts are not matched:

>>> Text('Long', Tag('em', 'cat'), '!').endswith('cat!')
False
isalpha()

Return True if all characters in the string are alphabetic and there is at least one character, False otherwise.

join(parts)

Join a list using this text (like string.join)

>>> letters = ['a', 'b', 'c']
>>> print(six.text_type(String('-').join(letters)))
a-b-c
>>> print(six.text_type(String('-').join(iter(letters))))
a-b-c
lower()

Convert rich text to lowercase.

>>> Text(Tag('em', 'Long cat')).lower()
Text(Tag('em', 'long cat'))
render(backend)

Render this Text into markup.

Parameters

backend – The formatting backend (an instance of pybtex.backends.BaseBackend).

render_as(backend_name)

Render this Text into markup. This is a wrapper method that loads a formatting backend plugin and calls Text.render().

>>> text = Text('Longcat is ', Tag('em', 'looooooong'), '!')
>>> print(text.render_as('html'))
Longcat is <em>looooooong</em>!
>>> print(text.render_as('latex'))
Longcat is \emph{looooooong}!
>>> print(text.render_as('text'))
Longcat is looooooong!
Parameters

backend_name – The name of the output backend (like "latex" or "html").

split(sep=None, keep_empty_parts=None)
>>> Text('a + b').split()
[Text('a'), Text('+'), Text('b')]
>>> Text('a, b').split(', ')
[Text('a'), Text('b')]
startswith(prefix)

Return True if the text starts with the given prefix.

>>> Text('Longcat!').startswith('Longcat')
True

Prefixes split across multiple parts are not matched:

>>> Text(Tag('em', 'Long'), 'cat!').startswith('Longcat')
False
upper()

Convert rich text to uppsercase.

>>> Text(Tag('em', 'Long cat')).upper()
Text(Tag('em', 'LONG CAT'))
class pybtex.richtext.String(*parts)

A String is a wrapper for a plain Python string.

>>> from pybtex.richtext import String
>>> print(String('Crime & Punishment').render_as('text'))
Crime & Punishment
>>> print(String('Crime & Punishment').render_as('html'))
Crime &amp; Punishment

String supports the same methods as Text.

class pybtex.richtext.Tag(name, *args)

A Tag represents something like an HTML tag or a LaTeX formatting command:

>>> from pybtex.richtext import Tag
>>> tag = Tag('em', 'The TeXbook')
>>> print(tag.render_as('html'))
<em>The TeXbook</em>
>>> print(tag.render_as('latex'))
\emph{The TeXbook}

Tag supports the same methods as Text.

class pybtex.richtext.HRef(url, *args)

A HRef represends a hyperlink:

>>> from pybtex.richtext import Tag
>>> href = HRef('http://ctan.org/', 'CTAN')
>>> print(href.render_as('html'))
<a href="http://ctan.org/">CTAN</a>
>>> print(href.render_as('latex'))
\href{http://ctan.org/}{CTAN}
>>> href = HRef(String('http://ctan.org/'), String('http://ctan.org/'))
>>> print(href.render_as('latex'))
\url{http://ctan.org/}

HRef supports the same methods as Text.

class pybtex.richtext.Protected(*args)

A Protected represents a “protected” piece of text.

  • Protected.lower(), Protected.upper(), Protected.capitalize(), and Protected.capitalize() are no-ops and just return the Protected object itself.
  • Protected.split() never splits the text. It always returns a one-element list containing the Protected object itself.
  • In LaTeX output, Protected is {surrounded by braces}.  HTML and plain text backends just output the text as-is.
>>> from pybtex.richtext import Protected
>>> text = Protected('The CTAN archive')
>>> text.lower()
Protected('The CTAN archive')
>>> text.split()
[Protected('The CTAN archive')]
>>> print(text.render_as('latex'))
{The CTAN archive}
>>> print(text.render_as('html'))
<span class="bibtex-protected">The CTAN archive</span>

New in version 0.20.

class pybtex.richtext.Symbol(name)

A special symbol. This class is rarely used and may be removed in future versions.

Examples of special symbols are non-breaking spaces and dashes.

Symbol supports the same methods as Text.

Style API

A formatting style in Pybtex is a class inherited from pybtex.style.formatting.BaseStyle.

class pybtex.style.formatting.BaseStyle(label_style=None, name_style=None, sorting_style=None, abbreviate_names=False, min_crossrefs=2, **kwargs)

The base class for pythonic formatting styles.

format_bibliography(bib_data, citations=None)

Format bibliography entries with the given keys and return a FormattedBibliography object.

Parameters
  • bib_data – A pybtex.database.BibliographyData object.
  • citations – A list of citation keys.

Pybtex loads the style class as a plugin, instantiates it with proper parameters and calls the format_bibliography() method that does the actual formatting job. The default implementation of format_bibliography() calls a format_<type>() method for each bibliography entry, where <type> is the entry type, in lowercase. For example, to format an entry of type book, the format_book() method is called. The method must return a Text object. Style classes are supposed to implement format_<type>() methods for all entry types they support. If a formatting method is not found for some entry, Pybtex complains about unsupported entry type.

An example minimalistic style:

from pybtex.style.formatting import BaseStyle
from pybtex.richtext import Text, Tag

class MyStyle(BaseStyle):
    def format_article(self, entry):
        return Text('Article ', Tag('em', entry.fields['title']))

Template language

Manually creating Text objects may be tedious. Pybtex has a small template language to simplify common formatting tasks, like joining words with spaces, adding commas and periods, or handling missing fields.

The template language is is not very documented for now, so you should look at the code in the pybtex.style.template module and the existing styles.

An example formatting style using template language:

from pybtex.style.formatting import BaseStyle, toplevel
from pybtex.style.template import field, join, optional

class MyStyle(BaseStyle):
    def format_article(self, entry):
        if entry.fields['volume']:
            volume_and_pages = join [field('volume'), optional [':', pages]]
        else:
            volume_and_pages = words ['pages', optional [pages]]
        template = toplevel [
            self.format_names('author'),
            sentence [field('title')],
            sentence [
                tag('emph') [field('journal')], volume_and_pages, date],
        ]
        return template.format_data(entry)

Extending Pybtex with plugins

  • Entry points

    • pybtex.database.input
    • pybtex.database.output
    • pybtex.backends
    • pybtex.style.formatting
    • pybtex.style.labels
    • pybtex.style.names
    • pybtex.style.sorting
  • Registering plugins
  • Example plugins

Pybtex uses plugins for bibliography data formats, output markup formats and bibliography formatting styles. This allows to add new formats or styles to Pybtex withoud modifying Pybtex itself.

The plugins are based on Setuptools’ entry points.

Entry points

Here is the list of entry points supported by Pybtex.

pybtex.database.input

This entry point is used for bibliography parsers. Must point to a subclass of pybtex.database.input.BaseParser.

There is also an additional entry point called pybtex.database.output.suffixes. It is used for registering bibliography formats for specific file suffixes (like BibTeX for .bib files).

For example, a JSON input plugin could use these entry points:

[pybtex.database.input]
json = pybtexjson:JSONParser

[pybtex.database.input.suffixes]
.json = pybtexjson:JSONParser

pybtex.database.output

This entry poing is used for bibliography writers. Must point to a subclass of pybtex.database.output.BaseWriter.

There is also an additional entry point called pybtex.database.output.suffixes. It is used for registering default plugins for specific file suffixes in the same way as pybtex.database.input.suffixes described above.

pybtex.backends

This entry point is for adding new output markup formats for Pythonic bibliography styles. The built-in plugins are latex, html, markdown, and plaintext. Must point to a pybtex.backends.BaseBackend subclass.

pybtex.style.formatting

This is the entry point for Pythonic bibliography styles. Must point to a pybtex.style.formatting.BaseStyle subclass.

pybtex.style.labels

Label styles for Pythonic bibliography styles.

pybtex.style.names

Name styles for Pythonic bibliography styles.

pybtex.style.sorting

Sorting styles for Pythonic bibliography styles.

Registering plugins

See Setuptools’ documentation.

Example plugins

An example project directory with two simple plugins and a setup.py file can be found in the examples/sample_plugins subdirectory.

Version History

Version 0.24.0

(released on January 17, 2021)

This is the last version that supports Python 2. The next version will require Python 3.6 or above.

  • Added support for sup and sub tags to LaTeX and Markdown backends.
  • Added support for @online entries and the urldate field.
  • Restored compatibility with Python 2.
  • Fixed tests on Windows.
  • Fixed bugs in the example plugin.
  • Fixed bad get_default_encoding() call.

Thanks to Matthias Troffaes for his contributions!

Version 0.23.0

(released on October 12, 2020)

  • Reimplemented OrderedCaseInsensitiveDict using collections.OrderedDict (so it has a __delitem__).
  • unsrt.py now supports type when formatting phdthesis.
  • Added from_string() to pybtex.database.BibliographyData.
  • Added from_string() and to_string() to pybtex.database.Entry.
  • Added indentation to __repr__ in pybtex.database.BibliographyData and pybtex.database.Entry.
  • Preserve order in pybtex.utils.OrderedCaseInsensitiveDict.__repr__().
  • Fixed entries with duplicate keys being removed during sorting.
  • Fixed handling of duplicate person fields
  • Use ElementTree instead of the deprecated cElementTree.
  • Import base classes from collections.abc instead of collections.
  • Use __iter__ instead of deprecated Element.getchildren().

Thanks to David Chiang, Jerry James, Jannik Schürg, Nathaniel Starkman, and Matthias Troffaes for their fixes and improvements!

Version 0.22.2

(released on January 17, 2019)

  • Fixed compatibility with Python 2 and older versions of Python 3.

Version 0.22.1

(released on January 16, 2019)

  • Fixed non-working --backend option with pybtex -l python.

Version 0.22.0

(released on November 18, 2018)

  • Fixed handling of duplicate fields in .bib biles. Thanks, Jannik Schürg!
  • BibTeX parser is now up to 10% faster on some files. Thanks, Fabrice Benhamouda!
  • Fixed parsing of names with \~ characters.
  • Fixed formatting proceedings without an editor field in unsrt.py.
  • In case of too many braces in a BibTeX string, PybtexSyntaxError is now raised instead of RecursionError.
  • Dropped 2to3, made the code compatible with both Python 2 and 3 with Six.
  • Moved tests outside of the pybtex package.
  • Fixed searching in docs with recent versions of Sphinx.
  • API: renamed bibtex.BibTeXEntryIterator to bibtex.LowLevelParser for clarity.
  • API: removed confusing usage of Person.text in tempate.names.
  • API: Entry.fields does not automagically look for cross-referenced entries anymore.

Version 0.21

(released on January 20, 2017)

  • BibTeX writer now uses latexcodec to encode characters that are not directly supported by the output encoding. Thanks, Hong Xu!
  • HTML backend: {braced stings} are now wrapped with <span class="bibtex-protected"> to enable custom CSS styling.
  • unsrt.py: DOI, PubMed and Arxiv links now use HTTPS instead of HTTP.
  • unsrt.py: URLs with percent characters are now formatted correctly.
  • unsrt.py: short page / volume / chapter numbers are now joined with a non-breaking space, like in BibTeX.
  • unsrt.py: inbook now uses the editor field if the author field is missing, like in BibTeX.
  • unsrt.py: the words “volume” and “pages” in the beginning of the sentence are now capitalized, like in BibTeX.
  • unsrt.py: removed unnecessary period between the book title and the comma in inbook.

Version 0.20.1

(released on March 17, 2016)

  • LaTeX backend: fix encoding tilde ("~") characters with newer versions of latexcodec.
  • Fix splitting names with escaped space ("\ ") characters.

Version 0.20

(released on March 10, 2016)

  • Yaml reader and writer now preserve the order of bibliography entries.
  • Improved URL formatting in pythonic styles.
  • Built-in pythonic styles now support the ISBN field.
  • Pythonic styles now treat LaTeX braces correctly:

    • case conversion does not affect {braced substrings},
    • braces are stripped from non-LaTeX output: "{P}ython" becomes "Python".
  • Pythonic styles now use latexcodec to decode LaTeX markup. For example, "Schr\"odinger" is now correctly rendered as "Schrödinger" in HTML or plain text.

Thanks to Hong Xu for his contributions!

Version 0.19

(released on October 26, 2015)

  • Added Markdown output format (contributed by Jorrit Wronski).
  • Incorrectly formatted author and editor names now result in warnings instead of errors, unless --strict mode is enabled.
  • Fixed HTML escaping.
  • Fixed parsing nested .aux files.
  • Fixed splitting names separated by non-lowercase " and ".
  • Fixed line numbers in error messages when parsing strings with DOS/Windows line breaks.
  • Fixed compatibility with BibTeX when parsing certain weird “von” names.
  • Removed excessive trailing newline from .bib output.
  • Text wrapping now works exactly as in BibTeX.
  • Added new API for reading and writing bibliography data.
  • Pythonic styles: reworked and extended the rich text API.
  • Pythonic styles: added strong, i, b, tt tags, renamed the old emph tag to em.
  • Pythonic styles: the author_year_title style now returns "" instead of None (fixes unorderable types error in Python 3).
  • Ported the documentation to Sphinx.

Thanks to Jorrit Wronski and Matthias Troffaes for their fixes and improvements!

Version 0.18

(released on July 6, 2014)

  • Pybtex is now fully case-insensitive (like BibTeX). As a consequence, IEEEtran styles now work correctly.
  • Added --preserve-case option to pybtex-convert (default behavior is to converted all identifiers to lower case).
  • An error is reported if two citations have the same key but different case, like in BibTeX. (Example: ddt1999 and DDT1999).
  • Fixed parsing unused bibliography entries with strings containing @ characters.
  • entry.max$ constant is now set to 250, global.max$ is set to 20000, like in BibTeX.
  • Added --strict option to pybtex-convert and pybtex-format (turns warning into errors).
  • Strict mode is now enabled by default when using pybtex as a library (exceptions are raised on all errors instead of just printing warnings to stderr).

    Non-strict error handling is still enabled when using pybtex from the command line, for compatibility with BibTeX. Use --strict option if you don’t like this.

  • Added missing pybtex-format manpage.

Version 0.17

(released on March 10, 2014)

  • Added pybtex-format utility for formatting bibliography files as HTML, LaTeX, and other supported human-readable formats.
  • Added --strict command line option to pybtex (all warnings become errors).
  • Added alpha label style, and alpha and unsrtalpha formatting styles.
  • Added support for url, eprint, doi, and pubmed fields in unsrt style.
  • Names with hyphens are now abbreviated correctly (“Jean-Baptiste” becomes “J.-B.”).
  • width$ now uses cmr10 font metrics, like in BibTeX. Non-latin characters are also supported.
  • Pythonic style engine now supports @preamble commands.
  • Warning on missing fields are now more human-readable.
  • When writing BibTeX files, put entry key on the same line with entry type. Fixes warnings in Jabref.
  • When using multiple .bib files, macros defined in earlier files are available in subsequent ones (like in BibTeX).
  • Fixed parsing .bst files with lines consisting of a single % character.
  • Fixed sorting entries without author in author_year_title sorting style.
  • Fixed broken CaseInsensitiveDict.get().
  • CaseInsensitiveDict is now pickleable.
  • Added support for registering plugins at runtime with pybtex.plugin.register_plugin() - useful for using pybtex as a library.

Many thanks to Matthias C. M. Troffaes for his numerous fixes and improvements!

Version 0.16

(released on March 17, 2012)

  • BibTeX .bib and .bst parsers were completely rewritten. They are now much faster and more BibTeX-compatible.
  • Syntax errors and undefined strings in .bib files now result in warnings instead of errors, like in BibTeX.
  • Unused entries in .bib files are now skipped, like in BibTeX.
  • The case of entry keys is now preserved (in previous versions they were converted to lowercase).
  • Pythonic style engine now supports sorting.
  • Pythonic style engine: fixed nested optional() blocks.
  • Fixed parsing of some names with a Last part but no von part.
  • Fixed processing of brace-level-one “special characters” in purify$ BibTeX built-in function.
  • Added proper error messages on encoding errors in .bib files.
  • The default encoding is now UTF-8 on all platforms.
  • pybtex-convert now preserves the order of entries in BibTeX and BibTeXML files.

The following changes were contributed by Matthias C. M. Troffaes:

  • Fixed first_of behavior when non-empty child is followed by a child that has a missing field.
  • Fixed crossref lookups when key is not lower case.
  • Completed unsrt and plain python styles: they now contain all entry types.
  • Added doctree backend for rendering into a tree of docutils nodes.
  • Added support for non-string backends.

Version 0.15

(released on February 1, 2011)

  • Changed license from GPL-3 to MIT.
  • Added support for setuptools plugins.
  • BibTeX parser: fixed whitespace normalization in concatenated strings.
  • BibTeX parser: when parsing multiple BibTeX files, macros defined in earlier files are now available to all subsequent files, like in BibTeX.
  • BibTeX .bst interpreter now prints warnings on missing entries, like BibTeX, instead of raising a KeyError.
  • call.type$ BibTeX built-in function now uses default.entry for unknown entry types, like in BibTeX.
  • substring$ now accepts start=0 and returns an empty string.
  • change.case$: fixed incorrect formatting of strings starting with special characters with "t" format.
  • Fixed abbreviation of names starting with special characters or non-alphabetic characters.
  • Fixed incorrect entry order and duplicated entries with \nocite{*}.
  • Added more detailed error messages for already defined variables in .bst files.

Version 0.14.1

(released on September 30, 2010)

  • Added missing custom_fixers directory to the tarball — needed only for converting the sources to Python 3.

Version 0.14

(released on September 20, 2010)

  • BibTeX writer: fixed quoting " (double quote) characters.
  • BibTeX parser now produces human-readable error messages on unread macros.
  • Added error messages on missing data in .aux files.
  • Improved performance on very long name lists.
  • Added support for Python 3.

Version 0.13.2

(released on February 26, 2010)

  • BibTeX parser: fixed a bug with parsing strings containing braces, like "Error in {DNA}".

Version 0.13.1

(released on February 18, 2010)

  • Fixed ImportError: No module named kpathsea errors. One of the source files was missing from pybtex-0.13.tar.bz2 for some strange reason. Sorry about that. ;)

Version 0.13

(released on February 14, 2010)

  • Implemented --min-crossrefs option.
  • All command line options of the original BibTeX are not supported.
  • Pybtex now respects BSTINPUTS, BIBINPUTS and TEXMFOUTPUT environment variables.
  • BibTeX bibliography parser now strips excessive whitespace from fields, like BibTeX does.

Version 0.12

(released on November 21, 2009)

  • Pybtex now works correctly with \input{filename} in LaTeX files.
  • Added a proper change.case$ BibTeX function instead of a stub.
  • Added -e/--encoding command line option.
  • Fixed non-working --bibtex-encoding option.
  • Added proper error messages on missing plugins, file IO errors, some BibTeX interpreter errors, etc.
  • Fallback to backslash-encoding when printing messages to the console - to make them printable regardless of the locale.

Version 0.11

(released on September 7, 2009)

  • Made text.lentgh$ and text.prefix$ BibTeX built-in functions treat braces and TeX special characters properly (like the original BibTeX functions do).
  • Changed purify$ to replace ties and hyphens by spaces.
  • Fixed a bug in substring$ with negative start values.
  • Fixed .bst file grammar to allow underscores in identifiers.
  • BibTeX name parser: ties are now treated as whitespace when splitting name parts.
  • Implemented BibTeX-like text wrapping. The resulting .bbl output should now be byte-for-byte identical to that of BibTeX in most cases.

Version 0.10

(released on August 24, 2009)

  • Added support for multiple bibliography databases.
  • Pythonic bibliography formatter: added helper functions to simplify writing BibTeX-like name formatting styles in Python. Added a tool for automatic conversion of BibTeX {ll}{, ff}-like patterns into Python.
  • BibTeX parser: added missing characters to the caracter set of the valid identifiers.
  • BibTeX parser: a comma is now allowed between the last field and the closing brace.
  • BibTeX name parser: when splitting name parts into words, whitespace at brace level > 0 is now ignored.
  • BibTeX name parser: fixed parsing of single-word lowercase names and complex von names, like in “Andrea de Leeuw van Weenen”.
  • Fixed broken --label-style and --name-style options.
  • Added (autogenerated) manpages.
  • Added this changelog.

Version 0.9

(released on August 17, 2009)

  • Implemented \citation{*}.
  • Implemented crossrefs.
  • BibTeX .bib parser now supports newlines inside strings.
  • Fixed: .bib filename from .aux file was ignored.
  • Fixed incorrect argument passing to codecs.open().
  • Fixed incorrect whitespace handling in the name parsing code.

Version 20090402

(released on February 04, 2009)

  • Fixed yet more encoding-related bugs.
  • Cleaned up some old nasty code, updated the documentation, added more tests.

Version 20080918

(released on September 18, 2008)

  • Added HTML backend. The pythonic bibliography formatter can now produce LaTeX, HTML, and plaintext.
  • BibTeXML writer now indents the resulting XML.
  • Removed the dependency on external elementtree.
  • Improved the interface of the pybtex-convert script. It is just convert foo.bib foo.yaml now.
  • Fixed several bugs in the BibTeX interpreter.
  • Fixed several encoding-related bugs.

Version 20070513

(released on May 13, 2007)

  • Added an interpreter for the BibTeX stack language. Pybtex now supports BibTeX style files.
  • Added a Yaml bibliography format (both input and output).
  • Improved processing of names with {braces}.
  • Added support for @preamble to both BibTeX parser and writer.
  • Introduced an experimental pythonic template language to make bibliography formatting easier with a more functional-oriented approach.
  • Added support for incollection entries to the experimentl pythonic bibliography style.
  • cElementTree is now used for BibTeXML parsing, if present.
  • Added some documentation files (finally).

Version 20060416

(released on April 16, 2006)

  • Added BibTeX and BibTeXML formatters for bibliography databases. Added a database conversion tool.
  • Improved name splitting in the BibTeX parser.
  • Locale encoding is now used by default.
  • Added richtext.Check class to simplify formatting of optional bibliography fields.
  • Added support for booklet and inbook entry types to the experimentl pythonic bibliography style.

Version 20060402

(released on April 2, 2006)

  • Added initial Unicode support and input/output encodings.
  • Introduced output backends to make bibliography styles markup-independent. Added LaTeX and Plaintext backends.
  • Improved BibTeXML parser, add support for pre-parsed names (<bibtex:first>, <bibtex:middle> and so on).
  • Added default macros for month names to the BibTeX parser.
  • Added an experimental richtext.Phrase (former Pack class (former Packer class)) class to make creating sentences and delimited lists easier.
  • Added experimental support for pluggable name and label styles to the pythonic bibliogrphy formatter.
  • Made Pybtex work on Windows by renaming aux.py to auxfile.py. Duh.

Version 0.1

(released on March 4, 2006)

Initial release. This version already has a basic BibTeX .bib parser, BibTeXML parser and a proof-of-concept pythonic bibliography formatter.

Author

Andrey Golovizin

Referenced By

The man pages pybtex-convert(1) and pybtex-format(1) are aliases of pybtex(1).

Jan 26, 2024 0.24.0 Pybtex User’s Guide