Digitalheir Bibtex Js Save

Library for parsing .bib files, used in Bibliography.js πŸ“š

Project README

Bibtex.js

npm version Build Status License Code Climate

Library for parsing BibTeX .bib files, based mostly on the excellent guide to BibTeX, Tame the BeaST.

Live demo in browser

Written in Typescript, compiled to ES5 Javascript (with typings provided).

This module literally just parses a BibTex file and processes it as far as BibTeX goes. It doesn't process TeX commands (i.e., {\"o} is not translated to ΓΆ). It does however, parse author names, as this is part of the BibTeX standard (see example below). If you want to actually work with a bibliography, look into Bibliography.js (which is mine) or Citation.js or Zotero. If you want to convert LaTeX to Unicode, look into my latex-to-unicode-converter.

Implementation

Not all internal BibTeX functions are implemented, simply because I don't need them personally and can't imagine anyone to need them. Most notably sorting entries is still an open issue because BibTeX has a little complicated algorithm which required a function that "purifies" field values, which for example makes {\ss} equivalent to ss but makes Γ€ come after z. I am unsure if that is actually what anyone wants in modern days though. A modern approach would be to use Unicode collation and then sort.

Pull requests and issues are welcome.

Usage

Download standalone ES5 file (latest) or get from npm:

npm install bibtex
import {parseBibFile, normalizeFieldValue} from "bibtex";

const bibFile = parseBibFile(`
          @InProceedings{realscience,
            author    = {Marteen Fredrik Adriaan ding de la Trumppert and Ω…Ω‡Ψ―ΩŠ N\\"allen and henQuq, jr, Mathize},
            title     = {You Won't Believe This Proof That {P} \\gtreqqless {NP} Using Super-{T}uring Computation Near Big Black Holes},
            booktitle = {Book of Qeq},
            month     = {September},
            year      = {2001},
            address   = {Dordrecht},
            publisher = {Willems Uitgeverij},
            url       = {https://github.com/digitalheir/},
            pages     = {6--9}
          }
`);

const entry = bibFile
  .getEntry("realscience") // Keys are case-insensitive

const fieldValue = entry
  .getField("TITLE"); // This is a complex BibTeX string

console.log(
    // But we can normalize to a JavaScript string
    normalizeFieldValue(fieldValue)
); 

const authorField = entry
  .getField("author"); // This is a special object, divided into first names, vons and last names according to BibTeX spec

authorField.authors$.map((author, i) => console.log("Author: " 
  + (author.firstNames
            .concat(author.vons)
            .concat(author.lastNames)
            .concat(author.jrs)).join(" ")));

Contact

Maarten Trompper ([email protected])

License

MIT

Open Source Agenda is not affiliated with "Digitalheir Bibtex Js" Project. README Source: digitalheir/bibtex-js
Stars
75
Open Issues
6
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating