Skip to content

Commit e8cc9ff

Browse files
authored
efilrst:0.1.0 (#906)
1 parent 8748069 commit e8cc9ff

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Joan Marcè i Igual
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Typst efilrst
2+
A simple referenceable list library for Typst. If you ever wanted to reference elements in a list by a key, this library is for you. The name comes from "reflist" but sorted alphabetically because we are not allowed to use descriptive names for packages in Typst 🤷🏻‍♂️.
3+
4+
## Example
5+
6+
```typst
7+
8+
#import "@preview/efilrst:0.1.0" as efilrst
9+
#show ref: efilrst.show-rule
10+
11+
#efilrst.reflist(
12+
[My cool constraint A],<c:a>,
13+
[My also cool constraint B],<c:b>,
14+
[My non-refernceable constraint C],
15+
list_style: "C1)",
16+
ref_style: "C1",
17+
name: "Constraint"
18+
)
19+
20+
See how my @c:a is better than @c:b.
21+
```
22+
23+
This generates the following output:
24+
25+
![Example of the typst output. The last sentence reads "See how my Constraint C1 is better than Constraint C2"](img/image.png)
26+
27+
28+
## License
29+
30+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
31+
32+
## Changelog
33+
34+
### 0.1.0
35+
36+
- Initial release
37+
38+
39+
15.6 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#import "../src/lib.typ" as efilrst
2+
3+
#show ref: efilrst.show-rule
4+
5+
6+
#efilrst.reflist(
7+
[My cool constraint A],<c:a>,
8+
[My also cool constraint B],<c:b>,
9+
[My non-refernceable constraint C],
10+
list-style: "C1)",
11+
ref-style: "C1",
12+
name: "Constraint"
13+
)
14+
15+
See how my @c:a is better than @c:b.
16+
21.9 KB
Loading
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#let reflist(..children, name: "", list-style: "1)", ref-style: "1") = {
2+
// Gather children in body-label pairs
3+
let childrenArray = children.pos()
4+
let childrenPairs = ()
5+
6+
for (n, val) in childrenArray.enumerate() {
7+
if (type(val) == content) {
8+
childrenPairs.push((val, none))
9+
} else if (type(val) == label and n > 0) {
10+
let (body, lbl) = childrenPairs.last()
11+
childrenPairs.last() = (body, val)
12+
}
13+
}
14+
15+
// Insert a metadata to be labeled
16+
let children = childrenPairs.enumerate().map(
17+
((n, (body, lbl))) => if (type(lbl) == label) {
18+
let num_text = numbering(ref-style, n+1)
19+
let m = metadata((reflist_type: "reflist", reflist_n: num_text, reflist_name: name))
20+
[#body#m#lbl]
21+
}
22+
else [
23+
#body
24+
]
25+
)
26+
27+
enum(numbering: list-style, ..children)
28+
}
29+
30+
31+
#let show-rule(it) = {
32+
if (it.element != none
33+
and it.element.func() == metadata
34+
and type(it.element.value) == dictionary
35+
and it.element.value.at("reflist_type", default: none) == "reflist") {
36+
let itv = it.element.value
37+
let sup = if (it.supplement != auto) { it.supplement } else { itv.reflist_name }
38+
link(it.element.location(), [#sup #itv.reflist_n])
39+
} else {
40+
it
41+
}
42+
}
43+
44+
45+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "efilrst"
3+
version = "0.1.0"
4+
entrypoint = "src/lib.typ"
5+
authors = ["Joan Marcè i Igual <@jmigual>"]
6+
license = "MIT"
7+
repository = "https://github.com/jmigual/typst-efilrst"
8+
keywords = ["typst", "list", "referenceable"]
9+
compiler = "0.11.0"
10+
description = "A simple referenceable list library for typst."
11+
exclude = ["examples/*", "img/*"]

0 commit comments

Comments
 (0)