https://github.com/digitalheir/bibtex-js
Library for parsing .bib files, used in Bibliography.js π
https://github.com/digitalheir/bibtex-js
bib bibliography bibtex javascript latex parser typescript
Last synced: 6 months ago
JSON representation
Library for parsing .bib files, used in Bibliography.js π
- Host: GitHub
- URL: https://github.com/digitalheir/bibtex-js
- Owner: digitalheir
- License: mit
- Created: 2017-05-24T05:22:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T08:25:28.000Z (almost 3 years ago)
- Last Synced: 2025-03-28T08:23:25.998Z (7 months ago)
- Topics: bib, bibliography, bibtex, javascript, latex, parser, typescript
- Language: TypeScript
- Homepage: https://digitalheir.github.io/bibtex-js/
- Size: 2.75 MB
- Stars: 82
- Watchers: 3
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bibtex.js
[](https://www.npmjs.com/package/bibtex)
[](https://travis-ci.org/digitalheir/bibtex-js)
[](https://github.com/digitalheir/bibtex-js/blob/master/LICENSE)
[](https://codeclimate.com/github/digitalheir/bibtex-js)Library for parsing BibTeX .bib files, based mostly on the excellent guide to BibTeX, [*Tame the BeaST*](http://tug.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf).
[Live demo in browser](https://digitalheir.github.io/bibtex-js/)
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](https://github.com/digitalheir/bibliography-js) (which is mine) or [Citation.js](https://github.com/larsgw/citation.js) or [Zotero](https://github.com/zotero/zotero). If you want to convert LaTeX to Unicode, look into my [latex-to-unicode-converter](https://github.com/digitalheir/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](https://github.com/digitalheir/bibtex-js/issues/1) 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.](https://github.com/digitalheir/bibtex-js/issues)
## Usage
Download standalone ES5 file ([latest](https://github.com/digitalheir/bibtex-js/releases/latest)) or get [from npm](https://www.npmjs.com/package/bibtex):
```
npm install bibtex
``````js
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-insensitiveconst fieldValue = entry
.getField("TITLE"); // This is a complex BibTeX stringconsole.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 specauthorField.authors$.map((author, i) => console.log("Author: "
+ (author.firstNames
.concat(author.vons)
.concat(author.lastNames)
.concat(author.jrs)).join(" ")));```
## Contact
Maarten Trompper ()## License
[MIT](https://github.com/digitalheir/bibtex-js/blob/master/LICENSE)