[GH-ISSUE #50] Math not rendering correctly #50581

Closed
opened 2026-05-05 10:36:54 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @florencekl on GitHub (Nov 3, 2023).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/50

Originally assigned to: @tjbck on GitHub.

Describe the bug
Mathjax/Katex/Latex/Math is not rendering correctly in ollama-webui, specifically matrices seem to be rendering wrong.

To Reproduce

Ask Ollama to calculate any math equation, for this example i asked it to:

calculate the inner product of these two vectors:
∣ψ1​⟩=(34i​)
∣ψ2⟩=(2i2)∣ψ2​⟩=(2i2​)

Or ask it to repeat this exact answer:

To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors:

\[\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}\]

Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get:

\[\langle\psi_1|\psi_2\rangle = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\]

So, the inner product of the two given vectors is \(-2i\).

Expected behavior
The rendering should show the matrices/vectors in this case and display the katex notation correctly.

I am not sure what the cause of this is because the HTML output of both example look the same to me so some outer div might be the cause,

Screenshots

Ollama Example:
image

In ChatGPT the same output looks like this:
image

Originally created by @florencekl on GitHub (Nov 3, 2023). Original GitHub issue: https://github.com/open-webui/open-webui/issues/50 Originally assigned to: @tjbck on GitHub. **Describe the bug** Mathjax/Katex/Latex/Math is not rendering correctly in ollama-webui, specifically matrices seem to be rendering wrong. **To Reproduce** Ask Ollama to calculate any math equation, for this example i asked it to: ``` calculate the inner product of these two vectors: ∣ψ1​⟩=(34i​) ∣ψ2⟩=(2i2)∣ψ2​⟩=(2i2​) ``` Or ask it to repeat this exact answer: ``` To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors: \[\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}\] Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get: \[\langle\psi_1|\psi_2\rangle = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\] So, the inner product of the two given vectors is \(-2i\). ``` **Expected behavior** The rendering should show the matrices/vectors in this case and display the katex notation correctly. I am not sure what the cause of this is because the HTML output of both example look the same to me so some outer div might be the cause, **Screenshots** Ollama Example: ![image](https://github.com/ollama-webui/ollama-webui/assets/59734957/fc01fb02-7f42-4d40-ad4f-052de27971c7) In ChatGPT the same output looks like this: ![image](https://github.com/ollama-webui/ollama-webui/assets/59734957/c613bfa2-2cfa-457b-a352-273ec57f3903)
Author
Owner

@tjbck commented on GitHub (Nov 3, 2023):

Hi, Could you please copy both outputs and verify both outputs have the same latex equation (in text) to rule out the issue from the model end? Thanks.

<!-- gh-comment-id:1793172255 --> @tjbck commented on GitHub (Nov 3, 2023): Hi, Could you please copy both outputs and verify both outputs have the same latex equation (in text) to rule out the issue from the model end? Thanks.
Author
Owner

@florencekl commented on GitHub (Nov 4, 2023):

Im unable to recreate the exact results of earlier but here are two examples with their exact outputs and how theyre rendering.

It seems to be a specific issue with how matrices are rendered because all other math equations i have seen so far seem correct.

Prompt:

Please repeat all of the following text exactly after me and use math notation:

To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors:

\[\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}\]

Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get:

\[\langle\psi_1|\psi_2\rangle = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\]

So, the inner product of the two given vectors is \(-2i\).

Using ChatGPT:
image

To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors:

\[ \langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix} \]

Here, the complex conjugate of the first vector is \((3, 4i)\). The second vector is \((2i, 2)\). Using the dot product formula for complex vectors, we get:

\[ \langle\psi_1|\psi_2\rangle = 3 \times 2i + (-4i) \times 2 = 6i - 8i = -2i \]

So, the inner product of the two given vectors is \(-2i\).

Using Llama2 with ollama-webui

image

Of course! Here is the text you provided, repeated exactly after you:

$$\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}$$

Using math notation:

$$\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot (2i, 2)$$

Simplifying using the dot product formula for complex vectors:

$$\langle\psi_1|\psi_2\rangle = 3 \cdot 2i - 4i \cdot 2 = -2i$$

So, the inner product of the two given vectors is $-2i$.
<!-- gh-comment-id:1793259394 --> @florencekl commented on GitHub (Nov 4, 2023): Im unable to recreate the exact results of earlier but here are two examples with their exact outputs and how theyre rendering. It seems to be a specific issue with how matrices are rendered because all other math equations i have seen so far seem correct. Prompt: ``` Please repeat all of the following text exactly after me and use math notation: To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors: \[\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}\] Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get: \[\langle\psi_1|\psi_2\rangle = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\] So, the inner product of the two given vectors is \(-2i\). ``` Using ChatGPT: ![image](https://github.com/ollama-webui/ollama-webui/assets/59734957/aedf3289-1848-49be-bc5c-879af1628c2c) ``` To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors: \[ \langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix} \] Here, the complex conjugate of the first vector is \((3, 4i)\). The second vector is \((2i, 2)\). Using the dot product formula for complex vectors, we get: \[ \langle\psi_1|\psi_2\rangle = 3 \times 2i + (-4i) \times 2 = 6i - 8i = -2i \] So, the inner product of the two given vectors is \(-2i\). ``` Using Llama2 with ollama-webui ![image](https://github.com/ollama-webui/ollama-webui/assets/59734957/2c937d37-f7b1-4837-a110-c95ffe2279a1) ``` Of course! Here is the text you provided, repeated exactly after you: $$\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot \begin{pmatrix} 2i \\ 2 \end{pmatrix}$$ Using math notation: $$\langle\psi_1|\psi_2\rangle = (3, -4i) \cdot (2i, 2)$$ Simplifying using the dot product formula for complex vectors: $$\langle\psi_1|\psi_2\rangle = 3 \cdot 2i - 4i \cdot 2 = -2i$$ So, the inner product of the two given vectors is $-2i$. ```
Author
Owner

@tjbck commented on GitHub (Nov 4, 2023):

Hi, The issue should be solved with #51. The culprit was the markdown rendering engine. Let me know if you're facing any other additional issues with the Katex support. Thanks!

<!-- gh-comment-id:1793282539 --> @tjbck commented on GitHub (Nov 4, 2023): Hi, The issue should be solved with #51. The culprit was the markdown rendering engine. Let me know if you're facing any other additional issues with the Katex support. Thanks!
Author
Owner

@tjbck commented on GitHub (Nov 4, 2023):

image

<!-- gh-comment-id:1793283395 --> @tjbck commented on GitHub (Nov 4, 2023): ![image](https://github.com/ollama-webui/ollama-webui/assets/25473318/c7303066-eb25-445b-8e66-3b2c13d64277)
Author
Owner

@florencekl commented on GitHub (Nov 4, 2023):

Thanks so much! 👍🏻

<!-- gh-comment-id:1793439903 --> @florencekl commented on GitHub (Nov 4, 2023): Thanks so much! 👍🏻
Author
Owner

@fugohan commented on GitHub (Jun 8, 2024):

image

I tried the same thing with a llama3 and it's not working.

Here is the exact repetition of the text with math notation:

To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors:

\[⟨ψ_1|ψ_2⟩ = (3, -4i) ⋅ \begin{pmatrix} 2i \\ 2 \end{pmatrix}\]

Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get:

\[⟨ψ_1|ψ_2⟩ = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\]

So, the inner product of the two given vectors is −2i.

I also figured out that the $$ notation isn't working as well.

<!-- gh-comment-id:2155892056 --> @fugohan commented on GitHub (Jun 8, 2024): ![image](https://github.com/open-webui/open-webui/assets/46691165/6e6343b6-878c-4e4c-9bf6-e7a9e6e85748) I tried the same thing with a llama3 and it's not working. ``` Here is the exact repetition of the text with math notation: To calculate the inner product of the two vectors, we use the formula for the inner product of two complex vectors: \[⟨ψ_1|ψ_2⟩ = (3, -4i) ⋅ \begin{pmatrix} 2i \\ 2 \end{pmatrix}\] Here, the complex conjugate of the first vector is (3, 4i). The second vector is (2i, 2). Using the dot product formula for complex vectors, we get: \[⟨ψ_1|ψ_2⟩ = 3 * 2i + (-4i) * 2 = 6i - 8i = -2i\] So, the inner product of the two given vectors is −2i. ``` I also figured out that the $$ notation isn't working as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#50581