Skip to content

[FEAT]: Latex Math Formula Render #2875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JesseM1024 opened this issue Dec 18, 2024 · 6 comments · Fixed by #3040
Closed

[FEAT]: Latex Math Formula Render #2875

JesseM1024 opened this issue Dec 18, 2024 · 6 comments · Fixed by #3040
Labels
enhancement New feature or request feature request

Comments

@JesseM1024
Copy link

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:
图片

@JesseM1024 JesseM1024 added enhancement New feature or request feature request labels Dec 18, 2024
@Dljdd
Copy link

Dljdd commented Dec 23, 2024

Hi I can help with implementing this

@spencerthayer
Copy link

@Dljdd this would be incredibly useful; thank you.

@geekmdtravis
Copy link

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

@Rrojaski
Copy link
Contributor

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. 🥴

@timothycarambat
Copy link
Member

timothycarambat commented 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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants