Coverage for skema/img2mml/latex2mml.py: 0%
16 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1# -*- coding: utf-8 -*-
2"""
3Convert the LaTeX equation to the corresponding presentation MathML using the MathJAX service.
4Please run the following command to initialize the MathJAX service:
5node data_generation/mathjax_server.js
6"""
8from typing import Text
9from fastapi import FastAPI
10from skema.img2mml.api import get_mathml_from_latex
11from skema.img2mml import schema
13# Create a web app using FastAPI
15app = FastAPI()
18@app.get("/ping", summary="Ping endpoint to test health of service")
19def ping():
20 return "The latex2mml service is running."
23@app.get("/get-mml", summary="Get MathML representation of a LaTeX equation")
24async def get_mathml(tex_src: str):
25 """
26 GET endpoint for generating MathML from an input LaTeX equation.
27 """
28 # convert latex string to presentation mathml
29 print(tex_src)
30 return get_mathml_from_latex(tex_src)
32@app.post("/latex2mml", summary="Get MathML representation of a LaTeX equation")
33async def mathml(eqn: schema.LatexEquation):
34 """
35 Endpoint for generating MathML from an input LaTeX equation.
36 """
37 # convert latex string to presentation mathml
38 return get_mathml_from_latex(eqn.tex_src)