Please provide math/equation rendering

0 votes
asked Nov 15, 2016 in Closed feature request by saad (120 points)
Please provide math/equation rendering, it would be very useful to have for instance mathjax-rendered equations and maths in SVG diagrams.

7 Answers

+1 vote
answered Nov 25, 2016 by plantuml (257,860 points)
selected Nov 27, 2016 by saad
Best answer

We've put online the beta version with JLatexMath.

The result is far better:

int_-1^1 sqrt(1-x^2)dx = pi/2

We have integrated this with the Creole parser.


note right
Try also
end note

Tell us if you find issues.
You can also download last beta and unzip the following file
(All .jar must be in the same folder)

+1 vote
answered Nov 16, 2016 by plantuml (257,860 points)
Mathjax looks javascript based, so integrating this with PlantUML (which is Java based) is not really possible.

If you find any OpenSource Java library that does the job (that is enabling math equation), we could considere integrating it.
commented Nov 17, 2016 by saad (120 points)
I'll do some research to see which may be more suitable in terms of ease of integration among the libs referenced in this URL:
+1 vote
answered Nov 17, 2016 by plantuml (257,860 points)
After having read the stackoverflow page, JEuclid may do the job, since it looks able to generated PNG/SVG images.
If someone find a better library, please post...

However, there are some points:

1) Last version of JEuclid was published in 2010 (so it is not active anymore)

2) JEuclid uses MathML. MathML is quite verbose : is it ok for you ? (See )

3) JEuclid is distributed under ASL license, which is not compatible with the default GPL license of PlantUML
(although there is a ASL version of PlantUML). We could do the same trick as for PDF export : loading the library at runtime (see )

4) It would be nice is someone (you? :-) could make a snipset (simple code example) with jeuclid-minimal-3.1.9-distribution that shows how to use Jeuclide from Java code (that is transforming some XML data to PNG/SVG image).
+1 vote
answered Nov 18, 2016 by plantuml (257,860 points)

We were able to write a snipset that works for PNG with JEuclid.

For the record:

    public static void main(String[] args) throws SAXException, IOException {

        Parser parser = Parser.getInstance();
        DocumentBuilder builder = parser.getDocumentBuilder();

        String s = "<?xml version=\"1.0\"?><!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"\"><math mode=\"display\"><mrow><munderover><mo>&#x222B;</mo><mn>1</mn><mi>x</mi></munderover><mfrac><mi>dt</mi><mi>t</mi></mfrac></mrow></math>";
        InputStream is = new ByteArrayInputStream(s.getBytes());
        Document doc = builder.parse(is);

        Converter conv = Converter.getInstance();

        BufferedImage img = conv.render(doc, LayoutContextImpl.getDefaultLayoutContext());
        ImageIO.write(img, "png", new File("out.png"));


Now this is working with MathML, and we still thinks that this is too verbose syntax.
Using AsciiMath syntax would probably be better.

There is a library ( ) that can transform ASCIIMath to MathML so that would be perfect.
This library is written in JavaScript, but maybe we can run it using Nashorn/Rhino script engine, or translate it in pure Java.

commented Nov 19, 2016 by saad (120 points)
Thank you for the prompt response !
I totally agree with your argument on JEuclid, and the ASCIIMath->MathML solution looks promising for syntax simplicity and compatibility.
However, it seems inevitable to overcome the need for compatibility with javascript (e.g. Rhino). Which brings up the question, would MathJax be a possible solution, given that it offers syntax simplicity like ASCIIMath but with better rendering capability and extended math support. Do you think it's possible ?
0 votes
answered Nov 25, 2016 by plantuml (257,860 points)

We've made some progress here.

Starting wih V8050, we use AsciiMathParser.js (included in plantuml.jar) and external JEuclid libraries (here ).
It's not yet fully integrated with PlantUML (you cannot yet use it with diagrams).

We've created a new @startmath/@endmath to test the concept.
So you can have now:
sum_(i=1)^n i^3=((n(n+1))/2)^2

If you want to try it with your own version of PlantUML, you can use V8050 and extract all libraries from in the same folder as plantuml.jar

The rendering is not as beautifull as
Mathjax needs a browser and rhino is just a Javascript engine.
So I am not sure that Javascript engine can fully run mathjax.

If anymore successfully integrates Mathjax with Java, please let us known!

The next step will be to integrate this into our creole parser, so that we can have something like:

Bob -> Alice : Can you calculate <math>sum_(i=1)^n i^3=((n(n+1))/2)^2</math> ?

But before doing that, we would like to know if the rendering is ok for you.
(We don't want to work on unused feature :-)

commented Nov 25, 2016 by Serge Wenger Work (14,160 points)
For me, the left part of the png is truncated, not the svg
0 votes
answered Nov 25, 2016 by plantuml (257,860 points)

Since the drawing with JEuclid is not perfect, we give a try with JLatexMath
This project is very well documented.
We used to transform sum_(i=1)^n i^3=((n(n+1))/2)^2 into LaTeX


Using this LaTeX expression, we were able to generate the two files with JLatexMath:

The result is really better.

Now we have to find a way to transform ASCIImath to LaTeX.
We found a library (JavaScript or PHP) that does the job:

So either we used rhino again to intregrate this, or we port the PHP code to Java

0 votes
answered Dec 1, 2016 by plantuml (257,860 points)
This has been released in V8051.

Hope this helps!
commented Dec 2, 2016 by saad (120 points)
I am really thankful, I already started my first math blocks on the demo server !