@citestyle/bibtex

中文文档
1.1.0发布于 2026/05/30MITTypeScriptES Module近 30 天下载 2023

BibTeX ↔ CSL-JSON parser and serializer

原始使用文档
文档目录9 节
  1. Installation
  2. Parse BibTeX to CSL-JSON
  3. Export CSL-JSON to BibTeX
  4. Full pipeline: BibTeX to formatted bibliography
  5. LaTeX to Unicode conversion
  6. API
  7. parseBibtex(str) → CslItem[]
  8. exportBibtex(items) → string
  9. convertLatex(str) → string

@citestyle/bibtex

Parse BibTeX files into CSL-JSON and export CSL-JSON back to BibTeX. Handles the real-world messiness of BibTeX: LaTeX accent commands, @string abbreviations, # concatenation, name particles (von, de la), suffixes (Jr., III), and corporate authors.

Use this to bring BibTeX references into the Citestyle formatting pipeline, or to export formatted bibliographies back to BibTeX for sharing with LaTeX users.

Installation

npm install @citestyle/bibtex

Parse BibTeX to CSL-JSON

import { parseBibtex } from '@citestyle/bibtex'

const bibtex = `
@article{smith2024,
  author = {Smith, John and de la Cruz, Maria},
  title = {A Study of {DNA} Replication},
  journal = {Nature},
  year = {2024},
  volume = {620},
  pages = {100--108},
  doi = {10.1038/example}
}
`

const items = parseBibtex(bibtex)

items[0].title                                // "A Study of DNA Replication"
items[0].author[0].family                     // "Smith"
items[0].author[1]['non-dropping-particle']    // "de la"
items[0].page                                 // "100-108"
items[0].DOI                                  // "10.1038/example"

Export CSL-JSON to BibTeX

import { exportBibtex } from '@citestyle/bibtex'

const output = exportBibtex([{
  id: 'smith2024',
  type: 'article-journal',
  title: 'A Study of DNA Replication',
  author: [{ family: 'Smith', given: 'John' }],
  issued: { 'date-parts': [[2024]] },
  'container-title': 'Nature',
  volume: '620',
  page: '100-108',
  DOI: '10.1038/example',
}])

// @article{smith2024,
//   author = {Smith, John},
//   title = {A Study of DNA Replication},
//   journal = {Nature},
//   year = {2024},
//   volume = {620},
//   pages = {100--108},
//   doi = {10.1038/example}
// }

Full pipeline: BibTeX to formatted bibliography

import { parseBibtex } from '@citestyle/bibtex'
import { createRegistry } from '@citestyle/registry'
import * as apa from '@citestyle/styles/apa'

const items = parseBibtex(readFileSync('references.bib', 'utf-8'))

const registry = createRegistry(apa)
registry.addItems(items)

const bibliography = registry.getBibliography()
bibliography.forEach(entry => {
  console.log(entry.html)   // Semantic HTML with CSS classes and linked DOIs
  console.log(entry.text)   // Plain text for copy-paste
})

LaTeX to Unicode conversion

import { convertLatex } from '@citestyle/bibtex'

convertLatex('Universit\\"at M\\"unchen')   // "Universität München"
convertLatex('Sch\\"onfinkel')               // "Schönfinkel"
convertLatex('{\\ss}')                       // "ß"
convertLatex('\\o')                          // "ø"
convertLatex("Caf\\'e")                      // "Café"

120+ LaTeX accent and command mappings. Covers \", \', \^, \~, \``, \c, \v, =, \H, \u, \d, \b, \k, and special commands (\ss, \o, \O, \ae, \AE, \aa, \AA, \l, \L, \i, \j`).

API

parseBibtex(str) → CslItem[]

Parse a BibTeX string into CSL-JSON items.

Supported entry types: @article, @book, @inproceedings, @incollection, @inbook, @phdthesis, @mastersthesis, @misc, @techreport, @unpublished, @proceedings, @manual, @conference, @booklet, @online

Handles:

  • LaTeX accent and command conversion (120+ mappings)
  • @string abbreviation expansion and # concatenation
  • Braced and quoted string values, nested brace stripping
  • Month abbreviations (jan–dec)
  • Name parsing with particles (von, de, de la) and suffixes (Jr., III)
  • Corporate/institutional authors via double braces: {{World Health Organization}}

exportBibtex(items) → string

Serialize CSL-JSON items to BibTeX. Produces clean output with en-dash page ranges (--) and proper name formatting.

convertLatex(str) → string

Convert LaTeX accent sequences and special commands to Unicode characters. Useful when processing individual BibTeX field values outside of the full parser.

版本与发布记录

@citestyle/bibtex 共发布 4 个版本,首次发布于 2026/03/13;过去 12 个月发布了 4 个版本。

版本发布日期距今
1.1.0latest2026/05/305 个月前
1.0.12026/04/276 个月前
1.0.02026/03/137 个月前
0.0.22026/03/137 个月前

关于 @citestyle/bibtex 的常见问题

@citestyle/bibtex 是什么?

BibTeX ↔ CSL-JSON parser and serializer

如何安装 @citestyle/bibtex?

在项目目录运行 npm install @citestyle/bibtex,或使用 pnpm add / yarn add / bun add。

@citestyle/bibtex 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@citestyle/bibtex 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@citestyle/bibtex 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@citestyle/bibtex 可以商用吗?

@citestyle/bibtex 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@citestyle/bibtex 的下载量有多少?

根据 npm 官方下载统计,@citestyle/bibtex 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,023 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@citestyle/bibtex 还在维护吗?

最新版本 1.1.0 发布于 2026/05/30(5 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/03/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。