The physica package provides support for Dirac bra-ket notation for states, inner products etc. in e.g. quantum mechanics.
Would it be possible to define my own functionality such that, when I write:
$
|a>, <b|, <a | b>, <n | H | m>, < H >
$
Typst would translate it to:
$
bra(a), ket(b), braket(a, b), matrixelement(n, H, m), expval(H)
$
I could imagine that it’s possible to do this. if you look at repr($ ... $) you can see that you have all the information that you’d need available – but the code to do it likely wouldn’t be pretty. Here’s an example of a smaller syntactical feature that I did:
… and the transformation necessary for bra-ket syntax would be more complex.
I can’t implement this right now, but maybe either you’re inspired by that other post, or someone else is motivated
I think you should think of other alternatives. Typst doesn’t natively support this well, but exposes equations in a form where you can transform them a little bit.
In your case, do you want to keep using </> for less than/greater than too? The ambiguity vs other operators is a problem for this syntax.
Here is an alternative for consideration or as starting point.
This one says: We sacrifice the >> and << operators and just overwrite them with the braket angles, to maybe make a custom syntax that we like.
#show sym.lt.double: math.angle.l // should be scoped to math.equation
#show sym.gt.double: math.angle.r
$<<a|b>> <= <<a|X|b>>$
That’s one way to think about custom syntax - in this case it’s just a custom shorthand - just like bra as a function is another good shorthand. And I just replaced a symbol, so I don’t have to think about how to try to match pairs of operators.
As long, that the body of the bra/ket/braket is not too high, it layouts nicely.
And you are right - I did think about that the functionality requested in my original question is probably ill-advised, since this would interfere with e.g. greater than/less than or just vertical bars in isolation.