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

LaTeX: MathTeXEngine 0.5.0, Luxor version 3.5.0 #241

Open
cormullion opened this issue Jul 28, 2022 · 18 comments
Open

LaTeX: MathTeXEngine 0.5.0, Luxor version 3.5.0 #241

cormullion opened this issue Jul 28, 2022 · 18 comments

Comments

@cormullion
Copy link
Member

MathTeXEngine version 0.5 changed their LaTeX code, so please could Luxor-LaTeXers check and report any issues with Luxor 3.5.0? Thanks!

@cormullion cormullion changed the title LaTeX: MathTeXEngine 0.5.0 hello, Luxor version 3.5.0 LaTeX: MathTeXEngine 0.5.0, Luxor version 3.5.0 Jul 28, 2022
@davibarreira
Copy link
Contributor

Ok, now I've found this issue. I'll try to check it during lunch. Have you already found any problems?

@cormullion
Copy link
Member Author

I think the font selection code doesn’t find the NewComputerModern Italic easily, and defaults to Regular.

@Kolaru
Copy link

Kolaru commented Aug 1, 2022

Each TeXChar carry its own (FreeType) font, so it should be possible to add a binding in Cairo.jl that can access it direclty using https://www.cairographics.org/manual/cairo-FreeType-Fonts.html

Similarly, now that MathTeXEngine use glyph indices directly, you would need https://www.cairographics.org/manual/cairo-text.html#cairo-show-glyphs that doesn't seem to be exported by Cairo.jl either right now. CairoMakie call into the C library directly so it doesn't have those problems.

I could restore TeXChar.represented_char as a quick hotfix (i.e. a unicode char instead of a glyph index in a specific font), it would give the wrong glyph for greek letters, integral and sum, but should otherwise work nicely.

@cormullion
Copy link
Member Author

Thanks. Ideally better font routines would be added to Cairo rather than to all the packages that depend on Cairo. I think more investigations are needed. Thanks for the excellent help, @Kolaru!

@cormullion
Copy link
Member Author

Work that needs to be done to support MathTeXEngine v0.5.0 correctly might include:

  • integrating GeometryBasics.jl into Luxor *
  • integrating FreeType(Abstraction).jl into Luxor
  • adding call interfaces to Cairo.jl functions for showing glyphs, extents, fonts, etc.
  • writing code to read TeXChar glyph indices from fonts and draw glyphs

( Luxor.jl is showing its age - it predates GeometryBasics.jl by some years 😃; perhaps it should be rewritten to use JuliaGeometry packages...)

I think this is a lot of work, so for now LaTex text setting is less than perfect.

@davibarreira
Copy link
Contributor

davibarreira commented Aug 4, 2022

Hey, @cormullion . Why does MathTeXEngine v0.5.0 requires such significant changes? I mean, more specifically, why GeometryBasics.jl?

@cormullion
Copy link
Member Author

I was looking at Julius' work here - https://github.com/JuliaPlots/Makie.jl/pull/2139/files# - it seems to need stuff from FreeType and GeometryBasics. MTXE now references the font glyphs directly, by index, rather than by Unicode. I'm no expert here, though! :)

@davibarreira
Copy link
Contributor

So, I took a look at the code to try to understand what was going on. Did the original fonts for the symbols change? In theory, the code I wrote for Luxor should work, as it get's the current font set by MathTeXEngine, and applies the fontface. Why doesn't it find the font anymore?

@cormullion
Copy link
Member Author

The main thing I noticed (not being a Latex user) is that the italic fonts weren't found when the documentation job was run. I'm guessing that the use of FreeTypeAbstraction.jl finds/uses font names differently.

Version 0.4 of MTXE returned, for ^n:

(TeXChar 'n' [U+006E in cmmi10 - Regular], [10.481249809265137, 0.34492188692092896], 0.6)

Version 0.5 of MTXE returned, for ^n:

(TeXChar 'n' [index 79 in NewComputerModern - 10 Italic], [10.489200115203857, 0.3878999948501587], 0.6)

The Cairo Toy Api's text() function is happy to select a font with Luxor.fontface("cmmi10"), but I'm not sure if it's happy with "NewComputerModern - 10 Italic" - but it would probably work OK if it received Luxor.fontface("NewCM10-Italic") though.

Perhaps we could use Luxor.settext and Luxor.setfont for all glyphs (not just the few you added), and work out how to select the fonts via setfont given strings like "NewComputerModern - 10 Italic".

The other issue is the use of glyph indices rather than represented_char -> Unicode. Code for this is probably already written somewhere (in MTXE and/or Makie). I don't know how I would do it other than by adding dependencies for FreeType and scanning the fonts for the indices.

@Kolaru
Copy link

Kolaru commented Aug 8, 2022

Did the original fonts for the symbols change?

Yes, I switch from the Computer Modern family (non unicode, a bunch of fonts for math symbols, weird glyph info in the font) to the New Computer Modern family (unicode, all symbols in a single font, but alternate glyph for some math symbols, requiring the glyph index business).

I don't think that GeometryBasics should be needed. The point type used for the position are from there, but that a mere detail I believe.

The other issue is the use of glyph indices rather than represented_char -> Unicode. Code for this is probably already written somewhere (in MTXE and/or Makie)

https://github.com/JuliaPlots/Makie.jl/pull/2139/files#diff-4c2354928757044a6b2d42b25e45db4aa14412f8a0367d3c28db496d62f6b64dR458-R463

This is it in the compat PR in Makie. I think the simpler way is probably to add a similar function to Cairo.jl and then use it there. I am not familiar with ccall so I can't promise anything, but I'll have a look next week-end if no one beats me to it.

@cormullion
Copy link
Member Author

cormullion commented Sep 19, 2022

If anyone has some spare time, please check the current master - I've tried to update it to find the fonts. Haven't yet addressed the glyph indices though...

I think it works on MacOS, but can't test it on other platforms...

@davibarreira
Copy link
Contributor

I was not able to figure it out :(

@cormullion
Copy link
Member Author

Thanks for looking anyway, @davibarreira ! It's difficult to get the right fonts on all platforms, and I'm seeing a strange vertical misalignment (eg i and π) which I can't currently explain. Also I broke the rotation... :(

Screenshot 2022-09-25 at 08 40 12

@Kolaru
Copy link

Kolaru commented Oct 2, 2022

Can you share the code snippet to produce the image ? That way I'll be able to do quicker tests :)

@cormullion
Copy link
Member Author

cormullion commented Oct 2, 2022

it's at http://juliagraphics.github.io/Luxor.jl/dev/howto/text/#Writing-LaTeX - my last attempt is on Luxor master...

@Kolaru
Copy link

Kolaru commented Oct 3, 2022

I made some progress in #244, but some stuff are still unclear.

@cormullion
Copy link
Member Author

That's great! Will follow the Cairo PR with great interest!

@RaulDurand
Copy link

Thanks for looking anyway, @davibarreira ! It's difficult to get the right fonts on all platforms, and I'm seeing a strange vertical misalignment (eg i and π) which I can't currently explain. Also I broke the rotation... :(

Screenshot 2022-09-25 at 08 40 12

How can I get variables written in italics as LaTeX? Currently the snipped produces non italics text.

@stale stale bot added the wontfix label Mar 17, 2024
@JuliaGraphics JuliaGraphics deleted a comment from stale bot Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants