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

Incorrect LaTeX rendering #317

Closed
bmxam opened this issue May 27, 2024 · 8 comments
Closed

Incorrect LaTeX rendering #317

bmxam opened this issue May 27, 2024 · 8 comments

Comments

@bmxam
Copy link

bmxam commented May 27, 2024

Hi,

I am trying to render a LaTeX formulae containing an integral, using Luxor. I've tried on two different computers, and obtained two different results, but never the correct one. Is it an expected behaviour? Thanks!

using Luxor
using MathTeXEngine

d = @png begin
    fontsize(20)
    text(L"\int_{\Gamma} \nabla f dA", O)
end 200 100 "mwe.png"

display(d)

The result:
mwe

@cormullion
Copy link
Member

Hi! The first thing is to get the MathTeXEngine fonts installed correctly - then at least some of the characters will appear in the right font. I’ll try your example later today to see if it’s a Luxor or MathTeXEngine issue.

@bmxam
Copy link
Author

bmxam commented May 27, 2024

I see. How do you check that the MathTeXEngine fonts are correctly installed? I ran the Luxor LaTeX documentation example (see below). Everything seems at the right place but, indeed, the font seems a little bit "bad" to me.

luxor-drawing-170301_552

@bmxam
Copy link
Author

bmxam commented May 27, 2024

On a linux machine, where the fonts of MathTeXEngine have been copied to ~/.local/share/fonts, I obtain the following result:
mwe

@cormullion
Copy link
Member

That's the first step. :) Now, I wonder whether MathTeXEngine is going to do a large integral anyway. To debug it:

using MathTeXEngine
generate_tex_elements(L"\int_{\Gamma} \nabla f dA")
6-element Vector{Any}:
 (TeXChar '∫' [index 5930 in NewComputerModern Math - Regular], [0.0, 0.0], 1.0)
 (TeXChar 'Γ' [index 374 in NewComputerModern Math - Regular], [-0.014700007624924183, -1.36899995803833], 0.6)
 (TeXChar '∇' [index 842 in NewComputerModern Math - Regular], [0.9990000128746033, 0.0], 1.0)
 (TeXChar 'f' [index 71 in NewComputerModern - 10 Italic], [1.8320000171661377, 0.0], 1.0)
 (TeXChar 'd' [index 69 in NewComputerModern - 10 Italic], [2.1389999389648438, 0.0], 1.0)
 (TeXChar 'A' [index 34 in NewComputerModern - 10 Italic], [2.6500000953674316, 0.0], 1.0)

and it looks like that "∫" glyph is scaled at 1.0... :( But I might be wrong.

Is that expected behaviour?

Well, yes... Support for LaTeX is not really very good, partly because text handling in Luxor/Cairo generally isn't very good, and partly because Cairo.jl doesn't really have maintainers any more (eg JuliaGraphics/Cairo.jl#357).

To be honest, I'd suggest either:

  • saving LaTex as an SVG image and importing it

  • fiddling with textplace() (which is painful but sometimes it gets the job done):

d = @png begin
    textplace(
        "∫abΓ∇fda",
        O - (200, 0),
        [
            (size=120, face="NewCMMath-Regular", advance=false), #
            (size=40, face="NewComputerModern10-Regular", shift = -70, kern=20), # a
            (size=40, shift = 100, kern = 25), # b
            (size=50, kern = 5), # Γ
            (size=50, face="NewCMMath-Regular", kern=5), #
            (size=50, face="NewComputerModern10-Regular", ), # f
            (size=50, ), # d
            (size=50, ), # a
        ])
end 600 600 "mwe.png"

display(d)
Screenshot 2024-05-27 at 17 37 19

@bmxam
Copy link
Author

bmxam commented May 27, 2024

Thank you for your answer. I chose the LaTeX svg in the present case. It would be nice to have a "fallback" extension where the LaTeX would be compiled on-the-fly (it would require a proper install) and rendered. I might take a look at it some day.

@cormullion
Copy link
Member

Yes - would be good.

But full LaTeX support is probably out of scope for this “simple drawing package” 😂. Makie.jl is a possibility.

@GiggleLiu
Copy link
Contributor

GiggleLiu commented May 28, 2024

I also notice that YaoPlots.jl does not render correctly in today's presentation:
image

It is not related to MathTexEngine, all utf-8 code does not render (at least on Mac) I think.

I'd love to see a full latex support! It will be amazing.

@cormullion
Copy link
Member

I'll close this issue which looks like a MathTeXEngine issue. @GiggleLiu This might be a different issue - happy to investigate if you provide more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants