Mathml and Java

MathML and Java

I've used JEuclid for rendering MathML in my Symja project (Java symbolic math system - point 4 of your list).
JEuclid may be too slow (especially at startup) to render MathML on a mobile phone.

Other alternatives for rendering math expressions with TeX:

  • JMathTex
  • SnuggleTeX
  • JLaTeXMath

and for re-arranging equations or as general Java math libraries:

  • Mathrider (Yacas for Java)
  • Jasymca - Symbolic Calculator for Mobile Devices
  • Java Algebra System
  • Hipparchus - library of lightweight, self-contained mathematics and statistics components
  • The Apache Commons Mathematics Library

Calculator projects for Android:

  • Calculator N+ (GNU public license)
  • Jasymca for Android (GNU public license)
  • Arity calculator for android (Apache license)

Maths Equation in Reports

Which JavaFX version are you using ?

I suppose you pasted this equation as a picture ?

The next coming versions of JavaFX support MathML :

  • JavaFX 8 Update 192 included in Java 8 Update 192
  • JavaFX 11.

So if you want to display an equation, I suggest you use MathML.
And if you want to save it in a database, you simply have to copy the MathML code.

Follow this link Java Early Access Download to reach the early access to these versions.

I don't know Jasper Report but I understand that it uses xml file. Or XML, MathML, HTML, SVG belong to the same family language (SGML) : They are just strings. So you can wrap your HTML + MathML text and formula in an xml expression or may be replace the picture name you used before with these codes.
Then you can set WebView or HTMLEditor content using this HTML + MathML code.

Below, the MathML code to display the following quadratic formula.

Quadratic formula

<math display="block"> 
<mrow>
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b </mi>
<mo>±</mo>
<msqrt>
<mrow>
<msup>
<mi>b</mi>
<mn>2</mn>
</msup>
<mo>−</mo>
<mn>4</mn>
<mi>a</mi>
<mi>c</mi>
</mrow>
</msqrt>
</mrow>
<mrow>
<mn>2</mn>
<mi>a</mi>
</mrow>
</mfrac>
</mrow>
</math>

Finally, print it :-) How to Print with JavaFX.

Other documents in that tutorial also show you how to build the browser that implements all what you want.

Is it possible to use MathML to describe data tables?

mtable is not specifically for matrices (in particular it does not add parenthesis around the data) It is used for all vertical alignment layouts such as tables and aligned equations.

MathML tags don't render properly in JavaFX WebView

The result on my computer with the code you posted ? ?

Screenshot CaptainIRS MathML Code

First, be sure you're using at least Java/JavaFX 8 192 build 04 or JavaFX 11 (MathML support is broken, in Java/JavaFX 9 and 10 and won't be fixed in these versions).

Secondly, verify your font list. May be a font config issue on your computer ?

At least one of these fonts must be installed (in order of preference):

  • Latin Modern Math

  • STIX Two Math

  • XITS Math
  • STIX Math
  • Libertinus Math
  • TeX Gyre Termes Math

  • TeX Gyre Bonum Math

  • TeX Gyre Schola

  • DejaVu Math TeX Gyre

  • TeX Gyre Pagella Math

  • Asana Math

  • Cambria Math

  • Lucida Bright Math
  • Minion Math

  • Times New Roman

The result on my computer too, but after Latin Modern Math font installation :

Sample Image

Code example : did you use a code like this ?

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class NavigateurTest extends Application {

final StackPane root = new StackPane();
final WebView webView = new WebView();
String ContentStackOverFlow = ""
+ "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
+ " <msub>"
+ " <mi>S</mi>"
+ " <mi>n</mi>"
+ " </msub>"
+ " <mo><</mo>"
+ " <mstyle displaystyle=\"true\" scriptlevel=\"0\">"
+ " <mfrac>"
+ " <mi>π</mi>"
+ " <mrow>"
+ " <mn>3</mn>"
+ " <msqrt>"
+ " <mn>3</mn>"
+ " </msqrt>"
+ " </mrow>"
+ " </mfrac>"
+ " </mstyle>"
+ "</math>";

public void init() {
root.getChildren().add(webView);
}

@Override
public void start(Stage primaryStage) {

//webView.getEngine().load("https://www.qwant.com");
webView.getEngine().loadContent(ContentStackOverFlow);

primaryStage.setTitle("OpenJFX MathML Rendering WebBrowser Test");
primaryStage.setScene(new Scene(root));
primaryStage.show();

}

}

Find mathmls from a String using java

You can't do that with Java's regex engine since this is valid input:

<math>
<apply>
<plus/>
<apply>
<times/>
<ci>a</ci>
<apply>
<power/>
<ci>x</ci>
<cn>2</cn>
</apply>
</apply>
<apply>
<times/>
<ci>b</ci>
<ci>x</ci>
</apply>
<ci>c</ci>
</apply>
</math>

i.e.: there can be arbitrary nested tags and Java's regex engine has no ability to match recursive patterns. You will have to resort to some parser to handle MathML input.

EDIT

Can i consider the entire thing as a string and find for a pattern which matches ? That is what i am trying. And there is not going to be any recursive tags inside another tag. they will be in same level.

In that case, try this pattern:

<math[>\s](?s).*?</math>

or as a String literal:

"<math[>\\s](?s).*?</math>"

which means:

<math[>\s]   # match `<math` followed by a space or `>`
(?s).*? # reluctantly match zero or more chars (`(?s)` causes `\r`
# and `\n` also to be matched)
</math> # match `</math>`


Related Topics



Leave a reply



Submit