@citestyle/bibtex 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +53 -46
  2. package/package.json +19 -4
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @citestyle/bibtex
2
2
 
3
- BibTeX parser and serializer. Converts between BibTeX and CSL-JSON, the standard input format for Citestyle.
3
+ 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.
4
+
5
+ Use this to bring BibTeX references into the Citestyle formatting pipeline, or to export formatted bibliographies back to BibTeX for sharing with LaTeX users.
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,11 +10,9 @@ BibTeX parser and serializer. Converts between BibTeX and CSL-JSON, the standard
8
10
  npm install @citestyle/bibtex
9
11
  ```
10
12
 
11
- ## Usage
12
-
13
- ### Parse BibTeX to CSL-JSON
13
+ ## Parse BibTeX to CSL-JSON
14
14
 
15
- ```js
15
+ ```javascript
16
16
  import { parseBibtex } from '@citestyle/bibtex'
17
17
 
18
18
  const bibtex = `
@@ -28,18 +28,20 @@ const bibtex = `
28
28
  `
29
29
 
30
30
  const items = parseBibtex(bibtex)
31
- console.log(items[0].title) // "A Study of DNA Replication"
32
- console.log(items[0].author[0].family) // "Smith"
33
- console.log(items[0].author[1]['non-dropping-particle']) // "de la"
34
- console.log(items[0].page) // "100-108"
31
+
32
+ items[0].title // "A Study of DNA Replication"
33
+ items[0].author[0].family // "Smith"
34
+ items[0].author[1]['non-dropping-particle'] // "de la"
35
+ items[0].page // "100-108"
36
+ items[0].DOI // "10.1038/example"
35
37
  ```
36
38
 
37
- ### Export CSL-JSON to BibTeX
39
+ ## Export CSL-JSON to BibTeX
38
40
 
39
- ```js
41
+ ```javascript
40
42
  import { exportBibtex } from '@citestyle/bibtex'
41
43
 
42
- const items = [{
44
+ const output = exportBibtex([{
43
45
  id: 'smith2024',
44
46
  type: 'article-journal',
45
47
  title: 'A Study of DNA Replication',
@@ -49,67 +51,72 @@ const items = [{
49
51
  volume: '620',
50
52
  page: '100-108',
51
53
  DOI: '10.1038/example',
52
- }]
54
+ }])
53
55
 
54
- const output = exportBibtex(items)
55
56
  // @article{smith2024,
56
57
  // author = {Smith, John},
57
58
  // title = {A Study of DNA Replication},
58
59
  // journal = {Nature},
59
- // ...
60
+ // year = {2024},
61
+ // volume = {620},
62
+ // pages = {100--108},
63
+ // doi = {10.1038/example}
60
64
  // }
61
65
  ```
62
66
 
63
- ### Convert LaTeX commands to Unicode
64
-
65
- ```js
66
- import { convertLatex } from '@citestyle/bibtex'
67
-
68
- convertLatex("Universit\\\"at M\\\"unchen") // "Universitat Munchen" → "Universitat München"
69
- convertLatex("Sch\\\"onfinkel") // "Schonfinkel" → "Schönfinkel"
70
- convertLatex("{\\ss}") // "ß"
71
- convertLatex("\\o") // "ø"
72
- ```
73
-
74
- ### Pipeline: BibTeX to formatted bibliography
67
+ ## Full pipeline: BibTeX to formatted bibliography
75
68
 
76
- ```js
69
+ ```javascript
77
70
  import { parseBibtex } from '@citestyle/bibtex'
78
71
  import { createRegistry } from '@citestyle/registry'
79
72
  import * as apa from '@citestyle/styles/apa'
80
73
 
81
- const bibtex = readFileSync('references.bib', 'utf-8')
82
- const items = parseBibtex(bibtex)
74
+ const items = parseBibtex(readFileSync('references.bib', 'utf-8'))
83
75
 
84
76
  const registry = createRegistry(apa)
85
77
  registry.addItems(items)
86
78
 
87
79
  const bibliography = registry.getBibliography()
88
- bibliography.forEach(entry => console.log(entry.html))
80
+ bibliography.forEach(entry => {
81
+ console.log(entry.html) // Semantic HTML with CSS classes and linked DOIs
82
+ console.log(entry.text) // Plain text for copy-paste
83
+ })
89
84
  ```
90
85
 
86
+ ## LaTeX to Unicode conversion
87
+
88
+ ```javascript
89
+ import { convertLatex } from '@citestyle/bibtex'
90
+
91
+ convertLatex('Universit\\"at M\\"unchen') // "Universität München"
92
+ convertLatex('Sch\\"onfinkel') // "Schönfinkel"
93
+ convertLatex('{\\ss}') // "ß"
94
+ convertLatex('\\o') // "ø"
95
+ convertLatex("Caf\\'e") // "Café"
96
+ ```
97
+
98
+ 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`).
99
+
91
100
  ## API
92
101
 
93
- ### `parseBibtex(str)`
102
+ ### `parseBibtex(str) → CslItem[]`
94
103
 
95
- Parse a BibTeX string into an array of CSL-JSON items.
104
+ Parse a BibTeX string into CSL-JSON items.
96
105
 
97
- **Supported entry types:** `@article`, `@book`, `@inproceedings`, `@incollection`, `@inbook`, `@phdthesis`, `@mastersthesis`, `@misc`, `@techreport`, `@unpublished`, `@proceedings`, `@manual`, `@conference`, `@booklet`, `@online`.
106
+ **Supported entry types**: `@article`, `@book`, `@inproceedings`, `@incollection`, `@inbook`, `@phdthesis`, `@mastersthesis`, `@misc`, `@techreport`, `@unpublished`, `@proceedings`, `@manual`, `@conference`, `@booklet`, `@online`
98
107
 
99
- **Features:**
100
- - LaTeX accent/command conversion (120+ mappings)
101
- - `@string` abbreviation expansion
102
- - `#` concatenation of string values
103
- - Braced and quoted string values
104
- - Month abbreviations (jan-dec)
108
+ **Handles**:
109
+ - LaTeX accent and command conversion (120+ mappings)
110
+ - `@string` abbreviation expansion and `#` concatenation
111
+ - Braced and quoted string values, nested brace stripping
112
+ - Month abbreviations (`jan`–`dec`)
105
113
  - Name parsing with particles (`von`, `de`, `de la`) and suffixes (`Jr.`, `III`)
106
- - Corporate/institutional authors via double braces (`{{World Health Organization}}`)
107
- - Nested brace stripping
114
+ - Corporate/institutional authors via double braces: `{{World Health Organization}}`
108
115
 
109
- ### `exportBibtex(items)`
116
+ ### `exportBibtex(items) → string`
110
117
 
111
- Serialize an array of CSL-JSON items to a BibTeX string. Produces clean output with en-dash page ranges and proper name formatting.
118
+ Serialize CSL-JSON items to BibTeX. Produces clean output with en-dash page ranges (`--`) and proper name formatting.
112
119
 
113
- ### `convertLatex(str)`
120
+ ### `convertLatex(str) → string`
114
121
 
115
- Convert LaTeX accent sequences and special commands to Unicode characters. Handles `\"`, `\'`, `\^`, `\~`, `\c`, `\v`, and special commands like `\ss`, `\o`, `\ae`.
122
+ Convert LaTeX accent sequences and special commands to Unicode characters. Useful when processing individual BibTeX field values outside of the full parser.
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "@citestyle/bibtex",
3
- "version": "0.0.2",
3
+ "version": "1.0.1",
4
4
  "description": "BibTeX ↔ CSL-JSON parser and serializer",
5
+ "author": "Uniweb",
6
+ "homepage": "https://github.com/uniweb/csl/tree/main/packages/bibtex",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/uniweb/csl.git",
10
+ "directory": "packages/bibtex"
11
+ },
12
+ "keywords": [
13
+ "bibtex",
14
+ "csl",
15
+ "parser",
16
+ "serializer",
17
+ "citation",
18
+ "latex",
19
+ "bibliography"
20
+ ],
5
21
  "type": "module",
6
22
  "exports": {
7
23
  ".": {
@@ -15,7 +31,7 @@
15
31
  "README.md"
16
32
  ],
17
33
  "dependencies": {
18
- "@citestyle/types": "0.0.2"
34
+ "@citestyle/types": "1.0.1"
19
35
  },
20
36
  "devDependencies": {
21
37
  "vitest": "^3.1.1"
@@ -25,7 +41,6 @@
25
41
  },
26
42
  "license": "MIT",
27
43
  "scripts": {
28
- "test": "vitest run --passWithNoTests",
29
- "lint": "echo 'TODO: configure linter'"
44
+ "test": "vitest run --passWithNoTests"
30
45
  }
31
46
  }