Skip to content

Commit acdae21

Browse files
committed
First working version
1 parent 0cdf2cc commit acdae21

11 files changed

Lines changed: 1465 additions & 2 deletions

File tree

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,16 @@ cython_debug/
165165
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166166
# and can be added to the global gitignore or merged into this file. For a more nuclear
167167
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168-
#.idea/
168+
.idea/
169169

170170
# Ruff stuff:
171171
.ruff_cache/
172172

173173
# PyPI configuration file
174174
.pypirc
175+
176+
# Ignore the tex files in the `test_template` directory, since we do not want to accidentally publish an official
177+
# template under a different license
178+
test/test_template/*.tex
179+
test/test_template/*.pdf
180+
test/test_template/*.cls

README.md

Lines changed: 270 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,271 @@
11
# python-bibtex-linter
2-
A Python script to parse bibtex entries and analyze them for errors.
2+
A Python tool to parse BibTeX entries and a set of self-defined invariants (constraints) on them.
3+
4+
> [!warning]
5+
> This tool is a **Work in Progress**.
6+
7+
## Motivation
8+
I've always assumed that I just needed to take care that my `references.bib` file was in order, that as many of the
9+
fields of the entries in there were filled, and then I could easily use them to create standard-conforming citations in
10+
my LaTeX documents.
11+
As it turns out, a lot of different citation styles omit various fields, and it's an overall mess.
12+
Therefore, I created this tool (in Python, since that's what I know best), that can parse the entries and then performs
13+
arbitrary (self-defined) invariant checks on them.
14+
15+
In my field the most used citation style is IEEEtran so this is how I've defined the invariants in the script.
16+
However, I tried to make it easy to define others if the need arises.
17+
18+
## How to use:
19+
First we need to install the tool, I recommend to use [pipx](https://github.com/pypa/pipx) for that:
20+
```commandline
21+
pipx install .
22+
```
23+
24+
Then you can call the script the following way:
25+
```commandline
26+
bibtex_linter path/to/refs.bib
27+
```
28+
29+
The script will parse the file, perform the verifications and print out the results.
30+
31+
## Definition of used Terms
32+
33+
### Entry
34+
An entry to the BibTeX file:
35+
```LaTeX
36+
@article{basic_case,
37+
author = {Test author},
38+
title = {Standard field format},
39+
year = {2020}
40+
}
41+
```
42+
43+
### Field
44+
A field inside an entry, consists of a `key` and a `value`:
45+
```LaTeX
46+
author = {Test author},
47+
```
48+
In this case, `"author"` would be the `key` and `"Test author"` the `value`.
49+
50+
> [!note]
51+
> There are many different ways of wrapping the value text, from `{}` via `{{}}` or `""`.
52+
> This tool removes these wrapping characters and only considers the text inside of them as `value`.
53+
54+
### Entry Type
55+
The entry type specifies the available fields and is written behind the `@` and in front of the first `{` of an entry:
56+
```LaTeX
57+
@article{...}
58+
@conference{...}
59+
@online{...}
60+
```
61+
62+
## IEEE Citations
63+
Here's my observations on the different entry types with the standard `IEEEtran.cls` style template.
64+
You can find maximal examples (e.g. of all the available fields) [here](./test/test_template/maximal_example_refs.bib).
65+
This file can also be used to generate a test bibliography to check how entries are rendered with your citation style
66+
and template.
67+
68+
> [!note]
69+
> This is not the full list of possible entry types, just the ones I deemed most important.
70+
> The full list can be found in the
71+
> [offical template documentation](https://ctan.net/macros/latex/contrib/IEEEtran/bibtex/IEEEtran_bst_HOWTO.pdf).
72+
73+
### Article
74+
A typical journal article.
75+
76+
Rendered fields:
77+
- author
78+
- title
79+
- journal
80+
- volume
81+
- pages
82+
- month
83+
- year
84+
- note
85+
86+
Not rendered fields:
87+
- language
88+
- number
89+
- url
90+
91+
### InProceedings/Conference
92+
A typical conference paper.
93+
94+
Rendered fields:
95+
- author
96+
- title
97+
- booktitle
98+
- editor
99+
- volume
100+
- series
101+
- address
102+
- pages
103+
- organization
104+
- publisher
105+
- month
106+
- year
107+
- note
108+
109+
Not rendered fields:
110+
- intype
111+
- language
112+
- number
113+
- paper
114+
- type
115+
- url
116+
117+
### Online/Electronic
118+
A reference on the internet.
119+
120+
Rendered fields:
121+
- author
122+
- title
123+
- howpublished
124+
- month
125+
- year
126+
- note
127+
128+
> [!warning]
129+
> It is especially surprising (to me), that the `online` type does not render the URL field.
130+
> After some research I found out that it is suggested to put the URL into the `note` field instead:
131+
> `note = {{Available: \url{...}, Accessed 2025-01-01}},`.
132+
133+
Not rendered fields
134+
- language
135+
- organization
136+
- address
137+
- url
138+
139+
### Book
140+
Referencing a whole book.
141+
142+
Rendered fields:
143+
- author
144+
- title
145+
- volume
146+
- series
147+
- address
148+
- publisher
149+
- edition
150+
- month
151+
- year
152+
- note
153+
154+
Not rendered fields:
155+
- editor
156+
- language
157+
- volume
158+
- number
159+
- url
160+
161+
### InBook
162+
Referencing a part of a book (chapters or pages).
163+
164+
Rendered fields:
165+
- author
166+
- title
167+
- volume
168+
- series
169+
- type
170+
- chapter
171+
- pages
172+
- address
173+
- publisher
174+
- edition
175+
- month
176+
- year
177+
- note
178+
179+
Not rendered fields:
180+
- editor
181+
- language
182+
- number
183+
- url
184+
185+
### InCollection
186+
Referencing a part of a book that has its own name.
187+
188+
Rendered fields:
189+
- author
190+
- title
191+
- booktitle
192+
- editor
193+
- volume
194+
- series
195+
- type
196+
- chapter
197+
- pages
198+
- address
199+
- publisher
200+
- edition
201+
- month
202+
- year
203+
- note
204+
205+
Not rendered fields:
206+
- language
207+
- number
208+
- url
209+
210+
### Standard
211+
Used for proposed or formally published standards.
212+
213+
Rendered fields:
214+
- author
215+
- title
216+
- howpublished
217+
- month
218+
- year
219+
- note
220+
221+
Not rendered fields:
222+
- language
223+
- organization
224+
- institution
225+
- type
226+
- number
227+
- revision
228+
- address
229+
- url
230+
231+
### TechReport
232+
Used for technical reports, or reports about standards. Not to be confused with
233+
[standard](#standard).
234+
235+
Rendered fields:
236+
- author
237+
- title
238+
- type
239+
- number
240+
- institution
241+
- address
242+
- month
243+
- year
244+
- note
245+
246+
> [!warning]
247+
> I advise against using the `techreport` entry type, as it omits the `howpublished` field, which I would
248+
> consider mandatory.
249+
250+
Not rendered fields:
251+
- language
252+
- howpublished
253+
- url
254+
255+
### Misc
256+
Anything else that does not fit the above.
257+
258+
Rendered fields:
259+
- author
260+
- title
261+
- howpublished
262+
- month
263+
- year
264+
- note
265+
266+
Not rendered fields:
267+
- language
268+
- organization
269+
- address
270+
- pages
271+
- url

bibtex_linter/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)