schang412 / typst-whalogen

A port of LaTeX mhchem to Typst
Apache License 2.0
19 stars 2 forks source link

Add support for math mode in `ce()` blocks #8

Open Andrew-S-Rosen opened 3 months ago

Andrew-S-Rosen commented 3 months ago

I want to be able to do something like $\alpha + \beta \rightarrow \gamma$ in typst but currently the only way to do something like this is

#import "@preview/whalogen:0.2.0": ce

$ ce("#sym.alpha + #sym.beta -> #sym.gamma") $

However, this renders everything as text.

In general, I think ce() should support entering math mode when $ is supplied. Something like:

$ ce("$alpha$ + $beta$ -> $gamma$") $
#ce("$alpha$ + $beta$ -> $gamma$")

There are many other scenarios where it would be nice to be able to inject math, so this is really more of a general feature request.

For instance, one might want to put a math mode entity above an equilibrium arrow. Doing ce("NO3^∙ + NO ->[k_2] 2 NO2") results in a non-italicized $k_2$.

schang412 commented 3 months ago

This is more difficult to implement than other requested enhancements. Currently, we immediately drop into math mode and turn all the text upright. Not sure of a good workaround for this, will require some thought.

I’ll work on the other enhancements this weekend.

Andrew-S-Rosen commented 3 months ago

I agree. While I have an idea on how to do the others, this one escapes me. I figured I'd open it regardless though.

Thanks for your willingness to tackle the other ones!