4 releases (2 breaking)

0.3.0 Jul 22, 2020
0.2.0 May 29, 2017
0.1.1 May 23, 2017
0.1.0 May 23, 2017

#12 in #latex

Download history 17/week @ 2020-09-20 25/week @ 2020-09-27 20/week @ 2020-10-04 33/week @ 2020-10-11 25/week @ 2020-10-18 14/week @ 2020-10-25 26/week @ 2020-11-01 20/week @ 2020-11-08 61/week @ 2020-11-15 72/week @ 2020-11-22 34/week @ 2020-11-29 66/week @ 2020-12-06 77/week @ 2020-12-13 81/week @ 2020-12-20 27/week @ 2020-12-27 130/week @ 2021-01-03

73 downloads per month
Used in inspirer

MIT license

42KB
1K SLoC

nom-bibtex

Rust Docs Badge crates.io

A feature complete BibTeX parser using nom.

nom-bibtex can parse the four differents types of entries listed in the BibTeX format description:

  • Preambles which allows to call LaTeX command inside your BibTeX.
  • Strings which defines abbreviations in a key-value format.
  • Comments.
  • Bibliography entries.

Example

extern crate nom_bibtex;
use nom_bibtex::*;

const BIBFILE_DATA: &str = "@preamble{
        \"A bibtex preamble\"
    }

    @Comment{
        Here is a comment.
    }

    Another comment!

    @string ( name= \"Charles Vandevoorde\")
    @string (github = \"https://github.com/charlesvdv\")

    @misc {my_citation_key,
        author= name,
        title = \"nom-bibtex\",
        note = \"Github: \" # github
    }
";

fn main() {
    let bibtex = Bibtex::parse(BIBFILE_DATA).unwrap();

    let preambles = bibtex.preambles();
    assert_eq!(preambles[0], "A bibtex preamble");

    let comments = bibtex.comments();
    assert_eq!(comments[0], "Here is a comment.");
    assert_eq!(comments[1], "Another comment!");

    let variables = bibtex.variables();
    assert_eq!(variables[0], ("name".into(), "Charles Vandevoorde".into()));
    assert_eq!(variables[1], ("github".into(), "https://github.com/charlesvdv".into()));

    let biblio = &bibtex.bibliographies()[0];
    assert_eq!(biblio.entry_type(), "misc");
    assert_eq!(biblio.citation_key(), "my_citation_key");

    let bib_tags = biblio.tags();
    assert_eq!(bib_tags[0], ("author".into(), "Charles Vandevoorde".into()));
    assert_eq!(bib_tags[1], ("title".into(), "nom-bibtex".into()));
    assert_eq!(bib_tags[2], ("note".into(), "Github: https://github.com/charlesvdv".into()));
}

Dependencies

~1.2–1.7MB
~38K SLoC