Giter Site home page Giter Site logo

nom-bibtex's Introduction

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 = r#"@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["name"], "Charles Vandevoorde");
    assert_eq!(variables["github"], "https://github.com/charlesvdv");

    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["author"], "Charles Vandevoorde");
    assert_eq!(bib_tags["title"], "nom-bibtex");
    assert_eq!(bib_tags["note"], "Github: https://github.com/charlesvdv");
}

nom-bibtex's People

Contributors

a6gibkm avatar atouchet avatar charlesvdv avatar coastalwhite avatar eigenform avatar jonasmalacofilho avatar rubdos avatar thezoq2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nom-bibtex's Issues

Support for escaping LaTeX special characters

Consider this bib file,

    @article{balliu_challenges_2023,
	  title    = {Challenges of {Producing} {Software} {Bill} of {Materials} for {Java}},
	  issn     = {1558-4046},
	  doi      = {10.1109/MSEC.2023.3302956},
	  urldate  = {2023-09-27},
	  journal  = {IEEE Security \& Privacy},
	  author   = {Balliu, Musard and Baudry, Benoit and Bobadilla, Sofia and Ekstedt, Mathias and Monperrus, Martin and Ron, Javier and Sharma, Aman and Skoglund, Gabriel and Soto-Valero, César and Wittlinger, Martin},
	  year     = {2023},
	  note     = {Conference Name: IEEE Security & Privacy},
	  pages    = {2--13},
	  url      = {https://ieeexplore.ieee.org/document/10235318/},
	}
  1. Shouldn't b0.tags()["title"] be Challenges of Producing Software Bill Of Materials for Java?
  2. Shouldn't b0.tags()["journal"] be IEEE Security & Privacy without \?

The inner {} brackets and \ are added when I export this paper's bibtex entry from Zotero. I may not be right, as my logic is only intuitive.

Supporting non-numeric values in month field

Note

This issue was originally posted in getzola/zola#2367

Issue

When loading a BibTeX file that has a non-numeric month field, the parsing fails. Using a three letter abbreviation for the month seems to be at least somewhat common practice.

Here is a BibTeX as provided by the IETF for an RFC (https://datatracker.ietf.org/doc/rfc6749/bibtex/)

@misc{rfc6749,
    series =    {Request for Comments},
    number =    6749,
    howpublished =  {RFC 6749},
    publisher = {RFC Editor},
    doi =       {10.17487/RFC6749},
    url =       {https://www.rfc-editor.org/info/rfc6749},
    author =    {Dick Hardt},
    title =     {{The OAuth 2.0 Authorization Framework}},
    pagetotal = 76,
    year =      2012,
    month =     oct,
    abstract =  {The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the third-party application to obtain access on its own behalf. This specification replaces and obsoletes the OAuth 1.0 protocol described in RFC 5849. {[}STANDARDS-TRACK{]}},
}

Workaround

My current workaround is to either manually change the month to its numerical representation (i.e. month = 10 instead of month = oct), or to add the following lines at the top of my bibtex file:

@string (jan="1")
@string (feb="2")
@string (mar="3")
@string (apr="4")
@string (may="5")
@string (jun="6")
@string (jul="7")
@string (aug="8")
@string (sep="9")
@string (oct="10")
@string (nov="11")
@string (dec="12")

(optional) `nom_locate` support

Hello! I have had the following idea in my head for a while, and would like some feedback:

I would like to create a library (and accompanying application) that can edit existing .bib files, in a non-destructive way, such that .bib files tracked in a VCS have a minimal diff. Therefore, I would need the position of every token/symbol/field in the BibTeX file.

It seems like nom_locate can support this, but this does need an optional field for the position in your models.

If I can optionally compile that in (with a feature-flag), would you accept a pull request for such a feature?

Request for release

Hello, I am sorry to come and nag you, but would it be possible to have a release in crates.io :)?

Support for special characters

Thanks for this nice little crate. I'm using it indirectly, as I am creating a research website using zola.

Now I ran into the issue that I published with people that have special characters in their name. We created a bibtex like this to make sure it works with most LaTex systems.

  • {\'{e}}-> é
  • \"u -> ü

I don't want to maintain multiple files (one for Zola with ü one for LaTex with \"u), so it would be great to improve nom-bibtex.

How could we add support for this in nom-bibtex? I think I would be willing to make a PR with a bit of help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.