enh: configurable latex delimiters #1049

Closed
opened 2025-11-11 14:36:15 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @0x7CFE on GitHub (May 27, 2024).

Is your feature request related to a problem? Please describe.
OpenWebUI is able to render TeX markup when it's enclosed in double $ signs, such as $$y = f(x)$$. I did my best but failed to explain that to Llama-3. It still uses single $ once in a while.

Describe the solution you'd like
It would be nice to have a way to configure the renderer, so that single $ entries would also be treated as TeX markup. Even better if $ quotes would be automatically treated and correctly rendered as an inline markup.

Describe alternatives you've considered

  • Use ChatGPT... It just works.
  • Invent a prompt that would prevent a model from using single-$ styled formulas.

Additional context
Sample output: https://openwebui.com/c/korvin/340ca756-a00b-4408-8acc-bc0c39fbb426

Note that some formulas are syntactically correct but not rendered properly due to single $ quotation.

It looks even worse in the UI:
image

Originally created by @0x7CFE on GitHub (May 27, 2024). **Is your feature request related to a problem? Please describe.** OpenWebUI is able to render TeX markup when it's enclosed in double `$` signs, such as `$$y = f(x)$$`. I did my best but failed to explain that to Llama-3. It still uses single `$` once in a while. **Describe the solution you'd like** It would be nice to have a way to configure the renderer, so that single `$` entries would also be treated as TeX markup. Even better if `$` quotes would be automatically treated and correctly rendered as an inline markup. **Describe alternatives you've considered** - Use ChatGPT... It just works. - Invent a prompt that would prevent a model from using single-`$` styled formulas. **Additional context** Sample output: https://openwebui.com/c/korvin/340ca756-a00b-4408-8acc-bc0c39fbb426 Note that some formulas are syntactically correct but not rendered properly due to single `$` quotation. It looks even worse in the UI: ![image](https://github.com/open-webui/open-webui/assets/3784017/a06a13a0-0d27-4456-bf09-214359d2b9ec)
Author
Owner

@Yanyutin753 commented on GitHub (Jul 6, 2024):

Me, too. Sometimes the math doesn't work

@Yanyutin753 commented on GitHub (Jul 6, 2024): Me, too. Sometimes the math doesn't work
Author
Owner

@Yanyutin753 commented on GitHub (Jul 10, 2024):

image

Sometimes the math doesn't work

@Yanyutin753 commented on GitHub (Jul 10, 2024): ![image](https://github.com/open-webui/open-webui/assets/132346501/b882818c-7206-420f-ace5-d30e5734e9c5) ### Sometimes the math doesn't work
Author
Owner

@Yanyutin753 commented on GitHub (Jul 17, 2024):

https://github.com/open-webui/open-webui/pull/3930 Look at this. I tried to solve this problem

@Yanyutin753 commented on GitHub (Jul 17, 2024): https://github.com/open-webui/open-webui/pull/3930 Look at this. I tried to solve this problem
Author
Owner

@MangoFF commented on GitHub (Aug 9, 2024):

why not fix it?

@MangoFF commented on GitHub (Aug 9, 2024): why not fix it?
Author
Owner

@Yanyutin753 commented on GitHub (Aug 9, 2024):

why not fix it?

The version is not the same, the author can pay attention to the latest dev version after the fix, and provide corresponding examples so that the author can better fix

@Yanyutin753 commented on GitHub (Aug 9, 2024): > why not fix it? The version is not the same, the author can pay attention to the latest dev version after the fix, and provide corresponding examples so that the author can better fix
Author
Owner

@chrisoutwright commented on GitHub (Sep 1, 2024):

For me it breaks in version 0.3.16 still when models are using $$ without newlines. And if it uses align or equation environments, it would break also.

Screenshot_20240901_020430_Vivaldi

If told to do newlines with $$ then it's ok

Screenshot_20240901_021235_Vivaldi

I added the following styleguide and it helped a bit:

`

### Key Guidelines for Displaying Equations in LaTeX

1. **Inline Math (`$...$`)**:
   - Use for simple equations within text.
   - Example: `The formula is $x = 2$.`
   - **Important**: Avoid placing math expressions within brackets like `($V^\pi(s)$)`. Instead, use `\(...\)` for proper formatting:
     ```markdown
     Incorrect: ($V^\pi(s)$)
     Correct: \((V^\pi(s))\)
     ```

2. **Bold Text and Math**:
   - Avoid placing math directly within bold syntax. Apply bold formatting only to text and NOT math.
   - **Incorrect**: `**Value Function Update ($V_\theta(s)$):**`
   - **Correct**: `**Value Function Update:** \(V_\theta(s)\)`

3. **Display Math (`\[...\]` or `$$...$$`)**:
   - Use for equations that stand alone on their own line.
   - Example: 
     \[
     y = mx + b
     \]
   - Or equivalently:
     $$
     y = mx + b
     $$

4. **Matrix Environments**:
   - Use `bmatrix` or `pmatrix` within display math for matrices.
   - Example:
     \[
     A = \begin{bmatrix}
     1 & 2 \\
     3 & 4
     \end{bmatrix}
     \]

5. **Multiline Equations**:
   - Avoid `align` or `equation` environments for multiline equations. Use separate display math for each line.
   - **Incorrect**: 
     ```latex
     \begin{align}
     \nabla_\theta J(\pi_\theta) &= \sum_t \gamma^t r(s_t, a_t) \\
     \Delta \theta &= \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a)
     \end{align}
     ```
   - **Correct**:
     \[
     \nabla_\theta J(\pi_\theta) = \sum_t \gamma^t r(s_t, a_t)
     \]
     \[
     \Delta \theta = \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a)
     \]

image

@chrisoutwright commented on GitHub (Sep 1, 2024): For me it breaks in version 0.3.16 still when models are using $$ without newlines. And if it uses align or equation environments, it would break also. ![Screenshot_20240901_020430_Vivaldi](https://github.com/user-attachments/assets/d6b2ebe9-3bad-4548-846f-3fd95663a00c) If told to do newlines with $$ then it's ok ![Screenshot_20240901_021235_Vivaldi](https://github.com/user-attachments/assets/33eec280-56a3-40a4-9a77-14530fc0ad4f) I added the following styleguide and it helped a bit: ` ```markdown ### Key Guidelines for Displaying Equations in LaTeX 1. **Inline Math (`$...$`)**: - Use for simple equations within text. - Example: `The formula is $x = 2$.` - **Important**: Avoid placing math expressions within brackets like `($V^\pi(s)$)`. Instead, use `\(...\)` for proper formatting: ```markdown Incorrect: ($V^\pi(s)$) Correct: \((V^\pi(s))\) ``` 2. **Bold Text and Math**: - Avoid placing math directly within bold syntax. Apply bold formatting only to text and NOT math. - **Incorrect**: `**Value Function Update ($V_\theta(s)$):**` - **Correct**: `**Value Function Update:** \(V_\theta(s)\)` 3. **Display Math (`\[...\]` or `$$...$$`)**: - Use for equations that stand alone on their own line. - Example: \[ y = mx + b \] - Or equivalently: $$ y = mx + b $$ 4. **Matrix Environments**: - Use `bmatrix` or `pmatrix` within display math for matrices. - Example: \[ A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \] 5. **Multiline Equations**: - Avoid `align` or `equation` environments for multiline equations. Use separate display math for each line. - **Incorrect**: ```latex \begin{align} \nabla_\theta J(\pi_\theta) &= \sum_t \gamma^t r(s_t, a_t) \\ \Delta \theta &= \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a) \end{align} ``` - **Correct**: \[ \nabla_\theta J(\pi_\theta) = \sum_t \gamma^t r(s_t, a_t) \] \[ \Delta \theta = \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a) \] ```` ![image](https://github.com/user-attachments/assets/2dc4e362-9a82-4705-99b1-d8680ec7a122)
Author
Owner

@RexWzh commented on GitHub (Sep 1, 2024):

Same issue, the tex rendering is not working:

image
@RexWzh commented on GitHub (Sep 1, 2024): Same issue, the tex rendering is not working: <img width="796" alt="image" src="https://github.com/user-attachments/assets/e4f816a3-6784-4185-86c5-d5f077b8a5b7">
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#1049