Expand description
§bibtex-parser
Fast BibTeX parsing with a Rust-first Library API.
bibtex-parser is built for applications that need both throughput and a
practical user-facing API: strict parsing by default, explicit tolerant
recovery when a corpus is messy, string and month expansion, comments and
preambles, validation, query/edit helpers, and configurable writing.
§Features
- Borrowed values where possible for low-allocation parsing.
- String variables, concatenation, and standard month constants.
- Entries, strings, preambles, comments, and tolerant failures in source order.
- Opt-in source-span capture.
- DOI normalization, duplicate detection, validation, sorting, and field normalization.
- Configurable writer for formatting and file output.
- Optional
parallelfeature for parsing multiple files concurrently. - Optional
latex_to_unicodefeature for LaTeX accent conversion helpers.
§Parse
use bibtex_parser::Library;
let input = r#"
@string{venue = "VLDB"}
@article{paper,
author = "Jane Doe and John Smith",
title = "Fast BibTeX",
journal = venue,
year = 2026
}
"#;
let library = Library::parse(input)?;
let entry = library.find_by_key("paper").unwrap();
assert_eq!(entry.get("journal"), Some("VLDB"));
assert_eq!(entry.year(), Some("2026".to_string()));
assert_eq!(entry.authors().len(), 2);§Tolerant Recovery
use bibtex_parser::{Block, Library};
let library = Library::parser()
.tolerant()
.capture_source()
.parse(r#"
@article{ok, title = "Good"}
@article{bad, title = "Missing close"
@book{recovered, title = "Recovered"}
"#)?;
assert_eq!(library.entries().len(), 2);
assert_eq!(library.failed_blocks().len(), 1);
let has_failure_span = library.blocks().iter().any(|block| {
matches!(block, Block::Failed(failed) if failed.source.is_some())
});
assert!(has_failure_span);§Write
use bibtex_parser::{Library, Writer, WriterConfig};
let library = Library::parse(r#"@article{paper, title = "Fast BibTeX"}"#)?;
let mut output = Vec::new();
let config = WriterConfig {
align_values: true,
..Default::default()
};
Writer::with_config(&mut output, config).write_library(&library)?;
assert!(String::from_utf8(output).unwrap().contains("@article{paper"));Re-exports§
pub use error::Error;pub use error::Result;pub use error::SourceSpan;pub use model::normalize_doi;pub use model::parse_names;pub use model::Entry;pub use model::EntryType;pub use model::Field;pub use model::PersonName;pub use model::ValidationError;pub use model::ValidationLevel;pub use model::ValidationSeverity;pub use model::Value;pub use parser::parse_bibtex;pub use parser::ParsedItem;
Modules§
- error
- Error types for the bibtex-parser crate
- latex_
unicode - LaTeX to Unicode conversion for common escape sequences
- model
- Data models for BibTeX entries
- parser
- BibTeX parser implementation using winnow
- prelude
- Re-export of common parser functions
Structs§
- Comment
- A BibTeX comment block.
- Failed
Block - A malformed block retained by tolerant parsing.
- Field
Normalize Options - Field normalization options.
- Issue
Summary - Summary of validation issues by severity
- Library
- A parsed BibTeX library.
- Library
Builder - Builder for creating libraries programmatically
- Library
Stats - Statistics about a library
- Parser
- Parser configuration.
- Preamble
- A BibTeX preamble block.
- Sort
Options - Entry and field ordering options.
- String
Definition - A BibTeX string definition.
- Validation
Report - Comprehensive validation report for a library
- Writer
- BibTeX writer
- Writer
Config - Configuration for writing BibTeX
Enums§
- Block
- A high-level block in a parsed BibTeX library.
- Field
Name Case - Field-name casing policy for field normalization.
- Month
Style - Month rendering style used by month normalization.
Functions§
- parse
- Parse a BibTeX library from a string.
- parse_
file - Parse a BibTeX library from a file.
- to_file
- Convenience function to write a library to a file.
- to_
string - Convenience function to write a library to a string.