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

Correct `\mathbf` Rendering to Regular Fonts #142

Closed xiaodong-hu closed 7 months ago

xiaodong-hu commented 7 months ago

Hi, I found that that both \mathbf . and \mathbf{...} cannot be correctly rendered in desired form as in LaTeX (bold AND regular). For example,

#import "@preview/mitex:0.2.2": *

#mitext(`Reciprocal vector is $\mathbf G$ or $\mathbf{G}$`)

gives 2024-03-20_14-13

But in LaTeX, it should be 2024-03-20_14-15

NOTE: \bm (as well as \boldsymbol(please also add support for this command)) behaves different from \mathbf!


And here is one more tricky thing:

See https://tex.stackexchange.com/questions/294561/using-textbf-vs-mathbf-in-math-mode. Precisely, \mathbf{...} and \textbf{...} are different in LaTeX, in that \mathbf{...} will remove ALL blank spaces within its arguments. So probably a more correct rendering is to parse, for example, for the LaTeX code:

$\sum_{i\in\mathcal I}\mathbf{Op With Space}=\text{blablabla}$

2024-03-20_15-10

as the Typst code:

$ sum_(i in cal(I))bold(#"Op With Spaces".replace(" ", ""))="blablabla" $ 

2024-03-20_15-18

I think this clearly demonstrate how to fix the \mathbf rendering problem : )

Thanks for your help!

Enter-tainer commented 7 months ago

in that \mathbf{...} with remove ALL blank spaces within its arguments.

This is tricky. How about other spaces in unicode? Blindly removing all spaces might be wrong in some cases. I wonder where can we get a spec describing the behavior of mathbf

Enter-tainer commented 7 months ago

For now we can first fix the font variant problem and deal with spaces later

Enter-tainer commented 7 months ago

https://github.com/mitex-rs/mitex/blob/919336210ad4fa45b4823d302b6819625bdf29c4/packages/mitex/specs/latex/standard.typ#L124

Enivex commented 7 months ago

in that \mathbf{...} with remove ALL blank spaces within its arguments.

This is tricky. How about other spaces in unicode? Blindly removing all spaces might be wrong in some cases. I wonder where can we get a spec describing the behavior of mathbf

Math isn't whitespace dependent in LaTeX. The difference here is that \textbf{} typesets as regular bold text (which does take whitespace into account, but only a single one if there are consecutive ones), while \mathbf{} is for typesetting with bold math symbols.

\[
    |\mathbf{ Hello   World }|          |\textbf{ Hello   World }|
\]

results in image

OrangeX4 commented 7 months ago

Fixed in 0.2.3