Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a new framework for defining aliases, i.e. symbols that copy other symbols, and uses that for all of the previously duplicated symbols in
sym
.We don't intend to have a lot of these, but for the ones we do have, having a system like this is a big improvement to maintainability.
As a good illustration, this PR automatically adds the
arrow
variant fromplus.circle
toxor
, which seems to have previously been overlooked.Guide to creating Aliases
There are two types of aliases:
let alias = symbol(a.b.c)
in typst.let alias = a.b.c
in typst.A shallow alias is declared with
A deep alias is the same, but additionally ends with
.*
.Note that this isn't quite like a glob pattern, since e.g.
a.b.*
also matchesa.b
itself.For some examples, see the diff of
sym.txt
.About the Implementation
Properly handling aliases like
top @= tack.b
is a bit difficult since modifiers are commutative.The implementation I wrote uses a fast-path prefix check first and then, if that fails, a slower and heavily allocating algorithm that goes through all modifiers one-by-one.
That way, an alias
a @= b.d
for a symbolb
with a variant.c.d
correctly copies that toa.c
.For the current symbols, the fast path would have been enough, but I didn't want to sacrifice correctness; This could otherwise come back to haunt us later.
And since the number of aliases will most likely be staying quite low, such a slow and inefficient fallback should be fine.
Shallow vs Deep Aliases in
sym
The rules by which I decided the kind of alias for the pre-existing duplicates are basically the following:
nabla
) This is to stay open to the possibility of adding variants to it later.Of course, as mentioned above,
xor
is a bit of an exception since it was missing one of the variants ofplus.circle
.