CSharpMath
CSharpMath copied to clipboard
Incorrect spacing and bounding box
Describe the bug There are incorrect spacing and bounding boxes as indicated by green ellipses. The top is created by LaTeX and the bottom is created by CSharpMath.
- [ ]

- [ ]

- [ ]

- [ ]

- [ ]

- [ ]

- [ ]

- [ ]

To Reproduce Make sure you have TeX distribution installed. Download the VS solution from my rep: https://github.com/sadqiang/GitHubReport/tree/master/GitHubReport.
Questions
- [ ] 1. What causes the size of LaTeX output to be smaller than that of Skia's ? I already set 12pt for both actually.
- [ ] 2. Why can't we use the following?
\Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr)
y=\cfrac{x}{1+\cfrac{x}{1+\cfrac{x}{1}}}
\mathscr{L}\left\{f(t)\right\} = F(s)
- [ ] 3. Can we change the math font from the default to, for example, Palatino, Bera, etc?
Some of these are deficiencies from iosMath that this library was ported from. I'll keep this in mind in the upcoming rewrite.
@Happypig375 : Is there a roadmap (a schedule of updates, versioning, etc) for CSharpMath ?
See the bottom part of #29, basically CSharpMath is in a process of being rewritten.
The 𝑃 case is interesting. It has a smaller glyph advance than the whole character width which makes sense for italic characters following it, but causes problems for non-italic characters such as ).
wpf-math, iosMath, CSharpMath and Typography follow the glyph advance resulting in the same output, while MathJax and KaTeX follow the character width, ignoring the glyph advance.
@prepare would ignoring the glyph advance be more suitable?
I think in this case for math expression + math-font, Exact glyph bounds should be used. (ignore glyph's advance) (since each glyph position is controled by Math layout engine)
But if you want to layout 'human text' with general font. It should use glyph's advance (since the result glyph advances are processed by GSUB, GPOS)
GSUB, GPOS with AsanaMath, LatinModernMath, XITSMath
(𝑃𝑃𝑃)
Notepad, LatinModernMath
@brezza92 (Typography-based MathML implementation) What do you think about this?,
Did you use glyph's advance or exact glyph bounds?
My MathML implement use glyph's advance this it my result. It has same problem.
I have an idea that, a cluster of letter may be treated as a human text (eg. some variable name may need GSUB/GPOS). and then find exact bounds of a cluster.
other else (eg math signs + - * / etc) should use exact bounds.
so (𝑃𝑃𝑃) should be split to 3 parts as image below (edited by hand). (central part 𝑃𝑃𝑃 => a cluster of letter, can use GSUB/GPOS)
a cluster of 𝑃𝑃𝑃 with GSUB/GPOS
What about when italic characters are mixed with upright characters?
What about when italic characters are mixed with upright characters?
please give me some example and your expected result

Sure, That side effect will happen in the same GSUB/GPOS layout block

Then, It should be considered that => the block of consecutive letter need gsub/gpos layout process or not.
In latin script=> may not,
but in other script => may be, some script need GSUB/GPOS to get correct final output. (eg. if the math expression contains some variable in non-latin letter).
So what should be considered as "a block of consecutive letters"? Same Unicode block? Same Unicode category?
not sure if https://docs.microsoft.com/en-us/dotnet/api/system.char.isletter?view=netcore-3.1 is OK?
If all letters are latin or math char=> it is OK to use only exact bounds, no need for GSUB,GPOS.
In math layout, When to use GSUB/GPOS?,
I think when we found a char from other script. (some unicode ranges that related to script)
Not sure that If it possible to put a char from other script (eg arabic, chinese, emoji), into math-expression or not,
If it possible, and no glyph inside a math-font, How to present it ?
and it means that block of text may need GSUB/GPOS.
David Carlisle told me that we cannot win. See section 7.5.5-7.5.6.
@pstricks-fans What is "we cannot win"?
@prepare
System.Char.IsLetter("𝑃P", 0) // true => 𝑃 is a letter
System.Char.IsLetter("𝑃P", 2) // true => P is a letter
@Happypig375 : I am not sure the meaning. It might mean it is impossible to get it right. Here is his statement.
@pstricks-fans I'd say that at least getting the spacing specified in the original post counts as fixing this case.
@prepare
System.Char.IsLetter("𝑃P", 0) // true => 𝑃 is a letter System.Char.IsLetter("𝑃P", 2) // true => P is a letter
Yes ?

Sure, That side effect will happen in the same GSUB/GPOS layout block
This is limitation of 𝑃P , if you put it in the same GSUB/GPOS block,
in the real world => It should be rarely used?
After reading ... from http://texdoc.net/texmf-dist/doc/context/documents/general/manuals/luatex.pdf#page=116
7.5.6 Script and kerning ... ... ... In 2018 fonts like Latin Modern and Pagella rely on cheatswith the boundingbox, Cambria uses staircase kerns and Lucida a mixture. Depending on howfonts evolve we might add some more control over what one can turn on and off.
EDIT:
I'm not sure that GSUB/GPOS technique is good for layout some Math fonst or not?
not sure that some Math fonts are designed with the GSUB,GPOS mechanism in mind or not?
Do you know who create/maintenance/update Latin-modern math font?
SORRY about what I've said, =>it come from my little knowledge :(
see => https://github.com/verybadcat/CSharpMath/issues/32#issuecomment-649200044
Latin Modern Math's last update is 6 years old and is pretty much unmaintained. However, I love its glyphs and would like to retain it as the default font.
Useful information about Math symbols advance width
https://docs.microsoft.com/en-us/typography/develop/character-design-standards/math
@prepare What about storing an italic measure (glyph.MathGlyphInfo?.ItalicCorrection) when positioning each glyph? So if the current character has less italic correction than the previous character, the difference becomes additional spacing?
I've overlooked that info!
The Math Font file (eg Latin Modern Math, Asana Math)
contain that info.
It may be used in this situation.
When a run of slanted characters is followed by a straight character (such as an operator or a delimiter), the italics correction of the last glyph is added to its advance width.
see detail more detail =>
https://docs.microsoft.com/en-us/typography/opentype/spec/math#mathitalicscorrectioninfo-table
@brezza92, please check this info (https://github.com/verybadcat/CSharpMath/issues/32#issuecomment-645291053) too.
Math Layout in "In-span" italic correction
from https://github.com/verybadcat/CSharpMath/issues/32 and should be solved by (https://github.com/verybadcat/CSharpMath/issues/32#issuecomment-645134531 and https://github.com/verybadcat/CSharpMath/issues/32#issuecomment-645291053)
pic 1: No italic correction if not set ScriptLang property to "math"
Users can layout math manually entire process by their own MathLayout engine.
But the GlyphLayout class also have a help for layouting "in-span" italic glyph.
- EnableBuiltinMathItalicCorrection (https://github.com/LayoutFarm/Typography/commit/ccad43bb2130137b71958d8b0aa8b046e3a82a15) is true by default
BUT
- GlyphLayout ScriptLang must be set to new ScriptLang("math") too.
see detail impl => https://github.com/LayoutFarm/Typography/commit/ccad43bb2130137b71958d8b0aa8b046e3a82a15#diff-b705c14388c05643560a455e65eaf449R468
pic 2: 'in-span' math italic correction
pic 3: latin modern math, 20pt, math italic correction
[A] (𝐹𝐹𝐹), [B] (FFF), [C] (𝐹F𝐹)
Please test it :)
Will do, thanks
Blocked on https://github.com/verybadcat/CSharpMath/issues/107#issuecomment-657902124
@Happypig375 We're having this issue too for Matrices, seems like it's the same issue?
