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

Lower case Greek should be italic #26

Closed
AshtonSBradley opened this issue Aug 22, 2021 · 16 comments · Fixed by #40
Closed

Lower case Greek should be italic #26

AshtonSBradley opened this issue Aug 22, 2021 · 16 comments · Fixed by #40

Comments

@AshtonSBradley
Copy link

Not sure if this is a deliberate font choice, but there are some strange italicization results for greek versus roman characters in Makie. Is this a MathTeXEngine problem, or Makie?

Screen Shot 2021-08-22 at 12 42 23 PM

more examples at this issue MakieOrg/Makie.jl#1245

@AshtonSBradley AshtonSBradley changed the title italics for greek seem reversed italics for Greek seem off Aug 22, 2021
@AshtonSBradley AshtonSBradley changed the title italics for Greek seem off italics are not correct Aug 22, 2021
@AshtonSBradley
Copy link
Author

AshtonSBradley commented Aug 22, 2021

cbar = Colorbar(f[1, 1][1,1],height=15,vertical=false)
Label(f[1, 1][1, 2], L"|\psi|^2\xi^2")

gives something like this

Screen Shot 2021-08-21 at 10 44 16 PM

Here it appears that \psi is not italicised, but | is, which seems to invert the normal situation for latex math where greek is italicised:

Screen Shot 2021-08-21 at 10 49 09 PM

It seems that instead greek is not leaning, while some math characters are leaning.

@AshtonSBradley AshtonSBradley changed the title italics are not correct italics are not correct for Greek etc Aug 22, 2021
@AshtonSBradley AshtonSBradley changed the title italics are not correct for Greek etc italic shape is not correct for Greek etc Aug 22, 2021
@AshtonSBradley
Copy link
Author

Note that computer modern is not correctly rendered using the current implementation. It should look like this

https://tug.org/FontCatalogue/computermodern/

Screen Shot 2021-08-22 at 6 39 11 PM

whereas I get, e.g.

Screen Shot 2021-08-22 at 6 45 56 PM

The integral seems to have survived intact, but \pi and \mu ...

@AshtonSBradley
Copy link
Author

I would be happy to have a go at fixing this... any pointers on how to get started?

@Kolaru
Copy link
Owner

Kolaru commented Aug 22, 2021

