Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ product of two vectors.

![Result of example code (page 1).](assets/example-1.svg)
![Result of example code (page 2).](assets/example-2.svg)

## Development

Create a symlink to more easily develop your package changes:

```
DEV_TEMPLATE=equate
DEV_VERSION=0.3.2

mkdir -p ~/.cache/typst/packages/preview/$DEV_TEMPLATE
rm -R ~/.cache/typst/packages/preview/$DEV_TEMPLATE/$DEV_VERSION
ln -s $PWD ~/.cache/typst/packages/preview/$DEV_TEMPLATE/$DEV_VERSION
```
16 changes: 9 additions & 7 deletions src/equate.typ
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
// State for tracking whether we're in a nested equation.
#let nested-state = state("equate/nested-depth", 0)

// Show rule necessary for referencing equation lines, as the number is not
// stored in a counter, but as metadata in a figure.
#let equate-ref(it) = {
/// Function for show rule necessary for referencing equation lines, as the number is not
/// stored in a counter, but as metadata in a figure.
/// - it (ref): the reference
/// - numbering-function ((ref) => (..int) => string): Function that takes a ref of which the numbering should be evaluated and returns a numbering function.
#let equate-ref(it, numbering-function) = {
if it.element == none { return it }
if it.element.func() != figure { return it }
if it.element.kind != math.equation { return it }
Expand Down Expand Up @@ -50,7 +52,7 @@
let suffix-start = it.element.numbering.codepoints().rev().position(c => c in counting-symbols)
it.element.numbering.slice(prefix-end, if suffix-start == 0 { none } else { -suffix-start })
} else {
it.element.numbering
numbering-function(it)
},
..nums
)
Expand Down Expand Up @@ -555,12 +557,12 @@
// rule instead of the equation rule.
if type(body) == label {
return {
show ref: equate-ref
show ref: it => equate-ref(it, ref => ref.element.numbering)
ref(body)
}
} else if body.func() == ref {
return {
show ref: equate-ref
show ref: it => equate-ref(it, ref => ref.element.numbering)
body
}
}
Expand Down Expand Up @@ -729,7 +731,7 @@
}

// Add show rule for referencing equation lines.
show ref: equate-ref
show ref: it => equate-ref(it, ref => ref.element.numbering)

equate-state.update(n => n + 1)
body
Expand Down
2 changes: 1 addition & 1 deletion src/lib.typ
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#import "equate.typ": equate, share-align
#import "equate.typ": equate, share-align, equate-ref