open-webui icon indicating copy to clipboard operation
open-webui copied to clipboard

enh: configurable latex delimiters

Open 0x7CFE opened this issue 1 year ago • 7 comments

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

0x7CFE avatar May 27 '24 20:05 0x7CFE

Me, too. Sometimes the math doesn't work

Yanyutin753 avatar Jul 06 '24 01:07 Yanyutin753

image

Sometimes the math doesn't work

Yanyutin753 avatar Jul 10 '24 10:07 Yanyutin753

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

Yanyutin753 avatar Jul 17 '24 10:07 Yanyutin753

why not fix it?

MangoFF avatar Aug 09 '24 03:08 MangoFF

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 avatar Aug 09 '24 05:08 Yanyutin753

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 avatar Sep 01 '24 00:09 chrisoutwright

Same issue, the tex rendering is not working:

image

RexWzh avatar Sep 01 '24 14:09 RexWzh