Thanks for the detailed report ! There are several things going on here.

  1. Currently we are using New Computer Modern and not erm... "vanilla" Computer Modern, for technical reason since the former is a set of unicode fonts, while the latter has some pre-unicode complications. The result still looks wrong compared to the expectation anyway.
  2. This is definitely mostly a MathTeXEngine problem, Makie trust this package about everything related to math rendering.
  3. That being said, there is currently a dependency conflict between Makie and MathTeXEngine due to the last breaking update of GeometryBasics.jl (see CompatHelper: bump compat for "GeometryBasics" to "0.4" for package CairoMakie MakieOrg/Makie.jl#1174 and related). This prevents the use of the very last version we have here. The src/protoype.jl renders think with a different pipeline, allowing to circumvent this issue and continue developpement as long at it isn't solve.
  4. In the latest (v0.2.0) the wrong italics for delimiters (including e.g. |) should be solved.
  5. For italicized greek letter it is more subtle. The main problem is finding where the glyphs for theses characters are located in the font files and making them available to Makie. They are not the main glyphs in the math font NewCMMath-Math nor the one from the italics font NewCM10-Italic... I fear that they may be alternative glyphs in the math font and we lack the ability to load those through TrueTypeAbstraction.jl. I unfortunately lack the latex knowledge to go read what latex engines do for this.
    Alternatively, it may be simpler to implement the vanilla Computer Modern set of fonts, since it doesn't use any of the OpenType tricks AFAIK. This would mostly require introducing the table associating unicode symbol to their (non unicode) code in the correct font. Matplotlib already have a similar table here we could adapt. I'm starting to be more and more convinced using Computer Modern may be the way to go despite this added complexity.

So point 3 and 5 require a fix. For the latter, the starting point is this function

function TeXChar(char, fontset::FontSet, char_type)

It is given a Char and FontSet and additional information about the context (currently char type and I'm adding font modifier to fix #21, hopefully today) and has the job to return a TeXChar object containing the code of the char inside the font, the font, and whether this symbol should be considered slanted or not. By navigating what it does, you should get an idea of the madness of font handling :D

If you'd like to contribute and have any question about the internal, I'm happy to help.

@AshtonSBradley
Copy link
Author

AshtonSBradley commented Aug 23, 2021

How does LaTeXStrings.jl approach compare to the two approaches outlined in point 5? Is it doing a version of the matplotlib lookup? I ask this because LaTeXStrings seems to produce consistently good output in my limited usage

@Kolaru
Copy link
Owner

Kolaru commented Aug 23, 2021

LaTeXStrings.jl doesn't do any layouting or rendering, it is only a convenient type for strings representing LaTeX code. The hard work is always done by the backend.

@AshtonSBradley
Copy link
Author

AshtonSBradley commented Aug 24, 2021

On closer inspection it seems to me that all lower case Greek has not had the conventional slant applied. Could this be fixed in the pipeline logic? Lower case Greek is always slanted/italic by convention. Presumably this wouldn't auto-fix in a different font until the logic is updated... or have I misunderstood the issue?

@AshtonSBradley
Copy link
Author

5. For italicized greek letter it is more subtle. The main problem is finding where the glyphs for theses characters are located in the font files and making them available to Makie. They are not the main glyphs in the math font NewCMMath-Math nor the one from the italics font NewCM10-Italic... I fear that they may be alternative glyphs in the math font and we lack the ability to load those through TrueTypeAbstraction.jl.

So I should at least hunt down an example of italicised lower case greek, and figure out whether TrueTypeAbstraction.jl can load it?

@AshtonSBradley
Copy link
Author

AshtonSBradley commented Aug 25, 2021

These lower case greek symbols look perfect. They seem to be part of the main font. Am I missing something here? Looks like they are not part of NewComputerModernMath though. I accessed via view -> language -> greek in fontbook for the italic form of the regular font. Does that help?

Screen Shot 2021-08-26 at 10 59 17 AM

@AshtonSBradley
Copy link
Author

how would I go about changing the default lower case greek to be italic?

This was referenced Aug 30, 2021
@AshtonSBradley
Copy link
Author

@Kolaru do you think there is a way forward using NCM, or does this require deeper surgery?

@AshtonSBradley AshtonSBradley changed the title italic shape is not correct for Greek etc Lower case Greek should be italic in math Sep 8, 2021
@AshtonSBradley AshtonSBradley changed the title Lower case Greek should be italic in math Lower case Greek should be italic Sep 8, 2021
@AshtonSBradley
Copy link
Author

The glyphs are definitely there already.

Here I used the Font Preview vscode extension to read the otf files in MathTeXEngine.jl:

Screen Shot 2021-09-08 at 10 10 47 PM

Can I just set the font that MathTeXEngine would use globally to italic? I mean I would much rather specify a few roman cases using \textrm{ } than have nonitalic defaults. In fact that is the normal situation (italic defaults on everything) I think...

Is the font used for math set at the Makie level, or MathTeXEngine?

How do I tell Makie to tell MathTeXEngine to use NewCM10-italic?

Or set the default font in MathTeXEngine?

@AshtonSBradley
Copy link
Author

mmm. Fonts are confusing. No italic math file for NewCM.

Yet, the "Math example" here

https://tug.org/FontCatalogue/newcomputermodernroman/

is italic. I don't get this. What is going on here?

@Kolaru
Copy link
Owner

Kolaru commented Sep 9, 2021

Sorry for the late answer I was quite busy recently.

These lower case greek symbols look perfect.

Yes they can do the job, they are not the glyphs used in the math example you linked below for some reason that eludes me as well. But we could use them anyway.

Can I just set the font that MathTeXEngine would use globally to italic?

Unfortunately things are a bit more complicated. Currently we separate between symbols and normal characters. Glyphs for symbols are taken from the math font and glyphs for normal character from the italic font. The catch is that greek letters are parsed as :symbol, so having them italicized require a bit more work.

Is the font used for math set at the Makie level, or MathTeXEngine?

How do I tell Makie to tell MathTeXEngine to use NewCM10-italic?

Or set the default font in MathTeXEngine?

The fonts are set in MathTexEngine there:

const _default_fonts = Dict(
:regular => joinpath("NewComputerModern", "NewCM10-Regular.otf"),
:italic => joinpath("NewComputerModern", "NewCM10-Italic.otf"),
:bold => joinpath("NewComputerModern", "NewCM10-Bold.otf"),
:bolditalic => joinpath("NewComputerModern", "NewCM10-BoldItalic.otf"),
:math => joinpath("NewComputerModern", "NewCMMath-Regular.otf")
)
const _default_font_mapping = Dict(
:text => :regular,
:delimiter => :regular,
:digit => :regular,
:function => :regular,
:punctuation => :regular,
:symbol => :math,
:char => :italic
)

The first dict define the default fonts with an identifiers (e.g. :italic for the italic font), while the second maps a element type (e.g. :symbol) to a font type (e.g. :math). As mentioned above, currently greek letters are parsed as :symbol so its clashes with symbols like \sum that we want to take from the :math font. The simplest way may be to parse greek letters as a separate type of object so we can easily define a font for them. Ideally I think it should be done by the parser (greek letters can be identified by looking at their unicode code).

do you think there is a way forward using NCM, or does this require deeper surgery?

Patching NCM is possible, but once I have more time I will look into the options in more details nonetheless.

@AshtonSBradley
Copy link
Author

awesome! I will give a test drive !

@AshtonSBradley
Copy link
Author

I guess MakieOrg/Makie.jl#1952 basically fixes this, apart from (so far) this new issue with backslash that will impact axis labels MakieOrg/Makie.jl#1967

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

Successfully merging a pull request may close this issue.

2 participants