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:
In ChatGPT the same output looks like this:
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:

In ChatGPT the same output looks like this:

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

```
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

```
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$.
```
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!
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):

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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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:
Or ask it to repeat this exact answer:
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:

In ChatGPT the same output looks like this:

@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.
@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:
Using ChatGPT:

Using Llama2 with ollama-webui
@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!
@tjbck commented on GitHub (Nov 4, 2023):
@florencekl commented on GitHub (Nov 4, 2023):
Thanks so much! 👍🏻
@fugohan commented on GitHub (Jun 8, 2024):
I tried the same thing with a llama3 and it's not working.
I also figured out that the $$ notation isn't working as well.