File size: 810 Bytes
282ba81
 
77c47bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282ba81
77c47bb
 
 
 
 
282ba81
77c47bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr

def latex_to_html(latex_str):
    # MathJax를 이용하여 LaTeX 수식을 HTML로 변환합니다.
    return f"""
    <!DOCTYPE html>
    <html>
    <body>
        <script src='https://polyfill.io/v3/polyfill.min.js?features=es6'></script>
        <script type="text/javascript" async
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML">
        </script>
        <p>
        $$ {latex_str} $$
        </p>
    </body>
    </html>
    """

iface = gr.Interface(fn=latex_to_html,
                    inputs="text",
                    outputs="html",
                    examples=[["E = mc^2"], ["\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}"]],
                    title="LaTeX Renderer with MathJax")

iface.launch(share=True)