### Install Pybtex with pip
Source: https://github.com/pybtex/pybtex/blob/master/docs/site/index.md
Use this command to install the Pybtex package using pip. This is the recommended method for most users.
```bash
pip install pybtex
```
--------------------------------
### BibTeX Data Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
An example of bibliography data in BibTeX format.
```bibtex
@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"
}
```
--------------------------------
### YAML Bibliography Entry Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/formats.rst
An experimental YAML-based bibliography format for Pybtex, largely a translation of BibTeXML.
```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
```
--------------------------------
### Basic Rich Text Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/styles.rst
Demonstrates creating and rendering a simple Text object with embedded tags in HTML and LaTeX formats.
```python
>>> from pybtex.richtext import Text, Tag
>>> text = Text('How to be ', Tag('em', 'a cat'), '.')
>>> print(text.render_as('html'))
How to be a cat.
>>> print(text.render_as('latex'))
How to be \emph{a cat}.
```
--------------------------------
### Registering JSON Input Plugin
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/plugins.rst
This example shows how to register a JSON input plugin using Pybtex's entry points. It defines the parser for the 'json' format and associates it with a specific file suffix '.json'.
```ini
[pybtex.database.input]
json = pybtexjson:JSONParser
[pybtex.database.input.suffixes]
.json = pybtexjson:JSONParser
```
--------------------------------
### BibTeX Style (.bst) Function Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
A snippet of a BibTeX style file (.bst) demonstrating a function definition for formatting volume information.
```bst-pybtex
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$
}
```
--------------------------------
### BibTeX Entry Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/formats.rst
A standard BibTeX entry for a book. This is the default format used by Pybtex.
```bibtex
@BOOK{strunk-and-white,
author = "Strunk, Jr., William and E. B. White",
title = "The Elements of Style",
publisher = "Macmillan",
edition = "Third",
year = 1979
}
```
--------------------------------
### BibTeXML Entry Example
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/formats.rst
The BibTeX entry translated into BibTeXML format, which is an XML representation.
```xml
William
Strunk
Jr.
E.
B.
White
The Elements of Style
Macmillan
Third
1979
```
--------------------------------
### Minimalistic Custom Style
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/styles.rst
An example of a minimalistic Pybtex style class that formats article entries by displaying the article title in italics.
```python
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']))
```
--------------------------------
### Article Formatting with Pybtex Templates
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/styles.rst
Example of a custom Pybtex style for formatting articles using the template language. It demonstrates handling volume, pages, title, journal, and date fields.
```python
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)
```
--------------------------------
### Converting Bibliography Databases
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Use the pybtex-convert utility to convert bibliography databases between supported formats. This example converts a BibTeX file to YAML.
```shell
$ pybtex-convert book.bib book.yaml
```
--------------------------------
### Specifying Bibliography Format with --format
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Instruct Pybtex to use a different bibliography format than the default BibTeX. This example tells Pybtex to look for a YAML-formatted file.
```shell
$ pybtex --format yaml book
```
--------------------------------
### Customizing Bibliography Formatting Style
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Change the formatting style used by pybtex-format with the --style option. This example uses the 'alpha' style.
```shell
$ pybtex-format --style alpha book.bib book.txt
```
--------------------------------
### Running Pybtex Workflow
Source: https://github.com/pybtex/pybtex/blob/master/README.rst
This snippet shows the typical command-line workflow for processing a LaTeX document with Pybtex.
```bash
latex foo.tex
pybtex foo.aux
latex foo.tex
latex foo.tex
```
--------------------------------
### Create BibliographyData and Write to String
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/parsing.rst
Shows how to create a `BibliographyData` object programmatically and then format it into a BibTeX string using `to_string`.
```python
>>> 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"
}
```
--------------------------------
### Compiling a Bibliography with Pybtex
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Use pybtex in the same way as the original bibtex command. This sequence shows how to compile a bibliography for a LaTeX file named book.tex.
```shell
$ latex book
$ pybtex book
$ latex book
$ latex book # to get cross-references right
```
--------------------------------
### Pretty-Printing Bibliography Databases
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Use the pybtex-format utility to convert a bibliography database to a human-readable format like TXT or HTML. The default style is 'unsrt'.
```shell
$ pybtex-format book.bib book.txt
$ pybtex-format book.bib book.html
```
--------------------------------
### Using Pythonic Bibliography Styles
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
Switch the style language from BibTeX to Python using the --style-language option. This allows for styles written in Python.
```shell
$ pybtex --style-language python book
```
--------------------------------
### Nested Rich Text with HRef and Tag
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/styles.rst
Illustrates creating a nested Text object with HRef and Tag elements, rendering it as HTML.
```python
>>> text = Text(
... HRef('https://ctan.org/', Tag('em', 'Comprehensive'), ' TeX Archive Network'),
... ' is ',
... Tag('em', 'comprehensive'),
... '.',
... )
>>> print(text.render_as('html'))
Comprehensive TeX Archive Network is comprehensive.
```
--------------------------------
### Clone Pybtex Development Sources
Source: https://github.com/pybtex/pybtex/blob/master/docs/site/index.md
Clone the Pybtex repository from Codeberg to access the development sources. This is useful for developers who want to contribute or use the latest code.
```bash
git clone https://codeberg.org/pybtex/pybtex
```
--------------------------------
### Changing Output Backend with Pythonic Styles
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/cmdline.rst
When using Pythonic styles, change the output backend from the default LaTeX to HTML or plaintext using the --output-backend option.
```shell
$ pybtex --style-language python --output-backend html book
$ pybtex --style-language python --output-backend plaintext book
```
--------------------------------
### pybtex convenience functions
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
Convenience functions for the Python engine, simplifying common bibliography formatting tasks.
```APIDOC
## pybtex convenience functions
### Description
Convenience functions for the Python engine, simplifying common bibliography formatting tasks.
### Functions
- **make_bibliography**: Creates a bibliography.
- **format_from_string**: Formats bibliography from a string.
- **format_from_strings**: Formats bibliography from multiple strings.
- **format_from_file**: Formats bibliography from a file.
- **format_from_files**: Formats bibliography from multiple files.
```
--------------------------------
### pybtex.bibtex convenience functions
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
Convenience functions for the BibTeX engine, simplifying common bibliography formatting tasks.
```APIDOC
## pybtex.bibtex convenience functions
### Description
Convenience functions for the BibTeX engine, simplifying common bibliography formatting tasks.
### Functions
- **make_bibliography**: Creates a bibliography.
- **format_from_string**: Formats bibliography from a string.
- **format_from_strings**: Formats bibliography from multiple strings.
- **format_from_file**: Formats bibliography from a file.
- **format_from_files**: Formats bibliography from multiple files.
```
--------------------------------
### Parse BibTeX File and Access Entry Data
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/parsing.rst
Demonstrates parsing a BibTeX file using `parse_file` and accessing specific fields and authors from an entry.
```python
>>> 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
```
--------------------------------
### pybtex.Engine
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
The base interface for Pybtex, providing core methods for bibliography processing. Most methods are wrappers for format_from_files.
```APIDOC
## pybtex.Engine
### Description
The base interface for Pybtex, providing core methods for bibliography processing. Most methods are wrappers for format_from_files.
### Methods
(Members of pybtex.Engine are documented via autoclass directive in the source.)
```
--------------------------------
### pybtex.bibtex.BibTeXEngine
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
The BibTeX engine class, providing an interface for processing bibliographies using BibTeX-compatible methods.
```APIDOC
## pybtex.bibtex.BibTeXEngine
### Description
The BibTeX engine class, providing an interface for processing bibliographies using BibTeX-compatible methods.
### Methods
(Members of pybtex.bibtex.BibTeXEngine are documented via autoclass directive in the source.)
```
--------------------------------
### Bibliography Data Classes
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/parsing.rst
Details on the core classes used to represent bibliography data in Pybtex.
```APIDOC
## Bibliography Data Classes
Pybtex utilizes the following classes to manage bibliography information:
- **`:py:class:`.BibliographyData`**: Represents a collection of bibliography entries and metadata.
- **Members**: `entries`, `fields`, `persons`, `add_entry`, `remove_entry`, `add_person`, `remove_person`, `add_field`, `remove_field`, `get_entry`, `get_persons`, `get_fields`.
- **`:py:class:`.Entry`**: Represents a single bibliography item (e.g., book, article).
- **Attributes**: `key`, `type`, `fields`, `persons`.
- **Members**: `add_person`, `remove_person`, `add_field`, `remove_field`, `get_person`, `get_field`.
- **`:py:class:`.Person`**: Represents a person associated with a bibliography entry (author, editor).
- **Members**: `first_names`, `middle_names`, `last_names`, `lineage_names`, `to_string`.
```
--------------------------------
### pybtex.PybtexEngine
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/formatting.rst
The Python engine class for Pybtex, offering an interface similar to the BibTeX engine for Python-based bibliography processing.
```APIDOC
## pybtex.PybtexEngine
### Description
The Python engine class for Pybtex, offering an interface similar to the BibTeX engine for Python-based bibliography processing.
### Methods
(Members of pybtex.PybtexEngine are documented via autoclass directive in the source.)
```
--------------------------------
### Writing Bibliography Data
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/parsing.rst
Methods for formatting BibliographyData objects into strings, byte strings, or writing to files.
```APIDOC
## Writing Bibliography Data
The :py:class:`.BibliographyData` class offers methods to serialize bibliography data.
### Methods
- **`.BibliographyData.to_string(format)`**: Formats the bibliography data into a string in the specified format (e.g., 'bibtex').
- **`.BibliographyData.to_bytes(format)`**: Formats the bibliography data into a byte string.
- **`.BibliographyData.to_file(file, format)`**: Writes the bibliography data to a file.
### Example
```python
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'))
```
```
--------------------------------
### Parsing Bibliography Data
Source: https://github.com/pybtex/pybtex/blob/master/docs/source/api/parsing.rst
Functions for reading bibliography data from various sources into a BibliographyData object.
```APIDOC
## Reading Bibliography Data
Pybtex provides high-level functions for parsing bibliography databases from strings, bytes, or files.
### Functions
- **`pybtex.database.parse_string(source)`**: Parses bibliography data from a string.
- **`pybtex.database.parse_bytes(source)`**: Parses bibliography data from a byte string.
- **`pybtex.database.parse_file(source)`**: Parses bibliography data from a file.
Each function returns a :py:class:`.BibliographyData` object.
### Example
```python
from pybtex.database import parse_file
bib_data = parse_file('../examples/tugboat/tugboat.bib')
print(bib_data.entries['Knuth:TB8-1-14'].fields['title'])
for author in bib_data.entries['Knuth:TB8-1-14'].persons['author']:
print(unicode(author))
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.