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
287 stars 10 forks source link

refactor: improve formula parser #131

Closed Myriad-Dreamin closed 7 months ago

Myriad-Dreamin commented 7 months ago

I have refactored the parser and added some tests for formulas.

During testing, I find a bug:

https://github.com/mitex-rs/mitex/blob/b85675ab1eba8774894948091432765fb433f1cc/crates/mitex/src/lib.rs#L1151-L1156

And two optional semantic errors to handle:

https://github.com/mitex-rs/mitex/blob/b85675ab1eba8774894948091432765fb433f1cc/crates/mitex/src/lib.rs#L1157-L1168

OrangeX4 commented 7 months ago

Now, in text mode, we translate $ a $ as #math.equation(block: false, $ a $); instead of using bare equation, to address the first bug. However, I'm not quite sure about the next two optional semantic errors, but they seem to be just edge cases. Should we not prioritize them for now?

Myriad-Dreamin commented 7 months ago

Now, in text mode, we translate $ a $ as #math.equation(block: false, $ a $); instead of using bare equation, to address the first bug.

Sounds great before we having taken all whitespace into control.

However, I'm not quite sure about the next two optional semantic errors, but they seem to be just edge cases. Should we not prioritize them for now?

You can do it now, but it is not urgent since they don't occur in regular document. In addition, this is not introduced by this PR and has stayed for a long time.

OrangeX4 commented 7 months ago

Ok, I've added formula check.