Kolaru / MathTeXEngine.jl

A latex math mode engine in pure Julia.
MIT License
97 stars 19 forks source link

`\mathbf` produces bolditalic instead of bold (LaTeX vs ISO standard) #94

Open manuelbb-upb opened 1 year ago

manuelbb-upb commented 1 year ago

Currently, L"\mathbf{x} gets parsed to TeXChar 'x' [index 89 in NewComputerModern - 10 Bold Italic]. This deviates from the standard LaTeX behavior, where we would expect an upright bold character.

In fact, the LaTeX package unicode-math offers options (math-style and bold-style) to conform to different notational standards. MathTeXEngine currently mostly adheres to the "ISO" style (except for Greek letters, as per https://github.com/Kolaru/MathTeXEngine.jl/issues/87). I guess, this is due to _default_font_mapping[:char]=:italic? I think, in the long run it would be great to also enable the user to choose either norm (like unicode-math does) or be consistent with the LaTeX style.

I tried

__default_font_modifiers = deepcopy(_default_font_modifiers)
__default_font_modifiers[:bf] = Dict(
    :italic => :bold, 
    :regular => :bold
)
MYFONT = FontFamily(
        _new_computer_modern_fonts,
        _default_font_mapping,
        __default_font_modifiers,
        _symbol_to_new_computer_modern,
        13,
        0.0375
)

as a quick hack, which indead works as expected: generate_tex_elements(L"\mathbf{x}", MYFONT)[1][1] gives TeXChar 'x' [index 89 in NewComputerModern - 10 Bold]. Unfortunately, it seems that I cannot pass my MYFONT down to be used with labels in Makie.

aniolm9 commented 9 months ago

Another hack that I'm using is generate_tex_elements(L"\mathrm{\mathbf{x}}"), but I agree that this should be fixed.