Skip to content

Commit 6e63334

Browse files
authored
alexandria:0.1.2 (#1963)
1 parent 2016d98 commit 6e63334

14 files changed

+5149
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.1.2] - 2025-03-08
30+
31+
### Added
32+
- support for `bytes` as a bib or csl file parameter, to be up-to-date with Typst 0.13's `bibliography()` API
33+
34+
## [0.1.1] - 2025-02-12
35+
36+
### Added
37+
- `load-bibliography` that stores bib data for later retrieval
38+
- `get-bibliography` that retrieves the data
39+
- `render-bibliography` that renders the bib data
40+
- add details (type, title, author, ...) to data available for bibliography users
41+
- add support for custom CSL styles loaded from files
42+
43+
### Fixed
44+
- fixed a deprecation warning when running Typst 0.13
45+
- split bibliographyx into load, get and render parts
46+
47+
## [0.1.0] - 2025-02-06
48+
49+
### Added
50+
51+
- plugin for rendering references and citations
52+
- Typst wrapper for
53+
- collecting citations
54+
- calling the plugin
55+
- processing its results (rendering structured data into styled content)
56+
- Tests for IEEE and APA references in English and German (APA tests are deactivated to to something that's probably a Typst bug)
57+
58+
59+
[Unreleased]: https://github.com/SillyFreak/typst-alexandria/compare/v0.1.2...HEAD
60+
[0.1.2]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.2
61+
[0.1.1]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.1
62+
[0.1.0]: https://github.com/SillyFreak/typst-alexandria/releases/tag/v0.1.0
+22
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.
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, such as not being able to collapse citations yet, but more general support is planned soon.
6+
7+
## Getting Started
8+
9+
To add this package to your project, use this:
10+
11+
```typ
12+
#import "@preview/alexandria:0.1.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/).
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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) = {
25+
if type(body) == array {
26+
body.map(render).join()
27+
} else if "text" in body {
28+
let body = body.text
29+
set text(style: "italic") if body.font-style == "italic"
30+
// TODO this is an absolute weight and not an offset
31+
set text(weight: "bold") if body.font-weight == "bold"
32+
set text(weight: "light") if body.font-weight == "light"
33+
show: it => {
34+
if body.font-variant == "small-caps" {
35+
it = smallcaps(it)
36+
}
37+
if body.text-decoration == "underline" {
38+
it = underline(it)
39+
}
40+
if body.vertical-align == "sup" {
41+
it = h(0pt, weak: true) + super(it)
42+
} else if body.vertical-align == "sub" {
43+
it = h(0pt, weak: true) + sub(it)
44+
}
45+
it
46+
}
47+
body.text
48+
} else if "elem" in body {
49+
let body = body.elem
50+
// TODO handle body.display when present
51+
render(body.children)
52+
} else if "link" in body {
53+
let body = body.link
54+
link(body.url, render(body.text))
55+
} else {
56+
set text(red)
57+
repr(body)
58+
}
59+
}
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)