mitex-rs/mitex

Correct `\mathbf` Rendering to Regular Fonts

Closed this issue · 5 comments

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!

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

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

mathbf: define-cmd(1, alias: "bold"),

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

Fixed in 0.2.3