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

Spaces in \text{} is not preserved when there is a single or zero char or numbers/dots #150

Open Enter-tainer opened 3 months ago

Enter-tainer commented 3 months ago
#mi(`A\text{ B }C`)

renders to image

In mathjax it is image

Enter-tainer commented 3 months ago

This also happens when there is no char in \text

image

image

Enter-tainer commented 3 months ago

image

Enter-tainer commented 3 months ago

This can be extremely hard to fix. https://discord.com/channels/1054443721975922748/1225462045583872083

In short, when layouting texts in math, typst has special code path for:

  1. single letter
  2. numbers And spaces are eaten sometimes.

https://github.com/typst/typst/blob/ffc9570c643540282d35dfe3075567c1200e4171/crates/typst/src/math/ctx.rs#L193

Enter-tainer commented 3 months ago

The tricky part is that this happens in layout stage, where everything is flattened. It's impossible to tell which Text comes from content block and whch text comes from math.

Enter-tainer commented 3 months ago

Maybe we can switch to strings for simple \text and textmath for complex ones? cc @OrangeX4 Although I don't know if strings can fix this problem

OrangeX4 commented 3 months ago

I think this can work, which means we need to first check if there are any special characters like the dollar sign $ inside \text{}, and then choose to convert them as string or content.