API services

MathType Web provides the following services:

  • Generate images of formulas with the following formats: PNG, SVG, PDF, EPS, SWF.
  • Convert MathML from/to LaTeX.
  • Generate a textual representation of a formula for accessibility.
  • Convert presentation MathML from/to content MathML.
  • Provide a simple formula calculator. Works with floating point numbers. Not to be confused with Wiris CAS.

There are mainly two interfaces to the services:

  • Web service interface based on simple HTTP calls.
  • Direct calls to a library, available as Java and .NET.
Licensing note. It is important to read carefully the terms at the MathType store.

MathType Web can generate images of formulas from Presentation MathML, Content MathML or LaTeX and export them to PNG, SWF, SVG, PDF and EPS.

Web service

   http://domain/context-path/render

GET and POST parameters:

  • mml: Presentation MathML or Content MathML that represents the formula.
  • latex: LaTeX code that represents the formula.
  • format: format of the image. Allowed values are png, swf, svg, pdf, and eps. If not specified, png is used.
  • Parameters from this list.

Examples:

Alternative services:

 http://domain/context-path/render.png\\ 
 http://domain/context-path/render.swf\\ 
 http://domain/context-path/render.svg\\ 
 http://domain/context-path/render.eps\\ 
 http://domain/context-path/render.pdf

When calling to render.png, render.swf, render.svg, render.eps, or render.pdf instead of render, format parameter is taken as png, swf, svg, eps, or pdf respectively.

Java

Example:

     Properties p = new Properties();
     p.setProperty("color", "red");
     Properties out = new Properties();
     byte[] imageBytes = PublicServices.getInstance().renderPng(null, "2-x", p, out);
     int width = Integer.parseInt(out.getProperty("width"));

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.renderPng
PublicServicesInterface.renderSwf
PublicServicesInterface.renderSvg
PublicServicesInterface.renderEps
PublicServicesInterface.renderPdf

Example:

     Dictionary<string, string> p = new Dictionary<string, string>();
     p["color"] = "red";
     Dictionary<string, string> out = new Dictionary<string, string>();
     byte[] imageBytes = PublicServices.getInstance().renderPng(null, "2-x", p, out);
     int width = int.Parse(out["width"]);

MathML

Classic input coverage

MathType Web implements MathML 2.0 and 3.0

MathML coverage page

Handwriting coverage

MathType Web provides a service to convert LaTeX code into Presentation MathML. The list of LaTeX commands currently supported by MathType Web, with examples, can be found here.

Web service

   http://domain/context-path/latex2mathml

GET and POST parameters:

  • latex: LaTeX code that represents the formula.
  • saveLatex: if defined, the LaTeX code is stored inside the result MathML as an annotation.
  • grammar: the URL of the transformation grammar used to convert from LaTeX to MathML. If not specified, the default grammar is used.

Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.latex2mathml

Example:

   String mathml = PublicServices.getInstance().latex2mathml("2-x", false, null);

Result:

<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mo>-</mo><mi>x</mi></mrow><annotation encoding="LaTeX">2-x</annotation></semantics></math>

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.latex2mathml

Example:

   string mathml = PublicServices.getInstance().latex2mathml("2-x", false, null);

Result:

<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mo>-</mo><mi>x</mi></mrow><annotation encoding="LaTeX">2-x</annotation></semantics></math>

MathType Web provides a service to convert Presentation MathML into LaTeX code. The list of MathML commands currently supported by MathType Web, with examples, can be found here.

Web service

   http://domain/context-path/mathml2latex

GET and POST parameters:

  • mml: Presentation MathML that represents the formula.
  • saveMathML: if defined, the MathML is stored inside the result LaTeX code as a comment.
  • grammar: the URL of the transformation grammar used to convert from MathML to LaTeX. If not specified, the default grammar is used.

Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.mathml2latex

Example:

   String latex = PublicServices.getInstance().mathml2latex("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", false, null);

Result:

2 minus x

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.mathml2latex

Example:

   String latex = PublicServices.getInstance().mathml2latex("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", false, null);

Result:

2 minus x

LaTex is a ocean of options; we offer a subset of it.

LaTeX coverage page.

MathType Web provides a service to convert Content MathML into Presentation MathML. The list of Content MathML tags currently supported by MathType Web can be found here.

Web service

   http://domain/context-path/content2mathml

GET and POST parameters:

  • mml: Content MathML that represents the formula.
  • grammar: the URL of the transformation grammar used to convert from Content MathML to Presentation MathML. If not specified, the default grammar is used.

Examples:

  https://www.wiris.net/demo/editor/content2mathml?mml=%3Cmath%3E%3Capply%3E%3Cminus%3E%3C/minus%3E%3Ccn%3E2%3C/cn%3E%3Cci%3Ex%3C/ci%3E%3C/apply%3E%3C/math%3E

Java

Detailed information is available in the reference page:

PublicServicesInterface.content2mathml

Example:

   String mathml = PublicServices.getInstance().content2mathml("<math><apply><minus></minus><cn>2</cn><ci>x</ci></apply></math>", null);

Result:

   <math><mn>2</mn><mo>-</mo><mi>x</mi></math>

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.content2mathml

Example:

   string mathml = PublicServices.getInstance().content2mathml("<math><apply><minus></minus><cn>2</cn><ci>x</ci></apply></math>", null);

Result:

   <math><mn>2</mn><mo>-</mo><mi>x</mi></math>

MathType Web provides a service to convert Presentation MathML into Content MathML. The list of Presentation MathML tags currently supported by MathType Web can be found here.

Web service

   http://domain/context-path/mathml2content

GET and POST parameters:

  • mml: Presentation MathML that represents the formula.
  • grammar: the URL of the transformation grammar used to convert from Presentation MathML to Content MathML. If not specified, the default grammar is used.

Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.mathml2content

Example:

   String mathml = PublicServices.getInstance().mathml2content <math><mn>2</mn><mo>-</mo><mi>x</mi></math> ", null);

Result:

   <math><apply><minus></minus><cn>2</cn><ci>x</ci></apply></math>

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.mathml2content

Example:

   string mathml = PublicServices.getInstance().mathml2content <math><mn>2</mn><mo>-</mo><mi>x</mi></math> ", null);

Result:

   <math><apply><minus></minus><cn>2</cn><ci>x</ci></apply></math>

MathType Web provides a service to convert accessible textual representations into Presentation MathML.

Web service

   http://domain/context-path/accessible2mathml

GET and POST parameters:

  • accessible: text represents the formula.
  • lang: language code in ISO 639 format (“en”, “es”, etc).

Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.accessible2mathml

Example:

   String mathml = PublicServices.getInstance().accessible2mathml("2 minus x", "en", null);

Result:

   <math xmlns="http://www.w3.org/1998/Math/MathML"><mn>2</mn><mo>-</mo><mi>x</mi></math>

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.accessible2mathml

Example:

   string mathml = PublicServices.getInstance().accessible2mathml("2 minus x", "en", null);

Result:

   <math xmlns="http://www.w3.org/1998/Math/MathML"><mn>2</mn><mo>-</mo><mi>x</mi></math>

MathType Web provides a service to convert Presentation MathML into accessible text.

Web service

   http://domain/context-path/mathml2accessible

GET and POST parameters:

  • mml: Presentation MathML that represents the formula.
  • lang: language code in ISO 639 format (“en”, “es”, etc).

Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.mathml2accessible

Example:

   String accessible = PublicServices.getInstance().mathml2accessible("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", "en", null);

Result:

2 minus x

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.mathml2accessible

Example:

   string accessible = PublicServices.getInstance().mathml2accessible("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", "en", null);

Result:

2 minus x

MathType Web can evaluate Presentation MathML or Content MathML to a floating point value. It admits a list of variable values that will be replaced before the evaluation. There is more information about this feature here.

The list of Content MathML tags currently supported by MathType Web can be found here.

Web service

   http://domain/context-path/evaluate

GET and POST parameters:

  • mml: Presentation MathML or Content MathML that represents the formula.
  • Parameters starting with “var_”, to define variable values. Example: “var_x=4.5”.
Examples:

Java

Detailed information is available in the reference page:

PublicServicesInterface.evaluate

Example:

     Properties variables = new Properties();
     variables.setProperty("x", "4.5");
     double result = PublicServices.getInstance().evaluate("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", variables, null);

Result:

-2.5

.NET

Detailed information is available in the reference page (although the documentation itself is a Javadoc):

PublicServicesInterface.evaluate

Example:

     Dictionary<string, string> variables = new Dictionary<string, string>();
     variables["x"] = "4.5";
     double result = PublicServices.getInstance().evaluate("<math><mn>2</mn><mo>-</mo><mi>x</mi></math>", variables, null);

Result:

-2.5

Coverage evaluation

the symbols appearing in the toolbar are the only ones that can be evaluated. Some extra simbols like || for absolute value.

All services now accept these request parameters:

httpstatus: If true then the service will return HTTP status code 5xx on error. Otherwise, if not defined or false, the service does not label errors; always returns HTTP status code 200.