Skip to content

Commit e9bf6a2

Browse files
authored
alexandria:0.2.2 (#3641)
1 parent 15b1cac commit e9bf6a2

File tree

14 files changed

+5852
-0
lines changed

14 files changed

+5852
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
<details>
11+
<summary>Migration guide from v0.1.x</summary>
12+
13+
<!-- Write migration guide here -->
14+
15+
</details>
16+
17+
### Added
18+
19+
### Changed
20+
21+
### Deprecated
22+
23+
### Removed
24+
25+
### Fixed
26+
27+
### Security
28+
29+
## [0.2.2] - 2025-12-12
30+
31+
### Added
32+
- Math markup embedded in references is now rendered correctly
33+
- Alexandria now supports footnote bibliography styles
34+
35+
### Changed
36+
- Improvements in the manual thanks to [alyst](https://github.com/alyst/)
37+
- Update the Hayagriva version used by the plugin from 0.8.1 to 0.9.1, fixing various bugs and bringing Alexandria in line with Typst 0.14.
38+
- Automated tests no longer run on 0.12 and 0.13 since bugfixes between Hayagriva 0.8 and 0.9 mean that older Typst and new Alexandria no longer match exactly. Alexandria should still be compatible with Typst 0.12+.
39+
- Errors while parsing a bibliography file now contain more detailed information on the location of the error. The messages are in line with what the native bibliography reports, except that the error is reported inside the package, not in the bibliography file.
40+
41+
## [0.2.1] - 2025-07-08
42+
43+
### Changed
44+
- update the Hayagriva version used by the plugin from 0.8.0 to 0.8.1, fixing various bugs
45+
46+
## [0.2.0] - 2025-04-23
47+
48+
### Added
49+
- `citegroup` added, which allows creating collapsed citations
50+
51+
### Changed
52+
- the structure in which config data is stored has changed: the state now has `prefixes.at(..).citations` instead of `prefixes.citations.at(..)`. If you use the (internal) functions of the `alexandria.hayagriva` module directly, this is a BREAKING change.
53+
- `get-citation-index()` is now `get-citation-info()` and returns a dictionary with `index` and `group`. If you use the (internal) functions of the `alexandria.hayagriva` module directly, this is a BREAKING change.
54+
- serialization inside the plugin has been simplified
55+
- during serialization, link bodies are no longer wrapped into text elements. If you use the (internal) functions of the `alexandria.hayagriva` module directly, this is a BREAKING change.
56+
57+
### Fixed
58+
- links now don't span whole citations, but only the parts that would be links in vanilla Typst
59+
- `cite(form: none)` is now supported
60+
61+
## [0.1.3] - 2025-03-13
62+
63+
### Added
64+
- Hayagriva's "transparent" content is now supported, enabling citation supplements
65+
66+
### Changed
67+
- `get-bibliography` now accepts `auto` as a parameter if there is only one bibliography
68+
69+
### Fixed
70+
- citations' supplements (such as `[1, p. 42]` instead of `[1]`) are no longer ignored
71+
72+
## [0.1.2] - 2025-03-08
73+
74+
### Added
75+
- support for `bytes` as a bib or csl file parameter, to be up-to-date with Typst 0.13's `bibliography()` API
76+
77+
## [0.1.1] - 2025-02-12
78+
79+
### Added
80+
- `load-bibliography` that stores bib data for later retrieval
81+
- `get-bibliography` that retrieves the data
82+
- `render-bibliography` that renders the bib data
83+
- add details (type, title, author, ...) to data available for bibliography users
84+
- add support for custom CSL styles loaded from files
85+
86+
### Fixed
87+
- fixed a deprecation warning when running Typst 0.13
88+
- split bibliographyx into load, get and render parts
89+
90+
## [0.1.0] - 2025-02-06
91+
92+
### Added
93+
94+
- plugin for rendering references and citations
95+
- Typst wrapper for
96+
- collecting citations
97+
- calling the plugin
98+
- processing its results (rendering structured data into styled content)
99+
- Tests for IEEE and APA references in English and German (APA tests are deactivated to to something that's probably a Typst bug)
100+
101+
102+
[Unreleased]: https://github.com/SillyFreak/typst-alexandria/compare/v0.2.2...HEAD
103+
[0.2.2]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.2.2
104+
[0.2.1]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.2.1
105+
[0.2.0]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.2.0
106+
[0.1.3]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.3
107+
[0.1.2]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.2
108+
[0.1.1]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.1
109+
[0.1.0]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2024 Clemens Koza
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Alexandria
2+
3+
This package provides an alternative to the built-in bibliography to allow a single document to have multiple bibliographies.
4+
5+
This package currently has a few limitations, mostly around how styling applies differently between the built-in bibliography and Alexandria.
6+
7+
## Getting Started
8+
9+
To add this package to your project, use this:
10+
11+
```typ
12+
#import "@preview/alexandria:0.2.2": *
13+
14+
#show: alexandria(prefix: "x:", read: path => read(path))
15+
16+
...
17+
18+
#bibliographyx(
19+
"bibliography.bib",
20+
// title: auto is not yet supported so it needs to be specified
21+
title: "Bibliography",
22+
)
23+
```
24+
25+
<picture>
26+
<source media="(prefers-color-scheme: dark)" srcset="./thumbnail-dark.svg">
27+
<img src="./thumbnail-light.svg">
28+
</picture>
29+
30+
## Usage
31+
32+
See the [manual](docs/manual.pdf) for details.
33+
34+
## License
35+
36+
Parts of the Rust plugin that interfaces with the [Hayagriva](https://github.com/typst/hayagriva) citation library are based on [typst-library's `bibliography.rs`](https://github.com/typst/typst/blob/26e65bfef5b1da7f6c72e1409237cf03fb5d6069/crates/typst-library/src/model/bibliography.rs). Likewise, the example bibliographies are taken or adapted from [typst-dev-assets' `works.bib`](https://github.com/typst/typst-dev-assets/blob/1dba4bea22e5e19597fbf5f321b047ff7626e2d0/files/bib/works.bib). Both are licensed from Typst's authors under the Apache License 2.0.
37+
38+
The example CSL style [`ieee.csl`](https://github.com/citation-style-language/styles/blob/fd6cb3e81762055d107839c3c288c359985f81c8/ieee.csl) is taken from the [CSL project](https://citationstyles.org/) who provide it under the [Creative Commons Attribution-ShareAlike 3.0 Unported license](https://creativecommons.org/licenses/by-sa/3.0/).
304 KB
Binary file not shown.
24.6 KB
Binary file not shown.
4.53 MB
Binary file not shown.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#let _p = plugin("alexandria.wasm")
2+
3+
#let names = {
4+
// Typst 0.13: `cbor.decode` is deprecated, directly pass bytes to `cbor` instead
5+
let decode = if sys.version < version(0, 13, 0) { cbor.decode } else { cbor }
6+
7+
decode(_p.names())
8+
}
9+
10+
#let read(
11+
sources,
12+
full,
13+
style,
14+
locale,
15+
citations,
16+
) = {
17+
// Typst 0.13: `cbor.decode` is deprecated, directly pass bytes to `cbor` instead
18+
let decode = if sys.version < version(0, 13, 0) { cbor.decode } else { cbor }
19+
20+
let config = cbor.encode((sources: sources, full: full, style: style, locale: locale, citations: citations))
21+
decode(_p.read(config))
22+
}
23+
24+
#let render(body, keys: none, ..transparent-contents) = {
25+
assert.eq(transparent-contents.named().len(), 0, message: "no named arguments allowed")
26+
let transparent-contents = transparent-contents.pos()
27+
let formatted(fmt) = it => {
28+
set text(style: "italic") if fmt.font-style == "italic"
29+
// TODO this is an absolute weight and not an offset
30+
set text(weight: "bold") if fmt.font-weight == "bold"
31+
set text(weight: "light") if fmt.font-weight == "light"
32+
if fmt.font-variant == "small-caps" {
33+
it = smallcaps(it)
34+
}
35+
if fmt.text-decoration == "underline" {
36+
it = underline(it)
37+
}
38+
if fmt.vertical-align == "sup" {
39+
it = h(0pt, weak: true) + super(it)
40+
} else if fmt.vertical-align == "sub" {
41+
it = h(0pt, weak: true) + sub(it)
42+
}
43+
it
44+
}
45+
46+
let inner(body) = {
47+
if type(body) == array {
48+
body.map(inner).join()
49+
} else if "text" in body {
50+
let body = body.text
51+
show: formatted(body)
52+
body.text
53+
} else if "elem" in body {
54+
let body = body.elem
55+
show: it => {
56+
if "entry" in body.meta {
57+
assert.ne(keys, none, message: "Alexandria: internal error: citation keys are missing")
58+
assert(body.meta.entry < keys.len(), message: "Alexandria: internal error: unmatched key in citegroup")
59+
let entry = keys.at(body.meta.entry)
60+
it = link(entry, it)
61+
}
62+
it
63+
}
64+
// TODO handle body.display when present
65+
inner(body.children)
66+
} else if "link" in body {
67+
let body = body.link
68+
show: formatted(body)
69+
link(body.url, body.text)
70+
} else if "markup" in body {
71+
eval(body.markup, mode: "math")
72+
} else if "transparent" in body {
73+
let body = body.transparent
74+
show: formatted(body)
75+
assert(body.cite-idx < transparent-contents.len(), message: "Alexandria: internal error: unmatched transparent content")
76+
transparent-contents.at(body.cite-idx)
77+
} else {
78+
set text(red)
79+
repr(body)
80+
}
81+
}
82+
inner(body)
83+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#let locale() = {
2+
let locale = text.lang
3+
if text.region != none { locale += "-" + text.region }
4+
locale
5+
}
6+
7+
#let csl-to-string(csl) = {
8+
if type(csl) in (str, bytes) { return csl }
9+
10+
let csl = repr(csl).slice(1, -1)
11+
assert.ne(csl, "..", message: "only named CSL styles can be converted to strings")
12+
csl
13+
}

0 commit comments

Comments
 (0)