Tra.pt Tools Logo Tra.pt Tool Blog

TeX-to-MathML Function

Here's what you need to know.

Note: Please only use this as a "build-time" tool. Fetching client-side over and over will overload the system. Once you've got the equation, you don't need to keep fetching the markup at every user visit. For dynamic rendering, please use Temml.

Endpoint

GET https://trapt.vercel.app/api/mathml

Arguments


Headers Details
Content-Type \ required "text/plain"
Accept "application/json"

.

Body Details
Body \ required This is the TeX text math function as a string. Only escape characters if your tool requires it.

Response


Body Details
Body "application/json"

Example:

{
  "title": "Tra.pt Tools Math Processor",
  "math": "<math>...</math>",
  "tex": "original TeX"
}

cURL:

$ curl --request GET \
  --url https://trapt.vercel.app/api/mathml \
  --header 'Accept: application/json' \
  --header 'content-type: text/plain' \
  --data 'G_{\mu\nu}=8\pi G\left(T_{\mu\nu}+{\large \rho}_\Lambda {\large g}_{\mu\nu} \right)'

Javascript:

const options = {
  method: 'GET',
  headers: {'content-type': 'text/plain', Accept: 'application/json'},
  body: 'G_{\mu\nu}=8\pi G\left(T_{\mu\nu}+{\large \rho}_\Lambda {\large g}_{\mu\nu} \right)'
};

fetch('https://trapt.vercel.app/api/mathml', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Python:

import http.client

conn = http.client.HTTPSConnection("trapt.vercel.app")

payload = "G_{\\mu\\nu}=8\\pi G\\left(T_{\\mu\\nu}+{\\large \\rho}_\\Lambda {\\large g}_{\\mu\\nu} \\right)"

headers = {
    'content-type': "text/plain",
    'Accept': "application/json"
    }

conn.request("GET", "/api/mathml", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Go:

package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://trapt.vercel.app/api/mathml"

	payload := strings.NewReader("G_{\\mu\\nu}=8\\pi G\\left(T_{\\mu\\nu}+{\\large \\rho}_\\Lambda {\\large g}_{\\mu\\nu} \\right)")

	req, _ := http.NewRequest("GET", url, payload)

	req.Header.Add("content-type", "text/plain")
	req.Header.Add("Accept", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Response for All:

{
  "title": "Tra.pt Tools Math Processor",
  "math": "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" class=\"mathml\" display=\"block\" ><mrow><msub><mi>G</mi><mrow><mi>μ</mi><mi>ν</mi></mrow></msub><mo>=</mo><mn>8</mn><mi>π</mi><mi>G</mi><mrow><mo fence=\"true\" form=\"prefix\">(</mo><msub><mi>T</mi><mrow><mi>μ</mi><mi>ν</mi></mrow></msub><mo>+</mo><msub><mstyle mathsize=\"1.2000em\"><mi>ρ</mi></mstyle><mrow><mi mathvariant=\"normal\">Λ</mi></mrow></msub><msub><mstyle mathsize=\"1.2000em\"><mi>g</mi></mstyle><mrow><mi>μ</mi><mi>ν</mi></mrow></msub><mo fence=\"true\" form=\"postfix\">)</mo></mrow></mrow></math>",
  "tex": "G_{\\mu\\nu}=8\\pi G\\left(T_{\\mu\\nu}+{\\large \\rho}_\\Lambda {\\large g}_{\\mu\\nu} \\right)"
}

Recent posts