Skip to content

Parse BibTeX entries into JavaScript objects (and back) including processing of basic LaTeX in entry fields.

License

ignacioxd/bib-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bib-parser - A BibTeX JavaScript Parser

Parse BibTeX entries into JavaScript objects (and back) including processing of basic LaTeX in entry fields.

dependencies Status devDependencies Status License: MIT


Installation

npm install ignacioxd/bib-parser

Usage

import {parse, build} from 'bib-parser';

or

const {parse, build} = require('bib-parser');

Then, give the parse function a BibTeX string and it will return an array of parsed entries.

let parsedEntriesArray = parse(bibtexString);

If you prefer to recieve an object keyed on the BibTeX entries' keys, pass an additional true argument:

let parsedEntriesObject = parse(bibtexString, true);

Parsed entries (objects or arrays) can be converted back to BibTeX strings using the build function:

let bibtexSource = build(parsedEntries);

Structure of Parsed Entries

Each BibTeX entry is returned as an object, with each attribute in the BibTeX entry becoming an all-lowercase attribute in its corresponding object. Each attribute will be returned both in its parsed and in its original formats (see below for more details). Additionally, authors will be further processed and returned as an array. An example of an attribute will help illustrate this.

@inproceedings{CiteMe1990:BetaPaper,
	Title={The \beta Effect},
	Author={Last Name, Jane and Jo\'{e} LastName},
	booktitle={Very Respectable Conference on {\beta} Examples},
	YEAR={1990}
}

will be parsed as an object with this structure:

{
  entryType: 'inproceedings',
  entryKey: 'CiteMe1990:BetaPaper',
  title: {
    rawName: 'Title',
    value: 'The β Effect',
    rawValue: 'The \\beta Effect'
  },
  author: {
    rawName: 'Author',
    value: 'Last Name, Jane and Joé LastName',
    rawValue:  "Last Name, Jane and Jo\\'{e} LastName",
    authors: [
      'Jane Last Name',
      'Joé LastName'
    ]
  },
  booktitle: {
    rawName: 'booktitle',
    value: 'Very Respectable Conference on β Examples',
    rawValue: 'Very Respectable Conference on {\\beta} Examples'
  },
  year: {
    rawName: 'YEAR',
    value: '1990',
    rawValue: '1990'
  }
}

More formally, each entry will have two special attributes: entryType to indicate the type of BibTeX entry in lowercase (e.g., inproceedings), and entryKey with the key identifier for the entry preserving the source's casing. Each BibTeX attribute will become an attribute in the respective object with the following structure:

  • rawName: Name of the BibTeX entry attribute as originally specified in the source string.
  • value: Parsed value of the attribute, including processing of basic LaTeX converted into Unicode symbols.
  • rawValue: Value of the attribute as originally included in the BibTeX source string. Any LaTeX is returned as is.

Additionally, author entries will contain an extra authors array with parsed author(s) name(s).

Reconstructing BibTeX Source

Entries returned by this library can be converted back to BibTeX using the build function. This function expects an array of entry objects, or a keyed object of entry objects. The return value will be an array of BibTeX string entries.

let bibtexSource = build(parsedEntries);

About

Parse BibTeX entries into JavaScript objects (and back) including processing of basic LaTeX in entry fields.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •