gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
31.76k stars 2.37k forks source link

Incorrect LaTeX formula display in gr.chatbot and gr.ChatInterface #8780

Closed MrCool1981 closed 1 month ago

MrCool1981 commented 1 month ago

Describe the bug

A valid KaTeX expression:

a_w = \frac{\text{moles}_{\text{water}}}{\text{moles}_{\text{water}} + \text{moles}_{\text{solute}}}

is successfully rendered using KaTeX tool: https://katex.org/

However, it is not displayed properly in gr.chatbot and gr.ChatInterface when wrapped in double $$:

$$a_w = \frac{\text{moles}_{\text{water}}}{\text{moles}_{\text{water}} + \text{moles}{\text{solute}}}$$

Once, the underscores are removed from denominator, the formula is displayed correctly:

$$a_w = \frac{\text{moles}_{\text{water}}}{\text{moles}{\text{water}} + \text{moles}{\text{solute}}}$$

The subscript text in the denominator is displayed correctly when "\text" tag is removed:

$$aw = \frac{moles_{water}}{moles_{water} + moles_{solute}}$$

Have you searched existing issues? 🔎

Reproduction

import random
import gradio as gr

def random_response(message, history):
    return random.choice(["Yes", "No"])

demo = gr.ChatInterface(random_response)

if __name__ == "__main__":
    demo.launch()

Screenshot

image image

Logs

No response

System Info

gradio==4.31.5
Python 3.12.3

Severity

I can work around it

abidlabs commented 1 month ago

Thanks for opening this issue @MrCool1981! Cc @dawoodkhan82

dawoodkhan82 commented 1 month ago

Must be an issue with how we are parsing markdown. Will take a look.