Skip to content

Commit cd50e74

Browse files
Bibliographies (#1058)
Adds citation support using a biblatex file and [pybtex](https://pybtex.org/), reactors most current citations to use it, and adds a small guide to explain how to use it. Resolves #957.
1 parent 0ebb5e6 commit cd50e74

File tree

80 files changed

+1099
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1099
-298
lines changed

.github/workflows/ci.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,22 @@ jobs:
118118
crate: mdbook-linkcheck
119119
version: '0.7.7'
120120

121+
# Install Python and friends for website generation only where needed
122+
- uses: actions/setup-python@v4
123+
with:
124+
python-version: '3.8'
125+
check-latest: true
126+
cache: 'pip'
127+
128+
- run: python3 -m pip install -r master/scripts/requirements.txt
129+
121130
- uses: actions/cache/restore@v3
122131
with:
123132
key: pre-website-${{ github.run_id }}
124133
path: master/docs
125134

126135
# Tell mdbook to use only the linkcheck backend
127-
- name: Check website links
136+
- name: Check website links and bibtex references
128137
env:
129138
MDBOOK_OUTPUT: '{"linkcheck":{}}'
130139
run: |

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106

107107
"[python]": {
108108
"editor.tabSize": 4,
109-
"editor.defaultFormatter": "ms-python.python"
109+
"editor.defaultFormatter": null,
110+
"editor.formatOnSave": false,
111+
"editor.formatOnType": false,
112+
"editor.formatOnPaste": false
110113
}
111114
}

CITING-SOURCES.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Citing sources
2+
3+
All of the references and sources of the agda-unimath library are managed in a
4+
[BibLaTeX](https://www.ctan.org/pkg/biblatex) file `references.bib`, and we have
5+
a custom set of macros to work with them.
6+
7+
The macros are as follows:
8+
9+
<!--
10+
We have inserted an invisible whitespace character between the first and second
11+
opening curly braces in the below examples to block the citation preprocessor
12+
from detecting them as macros.
13+
-->
14+
15+
- `{­{#cite referenceXYZ}}` will insert a citation to the reference labeled
16+
`referenceXYZ` (which must be defined in the `references.bib` file) at the
17+
current location, and add that reference to the current page's bibliography.
18+
- `{­{#reference referenceXYZ}}` will add the reference labeled `referenceXYZ`
19+
to the current page's bibliography without inserting a citation.
20+
- `{­{#bibliography}}` is a marker for where the bibliography of the current
21+
page should be inserted. If no such marker is found and the bibliography is
22+
inhabited, it will be inserted at the bottom of the page in a new section
23+
titled `References`.
24+
25+
Note that entries in the BibLaTeX file are expected to have all of the
26+
apropriate fields defined according to their type. For instance, `@book`s _must_
27+
have a defined field for `publisher` and `year`. If this information is not
28+
available, please define them as empty fields. E.g. `publisher = {},`.
29+
30+
If you are unsure about how to structure your BibLaTeX entry, it may be useful
31+
to know that the references are checked by the `linkcheck` GitHub workflow, so
32+
when you post your pull request to `agda-unimath` you can refer to the CI for
33+
possible issues.
34+
35+
**Note:** If the citation label of your reference is not being generated
36+
properly, we support a custom `citeas` field that can be used to overwrite it.
37+
For instance, _Homotopy Type Theory: Univalent Foundations of Mathematics_
38+
should be cited as {{#cite UF13}}, and to make it so we have set
39+
`citeas = {UF13}` for its BibLaTeX entry. Keep in mind that if the citation
40+
label is not being generated properly, then it is likely that the author list is
41+
not being parsed properly either.

HOWTO-INSTALL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ In order to contribute to the `agda-unimath` library you will additionally need:
2121
1. `git`
2222
2. `make`
2323
3. `python` version 3.8 or newer
24-
4. The python libraries `pre-commit`, `requests` and `tomli`. Those can be
25-
installed by running
24+
4. The python libraries `pre-commit`, `pybtex`, `requests` and `tomli`. Those
25+
can be installed by running
2626
```shell
2727
python3 -m pip install -r scripts/requirements.txt
2828
```

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ TIME ?= time
3434
METAFILES := \
3535
ART.md \
3636
CITE-THIS-LIBRARY.md \
37+
CITING-SOURCES.md \
3738
CODINGSTYLE.md \
3839
CONTRIBUTING.md \
3940
CONTRIBUTORS.md \
@@ -49,7 +50,7 @@ METAFILES := \
4950
STATEMENT-OF-INCLUSION.md \
5051
SUMMARY.md \
5152
TEMPLATE.lagda.md \
52-
USERS.md \
53+
USERS.md
5354

5455
.PHONY: agdaFiles
5556
agdaFiles:

TEMPLATE.lagda.md

-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,3 @@ concept-subconcept = ...
5050

5151
- An instructive example of a file with the expected structure is
5252
[`order-theory.galois-connections`](https://raw.githubusercontent.com/UniMath/agda-unimath/master/src/order-theory/galois-connections.lagda.md).
53-
54-
## References
55-
56-
1. Univalent Foundations Project, _Homotopy Type Theory – Univalent Foundations
57-
of Mathematics_ (2013) ([website](https://homotopytypetheory.org/book/),
58-
[arXiv:1308.0729](https://arxiv.org/abs/1308.0729))

book.toml

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ output-file = "docs/concept_index.json"
5151
mathswitch-template = "https://mathswitch.xyz/concept/Wd/{wikidata_id}"
5252
wikidata-template = "https://www.wikidata.org/entity/{wikidata_id}"
5353

54+
[preprocessor.citations]
55+
command = "python3 ./scripts/preprocessor_citations.py"
56+
bibtex_file = "references.bib"
57+
citation_style = "alpha"
58+
citation_label_style = "custom_alpha"
59+
error_on_unmatched_keys = true
60+
before = [ "git-metadata" ]
61+
5462
[output.linkcheck]
5563
follow-web-links = false
5664

@@ -62,6 +70,7 @@ additional-css = [
6270
"website/css/Agda.css",
6371
"website/css/Agda-highlight.css",
6472
"website/css/agda-logo.css",
73+
"website/css/bibliography.css",
6574
"theme/catppuccin.css",
6675
"theme/catppuccin-admonish.css",
6776
"theme/pagetoc.css",

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
python = pkgs.python38.withPackages (p: with p; [
2525
# Keep in sync with scripts/requirements.txt
2626
# pre-commit <- not installed as a Python package but as a binary below
27+
pybtex
2728
requests
2829
tomli
2930
]);

references.bib

+606
Large diffs are not rendered by default.

scripts/generate_main_index_file.py

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def generate_index(root_path, header):
109109
- [File template](TEMPLATE.lagda.md)
110110
- [The library coding style](CODINGSTYLE.md)
111111
- [Guidelines for mixfix operators](MIXFIX-OPERATORS.md)
112+
- [Citing sources](CITING-SOURCES.md)
112113
- [Citing the library](CITE-THIS-LIBRARY.md)
113114
- [Library contents](SUMMARY.md)
114115
- [Art](ART.md)

0 commit comments

Comments
 (0)