chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

LaTeX Handling Improvement

Open hayescode opened this issue 1 year ago • 8 comments

Is your feature request related to a problem? Please describe. When setting latex=true in config.toml it expects mathematical formulas to be encased in $ signs. All popular LLMs are not trained with this syntax and no amount of system instructions can get the LLM to consistently output in this format. Instead it looks like this:

image

Describe the solution you'd like Switch latex rendering to standard format. This also fixes the bug causing clashes with non-formula $ signs.

Describe alternatives you've considered Adding You must ALWAYS encapsulate formulas in '$' signs. For example: $$ y = ax^2 + bx + c $$. If you do anything else for any reason then you are a bad assistant

Additional context https://discord.com/channels/1088038867602526210/1196096445804187748/1196096445804187748

hayescode avatar Aug 16 '24 21:08 hayescode

I very strongly agree with hayescode. I have exact same problems, too. I tried to let LLM input '$' when LLM intent to input LaTeX, but I failed. Please, fix this problems.

Rendering error ex. 1 error

Rendering error ex. 2 error2

kungmo avatar Aug 18 '24 09:08 kungmo

Hi all, i was struggling till i read the solution of @hayescode, however as @kungmo i got still some issue. I've improved the system message and now i do not have anymore issues. Here my solution: == About LaTeX Math Mode== You MUST ALWAYS encapsulate LaTeX/KaTeX formulas in a KaTeX syntax with double '$' signs: $$…$$ If you do anything else for any reason then you are a bad assistant Example of wrong syntax: - [ y = ax^2 + bx + c ] - ( y = ax^2 + bx + c ) - \( y = ax^2 + bx + c \) Example of correct syntax: - $$ y = ax^2 + bx + c $$.

ThinkerNinja avatar Aug 26 '24 21:08 ThinkerNinja

Hi all, i was struggling till i read the solution of @hayescode, however as @kungmo i got still some issue. I've improved the system message and now i do not have anymore issues. Here my solution: == About LaTeX Math Mode== You MUST ALWAYS encapsulate LaTeX/KaTeX formulas in a KaTeX syntax with double '$' signs: … If you do anything else for any reason then you are a bad assistant Example of wrong syntax: - [ y = ax^2 + bx + c ] - ( y = ax^2 + bx + c ) - ( y = ax^2 + bx + c ) Example of correct syntax: - $$ y = ax^2 + bx + c $$.

Thank you for your solution. I applied it to prompt for my chatbot, but it sometimes works and sometimes does not work. When I use Google Gemma 2 9B, it works well. But now, I am using LG EXAONE 3.0 7.8B for specialiezed characteristics understanding Korean. When I apply your prompt in Korean, it does not fit perfect.

Still, I want Chainlit be able to handle KaTeX and LaTeX for any LLM. Here's my chatbot address: http://acer2.snu.ac.kr:8501

kungmo avatar Aug 27 '24 07:08 kungmo

when I use the correct formula on question prompt and send it to the LLM it does the correct latex conversion. but when I try to convert the LLM response to the correct formula and send/show it to the user, it renders the answer as plain text not latex. Question prompt and answer prompt has different behavior or sth. else ? Do you have any ideas ?

alkin1 avatar Sep 05 '24 18:09 alkin1

Is there a way to change the LaTeX wild character from $ to something else? Apparently, as mentioned in the document $ is impacting the conversations which involves calculations with dollar sign.

Screenshot 2024-12-09 at 4 02 51 PM

deneshkumar avatar Dec 09 '24 21:12 deneshkumar

I second this, Chainlit should have full LaTeX/KaTeX support

Fractal-0 avatar Jan 19 '25 05:01 Fractal-0

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Jul 25 '25 02:07 github-actions[bot]

Still an issue

hayescode avatar Jul 25 '25 14:07 hayescode