Bug 103680 (hb_ot_math) - Use HarfBuzz ot-math API to parse the OpenType MATH table
Summary: Use HarfBuzz ot-math API to parse the OpenType MATH table
Status: NEW
Alias: hb_ot_math
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL: http://frederic-wang.fr/opentype-math...
Whiteboard:
Keywords:
Depends on: 109142
Blocks: 32362 Formula-Editor Font-Rendering 99351 100746 103318
  Show dependency treegraph
 
Reported: 2016-11-03 14:23 UTC by Volga
Modified: 2024-04-18 18:45 UTC (History)
11 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volga 2016-11-03 14:23:56 UTC
Description:
Since HarfBuzz have been provided APIs to process the OpenType MATH table, LibreOffice could also display the mathmatical formulas with some fonts as Cambria Math and XITS, with help of these APIs.

Steps to Reproduce:
HarfBuzz version 1.3.3 is released on September 28, 2016, with some new APIs to parse the MATH table. See: https://github.com/behdad/harfbuzz/blob/master/NEWS

Actual Results:  
-

Expected Results:
If LibreOffice handle these APIs, any fonts including MATH table would easy to be used to presenting mathmatical formulas.


Reproducible: Always

User Profile Reset: No

Additional Info:


User-Agent: Mozilla/5.0 (Android 4.3; Mobile; rv:49.0) Gecko/49.0 Firefox/49.0
Comment 1 V Stuart Foote 2016-11-06 23:54:31 UTC
We still need to produce valid ODF 1.2+ Math Formula

This would probably be reasonable long term to reinstrument the Math Formula editor to make use of OpenType smart type features, but equally I would hope to implement LaTex syntax in addition to native We still need to produce valid ODF 1.2+ Math Formula

Short answer is that the whole thing needs to be refactored, so using OpenType Math syntax and layout would come in a as part of a larger effort. One I assume would also get us GSUB and GPOS support when using OpenType fonts.

So this by itself is a valid enhancment--but it will have to be done as a part of a broader refactoring of layout framework in LibreOffice. 


=-ref-=
https://www.microsoft.com/typography/otspec/math.htm
https://en.wikipedia.org/wiki/OpenType#Math
Comment 2 Volga 2016-11-07 14:59:34 UTC Comment hidden (obsolete)
Comment 3 V Stuart Foote 2016-11-07 16:00:01 UTC
Again, point is we must continue to produce valid ODF 1.2+ Formulas and working with OpenType Math tables alone has no UI or input syntax to work with--it needs inline interpreting of MathML or LaTeX.

Doing HarfBuzz API calls for inline support of OpenType smartfont features and MathML syntax for rendering formulas in text does not keep us ODF compliant if we abandon the Math formula editor. LaTex syntax markup is an equally viable approach (available now with TexMaths extension that requires an external LaTex instance but embeds formula as PNG or SVG and remains ODF compliant).

So the Math Formula editor would have to be refactored to support OpenType Math table markup and presumably retain legacy StarMath/Math markup for ODF compatibility.  While doing all that we would take care of (probably required) the rest of the OpenType smartfont feature support that folks have been asking for.

And I would hope while doing so we'd implement UI support for inline LaTex syntax as well, even if using HarfBuzz and not shaping with TeX.

Point being you really can't do anything with HarfBuzz APIs providing OpenType Math formulas without committing to the LO sm Math Formula editor being scrapped and starting over. This enhancement is valid, but I don't think anyone is volunteering to take on the refactoring needed.
Comment 4 ⁨خالد حسني⁩ 2016-11-07 16:26:58 UTC
You don’t need MathML to render fonts with OpenType math information. But anyway, ODF actually uses MathML to store math formulas (we currently also store the StarMath syntax in the MathML “annotation” tag and read it from there to I guess  avoid roundtrip conversion).
Comment 5 Frédéric Wang 2016-11-07 16:31:34 UTC
So as I see there are several separate issues:

1) Encoding of math formulas
   MathML is the standard used in ODF for encoding mathematical formulas and we can attach semantics annotation to MathML formulas (e.g. StarMath or LaTeX). Currently we use MathML with StarMath annotation. Storing images of formula for ODF document would be a horrible solution IMHO but that can still be used for exporting to other formats (e.g. HTML).

2) Writing math formulas
   Of course MathML is not intended to be written by hand. Currently we have StarMath and a visual editor (disabled by default). It would make sense to add a LaTeX input method.

3) Abstract tree for rendering/navigation of math formulas
   Currently, this tree matches the StarMath syntax which is very poor compared to MathML or LaTeX. I think we should really have MathML as an internal format here, so that valid ODF import/export is straighforward and we can manage additional annotations (LaTeX and StarMath) for more input methods.

IIUC, 3) is the topic discussed here. As Khaled said, using OpenType MATH is independent of the internal tree.
Comment 6 Frédéric Wang 2016-11-07 16:35:32 UTC
So focusing on 3), I agree that the StarMath-based code will need a big refactoring. Maybe a reasonable first step is to focus only on improving the rendering of stretchy and large operators using the MathVariants subtable. But otherwise, maybe instead of rewriting everything we just want to use a separate library such as libmathview (https://github.com/khaledhosny/libmathview/) or WebKit to provide a visual rendering of the formula that can also be navigated.
Comment 7 Volga 2016-12-03 03:43:39 UTC Comment hidden (obsolete)
Comment 8 Volga 2017-08-15 13:11:48 UTC
Bug 109142 have been fixed recently, which bring us HarfBuzz 1.4.8 with OpenType MATH table support, so we can started to working for this. And I suggest we need also adding this table into OpenSymbol font to make some brackets presented scaling.
Comment 9 Volga 2018-05-20 04:26:19 UTC Comment hidden (obsolete)
Comment 10 Volga 2018-05-20 04:35:47 UTC
(In reply to V Stuart Foote from comment #1) 
> We still need to produce valid ODF 1.2+ Math Formula
If ODF 1.2+ Math Formula is fully interoperable with MathML, I think we can try to create some sample files for test.
> This would probably be reasonable long term to reinstrument the Math Formula
> editor to make use of OpenType smart type features, but equally I would hope
> to implement LaTex syntax in addition to native We still need to produce
> valid ODF 1.2+ Math Formula
The following resources provides some sample LaTeX codes can also be used for testing:
https://github.com/khaledhosny/xits/tree/master/documentation/documentation-sources
http://www.gust.org.pl/projects/e-foundry/tg-math
Comment 11 Volga 2018-05-21 16:30:48 UTC
As a workaround, if you want to make use of mathmetical fonts in LibreOffice, you have to install XeLaTeX firstly, then install TexMaths extension (0.46 and newer) and configure it to call XeLaTeX for foumulas.
Comment 12 Volga 2018-05-25 15:01:54 UTC
(In reply to V Stuart Foote from comment #1)
> We still need to produce valid ODF 1.2+ Math Formula
> 
> This would probably be reasonable long term to reinstrument the Math Formula
> editor to make use of OpenType smart type features, but equally I would hope
> to implement LaTex syntax in addition to native We still need to produce
> valid ODF 1.2+ Math Formula
Also, the following page set an good example of LaTeX2Mathml, also would be help for test.
https://fred-wang.github.io/TeXZilla/
Comment 13 daviswar 2020-10-07 04:10:09 UTC Comment hidden (spam)