mitex-rs / mitex

LaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
https://mitex-rs.github.io/mitex/tools/underleaf.html
Apache License 2.0
240 stars 8 forks source link

feat: add support for `\(\)` and `\[\]` instead of `$`'s #125

Closed Tweoss closed 5 months ago

Tweoss commented 5 months ago

Not too sure on some of the organization, particularly treating \( and \[ as dollars syntactically.

#import "packages/mitex/mitex.typ": *

= Converted

#let test_text = "
  \\(1 + 2\\)
  \\[1 + 2\\]
"

#raw(mitex-convert(mode: "text", test_text))
= Rendered

#eval(
  mitex-convert(mode: "text", test_text), mode: "markup", scope: mitex-scope,
)

gives

image

Closes #124

Myriad-Dreamin commented 5 months ago

I'm not sure whether someone would like to override the command \( by renewcommand, in which we will fail since we treat \( as BeginMathInline rather than a generic command. Similarly, so do \), \[, and \]. But that is an edge case, so overall it looks good to me.

Tweoss commented 5 months ago

Thanks for the feedback! I added two tokens TokenStartMath and TokenEndMath, which seems to be the minimal necessary additions to clearly distinguish what's being used. (as opposed to adding StartMathDisplay and StartMathInline, which seemed inconsistent with the treatment of $ and $$ as one token)

Please let me know if there's anything else you see that could be improved

Myriad-Dreamin commented 5 months ago

I have run tests and benchmarks locally, now the PR looks well to me.

This PR still lacks of an important thing, that adds parsing tests to the mitex-parser for \(..\) and \[..\], but I forgot to tell you that.

I will push some parsing tests in later PR by myself.