-
-
Notifications
You must be signed in to change notification settings - Fork 11
Symbol Aliases #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Symbol Aliases #27
Conversation
This avoids it visually colliding with the deprecation annotation from typst#19.
This comment has been minimized.
This comment has been minimized.
This was discussed on Discord and there was no consensus on whether an alias system is desirable. I'm not sure what we should do with this PR for now. We can probably wait until Typst 0.13.0 is released to re-open the discussion and finally decide whether we want this for now. |
Note that if/when #62 is accepted, Edit: done |
This one was supposed to be singular, since it's one particular variant that serves as the basis of the alias.
I reverted |
@@ -552,8 +546,7 @@ or ∨ | |||
.curly ⋎ | |||
.dot ⟇ | |||
.double ⩔ | |||
xor ⊕ | |||
.big ⨁ | |||
xor @= plus.o.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also be noted that this adds xor.arrow
.
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
.