A Typst package enabling support for Unicode super and subscript characters in equations.
Usage
The package exposes the templatefunction supersubscripts
. It affects all math.equation
s by attaching every superscript and subscriptcharacter to the first nonspaceelement on its left.
#import "@preview/supersuboptimal:0.1.0": *
#show: supersubscripts
For all $(x,y)∈ℝ²$:
$
q := norm((x,y))₂ < 1
==> ∑ᵢ₌₁ⁿ q ⁱ < ∞
$
Because code like $x+yᶻ$
throws an “unknown variable” error, the package also exposes the function eq
, which inserts spaces before every superscript and subscriptcharacter and passing it on to math.equation
. This comes at the cost of missing syntaxhighlighting and codesuggestions in your IDE.
eq
accepts a raw
string as a positional parameter, and an argumentsink that’s passed onto math.equation
. Unless specified otherwise in the argumentsink, the resulting equation is typeset with block: true
if and only if the raw
also satisfied block: true
. eq
is automatically applied to every raw
with lang: "eq"
.
#eq(`0 = aᵇ`)
#eq(```
1 = x+yᶻ
```)
#eq(`2 = aᵇ`, block: true, numbering: "(1)")
```eq
3 = aᵇᶜ⁺ᵈ₃ₑ⁽ᶠ⁻ᵍ⁾ₕᵢ
```
Sometimes in mathematical writing, variables are decorated with an asterisk, e.g. $x^*$
. The character ꙳
can now be used, as well: $x꙳ = x^*$
.
Known issues

As mentioned above,
$aᵇ$
leads to an “unknown variable” error. As a workaround,$a ᵇ$
produces the same output, or you can use theeq
function described above. The first workaround also means I can’t reasonably implement topleft and bottomleft attachments. For example,
$a ³b$
is rendered like$attach(a, t: 3) b$
, rather than$a attach(b, tl: 3)$
.
 The first workaround also means I can’t reasonably implement topleft and bottomleft attachments. For example,

Multiple attachments are concatenated into one content without another pass of
equation
. For example,#eq(`0ˢⁱⁿ⁽ᵏ⁾`)
is equivalent to$0^(s i n "(" k ")")$
, rather than$0^sin(k)$
. I won’t fix this, because: Another pass of
equation
would cause performance issues at best, and infinite loops at worst.  If this were fixed, code such as
$e ˣ ʸ$
would undesirably produce an “unknown variablexy
” error.
 Another pass of

Let’s call a piece of content “small” if it consists of only a single nonseparated sequence of characters in Typst (internally, this is the distinction between the contentfunctions
sequence
andtext
). For instance,$1234$
and$a$
constitute “small” content, but$a b$
and$3a$
and$1+2+3+4+5$
do not.This package only runs on non“small” pieces of content. For example,
$sqrt(35²)$
still renders with the defaultUnicodecharacter and will look different from$sqrt(35^2)$
. On the other hand,$sqrt(a⁶)$
is rendered correctly. This is because35²
constitutes “small” content, buta⁶
does not.A workaround is implemented for “small” content immediately within an equation, i.e. not nested within another contentfunction. For example,
$7²$
renders the same as$7^2$
, even though it’s “small” content. 
Equations within other contentelements might trigger multiple showrulepasses, possibly causing performanceissues.