Rendering TeX formulas as equation objects in XLSX

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Rendering TeX formulas as equation objects in XLSX

Cosimo
Hi,

I'm trying to render LaTeX equations like:

    \sigma=\frac{\sqrt{3}}{2}

into Excel equation objects. The JLatexMath package allows one to render a latex equation into a PNG image. I tried that, but it seems that the SXSSF streaming interface doesn't allow me to add images to the workbook.

I'm considering an alternative solution, streaming or not, to render latex equations directly into equation objects (the `<m:oMathPara><m:r>...` drawingml objects IIUC).

What I have available from JLatexMath is a Graphics2D interface, so the equations can be painted onto a Graphics2D context. The closest match I found in POI is the EscherGraphics2D class.
Is there any existing way with POI to convert latex into an xml equation/math drawing object?

I found https://github.com/jgm/texmath that is doing exactly that, but it's Haskell.
Haven't found anything equivalent in Java.

Any ideas?

Thanks,

--
Cosimo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Rendering TeX formulas as equation objects in XLSX

Andreas Reichel
Cosimo,

assuming you will need "streaming/SXSSF" solely for large data, but not
because of many formulas, maybe you can:

1) first create a XSSF workbook and add your formula objects/pictures
and save it and
2) then create a SXSSF from that XSSF template with the formula
objects/pictures and fill it with your large data

Good luck and cheers.
Andreas

On Fri, 2020-10-23 at 10:44 +0200, Cosimo wrote:

> Hi,
>
> I'm trying to render LaTeX equations like:
>
>     \sigma=\frac{\sqrt{3}}{2}
>
> into Excel equation objects. The JLatexMath package allows one to
> render a latex equation into a PNG image. I tried that, but it seems
> that the SXSSF streaming interface doesn't allow me to add images to
> the workbook.
>
> I'm considering an alternative solution, streaming or not, to render
> latex equations directly into equation objects (the
> `<m:oMathPara><m:r>...` drawingml objects IIUC).
>
> What I have available from JLatexMath is a Graphics2D interface, so
> the equations can be painted onto a Graphics2D context. The closest
> match I found in POI is the EscherGraphics2D class.
> Is there any existing way with POI to convert latex into an xml
> equation/math drawing object?
>
> I found https://github.com/jgm/texmath that is doing exactly that,
> but it's Haskell.
> Haven't found anything equivalent in Java.
>
> Any ideas?
>
> Thanks,
>

Reply | Threaded
Open this post in threaded view
|

Re: Rendering TeX formulas as equation objects in XLSX

Andreas Reichel
In reply to this post by Cosimo
Btw, there seems to be a stylesheet that translates MathML into
OMML: https://github.com/python-openxml/python-docx/files/1453769/MML2OMML.zip

And this shows how to use
it: https://stackoverflow.com/questions/46623554/add-latex-type-equation-in-word-docx-using-apache-poi

Good luck!

On Fri, 2020-10-23 at 10:44 +0200, Cosimo wrote:

> Hi,
>
> I'm trying to render LaTeX equations like:
>
>     \sigma=\frac{\sqrt{3}}{2}
>
> into Excel equation objects. The JLatexMath package allows one to
> render a latex equation into a PNG image. I tried that, but it seems
> that the SXSSF streaming interface doesn't allow me to add images to
> the workbook.
>
> I'm considering an alternative solution, streaming or not, to render
> latex equations directly into equation objects (the
> `<m:oMathPara><m:r>...` drawingml objects IIUC).
>
> What I have available from JLatexMath is a Graphics2D interface, so
> the equations can be painted onto a Graphics2D context. The closest
> match I found in POI is the EscherGraphics2D class.
> Is there any existing way with POI to convert latex into an xml
> equation/math drawing object?
>
> I found https://github.com/jgm/texmath that is doing exactly that,
> but it's Haskell.
> Haven't found anything equivalent in Java.
>
> Any ideas?
>
> Thanks,
>

Reply | Threaded
Open this post in threaded view
|

Re: Rendering TeX formulas as equation objects in XLSX

Cosimo
On Fri, Oct 23, 2020, at 12:11, Andreas Reichel wrote:

> And this shows how to use
> it: https://stackoverflow.com/questions/46623554/add-latex-type-equation-in-word-docx-using-apache-poi

Seems to be a good approach, thanks!

--
Cosimo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Rendering TeX formulas as equation objects in XLSX

Cosimo
On Fri, Oct 23, 2020, at 14:09, Cosimo wrote:
> On Fri, Oct 23, 2020, at 12:11, Andreas Reichel wrote:
>
> > And this shows how to use
> > it: https://stackoverflow.com/questions/46623554/add-latex-type-equation-in-word-docx-using-apache-poi
>
> Seems to be a good approach, thanks!

I am not familiar with poi, but I can't see any way to add a "omath object",
whatever these things are called, to an XSSFWorkbook.

Based on that SO post, for Word, the path is `doc.createParagraph()` and
then `paragraph.getCTP().addNewOMath()`.
For an XSSFWorkbook, how would one get there?

Sheet -> Drawing -> CTDrawing -> ??

--
Cosimo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Rendering TeX formulas as equation objects in XLSX

Andreas Reichel
Cosima,

unfortunately it looks like you would need to go via XSSFSheet --> 
getCTWorkbook()

https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#getCTWorkbook

Good luck.
Andreas



On Fri, 2020-10-23 at 17:43 +0200, Cosimo wrote:

> On Fri, Oct 23, 2020, at 14:09, Cosimo wrote:
> > On Fri, Oct 23, 2020, at 12:11, Andreas Reichel wrote:
> >
> > > And this shows how to use
> > > it: https://stackoverflow.com/questions/46623554/add-latex-type-equation-in-word-docx-using-apache-poi
> >
> > Seems to be a good approach, thanks!
>
> I am not familiar with poi, but I can't see any way to add a "omath
> object",
> whatever these things are called, to an XSSFWorkbook.
>
> Based on that SO post, for Word, the path is `doc.createParagraph()`
> and
> then `paragraph.getCTP().addNewOMath()`.
> For an XSSFWorkbook, how would one get there?
>
> Sheet -> Drawing -> CTDrawing -> ??
>