Kolaru / MathTeXEngine.jl

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

ℝ and similar are not supported? #49

Closed davibarreira closed 2 years ago

davibarreira commented 2 years ago

I've tried using:

generate_tex_elements(L"\mathbb{R}")

And I get an error:

ArgumentError: font modifier bb not supported for the current font family.

If I try to use the unicode directly, it does seem to return the correct character. But when I try to visualize it in the screen, I get a blanket square, like if the character does not exist for that font.

TheCedarPrince commented 2 years ago

Can confirm that I get this error as well given a L"" string like: L"ℝ"

image

That square appears which @davibarreira was discussing. Further if I try generate_tex_elements per Davi, I get that error as well

davibarreira commented 2 years ago

@Kolaru , do you have any idea why this might be happening? I'm willing to try to fix it :) My guess is that this is actually an issue with CMU font.

Kolaru commented 2 years ago

There are two problems.

First, the canonical form for these commands is not defined. Both version should be parse the same way, but they are not:

julia> texparse("ℝ")
TeXExpr :expr
└─ TeXExpr :symbol
   └─ 'ℝ'

julia> texparse(L"\mathbb{R}")
TeXExpr :expr
└─ TeXExpr :font
   ├─ :bb
   └─ TeXExpr :char
      └─ 'R'

This normalization is done by adding the rule in command_registration.jl. There are some more details about the concept in src/parser/README.md.

Then, the layout system needs to know which font and charcter it needs to grab for it. For these, the correct charcters need to be found in the many font files of the CM family, added to assets/ and loaded.

I think the easiest representation is TeXExpr(:symbol, 'ℝ'), then adding the char data in src/engine/computer_modern_data.jl would be enough.

On the other hand, that's a bunch of new rules, so if the characters are stored in a reasonnable way in their own font, using the font modifier system may make more sense.

Kolaru commented 2 years ago

It is now supported if you use unicode input.

\mathbb{R} is not there yet though.