A Rust crate for parsing BibTeχ and BibLaTeχ files.
As opposed to the biblatex
crate, this crate does not try to interpret the content of fields.
This crate resulted from the usecase that biblatex
threw an error when math inline mode was not terminated before text was cut off.
Anyone, how wants to retrieve data from a .bib
file.
Add this to your Cargo.toml
:
[dependencies]
bibparser = "0.4.0"
Instantiate the parser and iterate over the items:
use bibparser::Parser;
//let mut p = Parser::from_file("source.bib")?;
let mut p = Parser::from_str(r#"@book{tolkien1937, author = {J. R. R. Tolkien}}"#)?;
for result in p.iter() {
let entry = result?;
println!("type = {}", entry.kind);
println!("id = {}", entry.id);
for (name, data) in entry.fields.iter() {
println!("\t{}\t= {}", name, data);
}
}
This library comes with one example:
$ cargo run --example cli -- --input refs.bib
You can also enable serde-json support in order to print data as JSON:
$ cargo run --features serde,serde_json --example cli -- --input refs.bib --json
In this example, the library would read file refs.bib
and then only print the entry with ID tolkien1937
to stdout.
On github.
- 2022-07-16 version 0.4.0: skip @preamble, proper escape character handling, more tests, bugfix lexing error propagation
- 2022-01-30 version 0.3.2: bugfix cli example & add JSON support
- 2022-01-30 version 0.3.1: fix documentation & README
- 2022-01-30 version 0.3.0: initial release
On github.
.bib
are strongly associated with Teχ which is a programming language, not a markup language. As such only the plain Teχ engine would be capable of understanding the content (esp. the field'sdata
content). This library explicitly takes the approach to assume the content to be a markup language, which hopefully serves 99% of all usecases.- The markup language parsed by this library is not formalized.
- Compability to BibTeχ or biblatex was not comprehensively tested.