[GH-ISSUE #2875] [FEAT]: Latex Math Formula Render #1828

Closed
opened 2026-02-22 18:26:42 -05:00 by yindo · 6 comments
Owner

Originally created by @JesseM1024 on GitHub (Dec 18, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2875

What would you like to see?

Currently it can render code blocks correctly but it cannot render latex formulas. Sometimes the readability of Latex related responses are quite low. For example:
图片

Originally created by @JesseM1024 on GitHub (Dec 18, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2875 ### What would you like to see? Currently it can render code blocks correctly but it cannot render latex formulas. Sometimes the readability of Latex related responses are quite low. For example: ![图片](https://github.com/user-attachments/assets/1d9fc766-68bc-46e9-b27c-a01cd622a014)
yindo added the enhancementfeature request labels 2026-02-22 18:26:42 -05:00
yindo closed this issue 2026-02-22 18:26:42 -05:00
Author
Owner

@Dljdd commented on GitHub (Dec 23, 2024):

Hi I can help with implementing this

@Dljdd commented on GitHub (Dec 23, 2024): Hi I can help with implementing this
Author
Owner

@spencerthayer commented on GitHub (Dec 23, 2024):

@Dljdd this would be incredibly useful; thank you.

@spencerthayer commented on GitHub (Dec 23, 2024): @Dljdd this would be incredibly useful; thank you.
Author
Owner

@geekmdtravis commented on GitHub (Jan 24, 2025):

Just lending my vote for this as a high-value feature, while recognizing it's likely to be somewhat tedious to implement. Some of the LaTeX render failures are simply bad LLM output, but many of the cases not captured by AnythingLLM are quite clearly valid latex blocks.

Image
@geekmdtravis commented on GitHub (Jan 24, 2025): Just lending my vote for this as a high-value feature, while recognizing it's likely to be somewhat tedious to implement. Some of the LaTeX render failures are simply bad LLM output, but many of the cases not captured by AnythingLLM are quite clearly valid latex blocks. <img width="778" alt="Image" src="https://github.com/user-attachments/assets/f4bb0032-2605-447c-86ec-0689489e7d8c" />
Author
Owner

@Rrojaski commented on GitHub (Jan 27, 2025):

It appears that the LaTeX parser being used does not support the delimiters \( ... \) and \[ ... \] that the LLM outputs. Here's a GitHub issue I found asking for a workaround for that package: markdown-it-katex Issue #10 -- No idea why the issue was closed without any resolution. 🥴

@Rrojaski commented on GitHub (Jan 27, 2025): It appears that the LaTeX parser being used does not support the delimiters \\( ... \\) and \\[ ... \\] that the LLM outputs. Here's a GitHub issue I found asking for a workaround for that package: [markdown-it-katex Issue #10](https://github.com/waylonflinn/markdown-it-katex/issues/10) -- No idea why the issue was closed without any resolution. 🥴
Author
Owner

@timothycarambat commented on GitHub (Jan 27, 2025):

Maybe we can just fork that library and add more delimiters to cover this? Not sure, but that is basically the root cause here. The main issue is that [] and () are valid markdown, so they can conflict

Edit:

Can someone copy-paste some text output that is not rendering in AnythingLLM so i can test this?

@timothycarambat commented on GitHub (Jan 27, 2025): Maybe we can just fork that library and add more delimiters to cover this? Not sure, but that is basically the root cause here. The main issue is that `[]` and `()` are valid markdown, so they can conflict Edit: Can someone copy-paste some text output that is not rendering in AnythingLLM so i can test this?
Author
Owner

@timothycarambat commented on GitHub (Jan 27, 2025):

Image

First chat raw - using $$ notation as well as $

Sure! A Taylor series of a function f(x) centered at a point a can be represented in LaTeX as:

$$f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}{(x-a)}^n$$

Here, $f^{(n)}(a)$ represents the nth derivative of f(x) evaluated at x = a, and n! represents the factorial of n. The summation symbol $\sum$ indicates that we are summing all the terms from n = 0 to infinity.

Using block notation

Sure! Here is the same Taylor series using the LaTeX notation that uses \[...\] and \(...\):

\[f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}{(x-a)}^n\]
In this case, we used \[ and \] to enclose the equation, and \( and \) to enclose the variables and symbols within the equation.
@timothycarambat commented on GitHub (Jan 27, 2025): <img width="1298" alt="Image" src="https://github.com/user-attachments/assets/596920d4-f279-49aa-9421-68e880d0722f" /> First chat raw - using `$$` notation as well as `$` ``` Sure! A Taylor series of a function f(x) centered at a point a can be represented in LaTeX as: $$f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}{(x-a)}^n$$ Here, $f^{(n)}(a)$ represents the nth derivative of f(x) evaluated at x = a, and n! represents the factorial of n. The summation symbol $\sum$ indicates that we are summing all the terms from n = 0 to infinity. ``` Using block notation ``` Sure! Here is the same Taylor series using the LaTeX notation that uses \[...\] and \(...\): \[f(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}{(x-a)}^n\] In this case, we used \[ and \] to enclose the equation, and \( and \) to enclose the variables and symbols within the equation. ```
yindo changed title from [FEAT]: Latex Math Formula Render to [GH-ISSUE #2875] [FEAT]: Latex Math Formula Render 2026-06-05 14:42:55 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1828