@citation-js/plugin-bibtex

中文文档
0.9.0发布于 2026/09/18MITTypeScriptESM + CJS近 30 天下载 31.8万

Plugin for BibTeX formats for Citation.js

原始使用文档
文档目录15 节
  1. Install
  2. Usage
  3. Formats
  4. BibTeX
  5. BibLaTeX
  6. Bib.TXT
  7. Configuration
  8. Type mappings
  9. Required types
  10. Field types
  11. Unicode
  12. Formatting
  13. Other commands
  14. English languages
  15. Replacement strings

@citation-js/plugin-bibtex

Plugin for BibTeX formats for Citation.js.

NPM version NPM total downloads License Dependency status

Install

npm install @citation-js/plugin-bibtex

Usage

Register by importing the package:

require('@citation-js/plugin-bibtex')

Formats

Formats and other features added by this plugin.

BibTeX

This plugin adds input and output support for BibTeX, both in text form and as a JSON representation. Input types are called @bibtex/text and @bibtex/entry+object, output format is bibtex. The output has format dictionary support.

BibLaTeX

This plugin adds input and output support for BibLaTeX, both in text form and as a JSON representation. Input types are called @biblatex/text and @biblatex/entry+object, output format is biblatex. The output has format dictionary support.

Bib.TXT

This plugin adds input and output support for Bib.TXT, a simplified and modernised version of BibTeX. Input types are called @bibtxt/text and @biblatex/entry+object, output format is bibtxt. The output has format dictionary support.

Configuration

Configuration can be accessed like the following:

const { plugins } = require('@citation-js/core')
const config = plugins.config.get('@bibtex')
PropertyValues [default]Description
config.parse.stricttrue, [false]When true, entries are checked for required fields.
config.parse.sentenceCase'always', 'english', ['never']Convert titles to sentence case when parsing.
config.format.useIdAsLabeltrue, [false]Use the entry ID as the label instead of generating one.
config.format.checkLabel[true], falseRemove unsafe characters from the provided label (or ID).
config.format.asciiOnly[true], falseEscape or remove non-ASCII characters.

Type mappings

Entry type mappings between BibLaTeX or BibTeX and CSL-JSON are available through config.types.biblatex and config.types.bibtex. In both cases, the Bib(La)TeX mappings are in the source field and the reverse mappings in the target field.

config.types.biblatex.source.inproceedings = 'paper-conference'
config.types.biblatex.target['paper-conference'] = 'inproceedings'

Required types

The list of required fields for each type for BibLaTeX and BibTeX is available under config.required.biblatex and config.required.bibtex respectively. In both cases, the list consists of strings for required fields and arrays for sets of fields where at least one should be present (year OR date for BibLaTeX for example).

config.required.biblatex.book = [
  'title',
  ['author', 'editor'],
  'publisher',
  ['year', 'date']
]

Field types

Field types (used for both BibLaTeX and BibTeX) are available through config.constants.fieldTypes. This returns an object mapping Bib(La)TeX field names to an array containing a field type and a value type. The former is either field, list (" and "-delimited), or separated (comma-delimited). As for the latter:

Value typeDescription
literalNormal text or numeric content
titleLike literal but can be affected by config.parse.sentenceCase
nameA personal or organizational name
dateAn EDTF Level 1 date
verbatimUnaltered text (no expansion of commands, etc.)
uriSame as verbatim but if needed the URL is encoded
otherNo special behaviour, treated like literal
// Add `daturl` for dat:// URLs
config.constants.fieldTypes.daturl = ['field', 'uri']
// Do not treat `publisher` as a list
config.constants.fieldTypes.publisher = ['field', 'literal']

Unicode

  • config.constants.diacritics maps commands (\") to diacritics
  • config.constants.commands maps commands (\textinterrobangdown) to general unicode characters (⸘)
  • config.constants.ligatures maps non-command character sequences (---, ~, etc.) to their replacements (emdash, no-breaking space, etc.)
  • config.constants.ligaturePattern is a RegExp that recognizes the ligatures mapped above
  • config.constants.mathScripts maps superscript and subscript (in properties ^ and _ respectively)
config.constants.diacritics['"'] = '\u0308'
config.constants.commands.textinterrobangdown = '⸘'
config.constants.ligatures = {
  '---': '\u2014',
  '~': '\u00A0'
}
config.constants.ligaturePattern = /---|~/g // Don't forget the (g)lobal flag
config.constants.mathScripts = {
  '^': { '1': '¹' },
  '_': { '1': '₁' }
}

Formatting

  • config.constants.formattingEnvs maps environment commands to formatting
  • config.constants.formattingCommands maps regular commands to formatting
  • config.constants.mathScriptFormatting maps ^ and _ to resp. super- and subscript
  • config.constants.formatting maps formatting to HTML (though RTF or Markdown could be substituted)
config.constants.formattingEnvs.bf = 'bold'
config.constants.formattingCommands.textbf = 'bold'
config.constants.mathScriptFormatting['^'] = 'superscript'
config.constants.formatting = {
  bold: ['<b>', '</b>'],
  superscript: ['<sup>', '</sup>']
}

Other commands

The object config.constants.argumentCommands maps command names to functions handling them. This does not include commands used above. Braced arguments are parsed automatically based on how many arguments the function takes. It does not support optional arguments (i.e. those in square braces) yet.

config.constants.argumentCommands.href = function (url, displayText) {
  // Note: <a> tags are not supported by CSL so watch out if you use this
  return `<a href="${url}">${displayText}</a>`
}

// You can also use it to replace commands that produce text
config.constants.argumentCommands.LaTeX = () => 'LaTeX'

English languages

The array config.constants.sentenceCaseLanguages affects which languages are eligible for sentence-casing when config.parse.sentenceCase is set to 'english'. All entries should be lowercase.

config.constants.sentenceCaseLanguages = [
  'english',
  'en-us',
  'en-gb'
]

Replacement strings

The object config.constants.defaultStrings determines which strings are defined by default.

config.constants.defaultStrings.larsgw = "Willighagen, Lars G"

版本与发布记录

@citation-js/plugin-bibtex 共发布 59 个版本,首次发布于 2018/12/07;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.9.0latest2026/09/181 个月前
0.8.22026/07/133 个月前
0.8.12026/07/064 个月前
0.8.02026/07/064 个月前
0.7.212025/10/201.1 年前
0.7.182025/01/281.8 年前

关于 @citation-js/plugin-bibtex 的常见问题

@citation-js/plugin-bibtex 是什么?

Plugin for BibTeX formats for Citation.js

如何安装 @citation-js/plugin-bibtex?

在项目目录运行 npm install @citation-js/plugin-bibtex,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@citation-js/core(^0.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@citation-js/plugin-bibtex 支持 TypeScript 吗?

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

@citation-js/plugin-bibtex 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@citation-js/plugin-bibtex 需要什么版本的 Node.js?

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

@citation-js/plugin-bibtex 可以商用吗?

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

@citation-js/plugin-bibtex 的下载量有多少?

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

@citation-js/plugin-bibtex 还在维护吗?

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