Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Enter-tainer opened this issue Apr 4, 2024 · 6 comments
Labels

Comments

@Enter-tainer
Copy link
Member

#mi(`A\text{ B }C`)

renders to
image

In mathjax it is
image

@Enter-tainer Enter-tainer changed the title Spaces in \text{} when there is a single char is not preserved Spaces in \text{} is not preserved when there is a single or zero char Apr 4, 2024
@Enter-tainer
Copy link
Member Author

This also happens when there is no char in \text

image

image

@Enter-tainer Enter-tainer changed the title Spaces in \text{} is not preserved when there is a single or zero char Spaces in \text{} is not preserved when there is a single or zero char or numbers/dots Apr 4, 2024
@Enter-tainer
Copy link
Member Author

image

@OrangeX4 OrangeX4 added help wanted Extra attention is needed T Spec labels Apr 4, 2024
@Enter-tainer
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member

OrangeX4 commented Apr 4, 2024

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.

@OrangeX4 OrangeX4 removed the help wanted Extra attention is needed label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants