pybtex-docutils

1.0.3 · active · verified Sun Apr 12

pybtex-docutils is a Docutils backend for the Pybtex bibliography processor. It enables the insertion of BibTeX citations into documentation generated by Docutils, particularly for reStructuredText. The current version is 1.0.3, and while releases are not on a strict schedule, the library is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `simplebibliography` directive with a pure Docutils workflow. It generates a sample BibTeX file (`refs.bib`) and an reStructuredText file (`example.rst`), then uses a Python script to process `example.rst` into `example.html`, including the bibliography. This setup requires manually registering the `SimpleBibliography` directive with Docutils.

import io
from docutils.parsers.rst import directives, Directive
from docutils.core import publish_cmdline, default_description
from pybtex_docutils import SimpleBibliography

# Create a dummy .bib file
with open('refs.bib', 'w') as f:
    f.write('''
@Book{Nelson1987,
    author    = {Edward Nelson},
    title     = {Radically Elementary Probability Theory},
    publisher = {Princeton University Press},
    year      = {1987}
}
''')

# Create a dummy .rst file
with open('example.rst', 'w') as f:
    f.write('''
.. highlight:: python

Example Document
================

See {Nelson1987}_ for an introduction to non-standard analysis.

.. simplebibliography:: refs.bib
''')

# Register the directive and publish the document
description = ('Like rst2html5.py, but with .. simplebibliography support' + default_description)
directives.register_directive("simplebibliography", SimpleBibliography)
publish_cmdline(writer_name='html5', description=description, argv=['example.rst', 'example.html'])

print("Generated example.html with bibliography.")

view raw JSON →