[PR #5675] [MERGED] fix: Fix KaTeX Rendering (Followup) #8534

Closed
opened 2025-11-11 17:58:57 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/5675
Author: @sp301415
Created: 9/24/2024
Status: Merged
Merged: 9/24/2024
Merged by: @tjbck

Base: devHead: dev


📝 Commits (1)

  • d501ece fix: Fix KaTeX corner cases

📊 Changes

1 file changed (+15 additions, -10 deletions)

View changed files

📝 src/lib/utils/marked/katex-extension.ts (+15 -10)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests for validating the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

While most of the KaTeX rendering issues were fixed in #5655, there were some remaining corner cases.
For example,

This was not registered as block math equation:
\[
abc
\]
But this was.

\[
x
\]

Also, mixing inline math and special characters lead to rendering errors, such as (\(a\)). This PR attempts to fix them.

Changed

  • Rewrote inline and block math delimiters. Following ChatGPT's behavior, now block math delimiters doubles as inline delimiters by not appending a newline character. For instance, \[ ... \] acts as an inline delimiter, and \[\n ... \n\] acts as an block delimiter.
  • Added more checks to allowed special characters before/after inline math.
  • Added \begin{equation} ... \end{equation} to the delimiters.

Screenshots or Videos

Before:
katex_old_1
After:
katex_new_1
Before:
katex_old_2
After:
katex_new_2
It also fixes #3577.
Before:
katex_old_3
After:
katex_new_3


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/5675 **Author:** [@sp301415](https://github.com/sp301415) **Created:** 9/24/2024 **Status:** ✅ Merged **Merged:** 9/24/2024 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `dev` --- ### 📝 Commits (1) - [`d501ece`](https://github.com/open-webui/open-webui/commit/d501ece24776ac85f0ba79252a7f37ac5b6bfbc9) fix: Fix KaTeX corner cases ### 📊 Changes **1 file changed** (+15 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/utils/marked/katex-extension.ts` (+15 -10) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests for validating the changes? - [ ] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description While most of the KaTeX rendering issues were fixed in #5655, there were some remaining corner cases. For example, ``` This was not registered as block math equation: \[ abc \] ``` ``` But this was. \[ x \] ``` Also, mixing inline math and special characters lead to rendering errors, such as `(\(a\))`. This PR attempts to fix them. ### Changed - Rewrote inline and block math delimiters. Following ChatGPT's behavior, now block math delimiters doubles as inline delimiters by not appending a newline character. For instance, `\[ ... \]` acts as an inline delimiter, and `\[\n ... \n\]` acts as an block delimiter. - Added more checks to allowed special characters before/after inline math. - Added `\begin{equation} ... \end{equation}` to the delimiters. --- ### Screenshots or Videos Before: <img width="743" alt="katex_old_1" src="https://github.com/user-attachments/assets/661d5a1d-6ec3-4b79-88cf-56bd190e9962"> After: <img width="745" alt="katex_new_1" src="https://github.com/user-attachments/assets/8a29e717-3392-4ea4-88f4-268ae09596d7"> Before: <img width="746" alt="katex_old_2" src="https://github.com/user-attachments/assets/0c58ffcd-34c8-4fab-8396-4ecbc56551b4"> After: <img width="737" alt="katex_new_2" src="https://github.com/user-attachments/assets/d6f06b1d-6bdc-4c32-b8e5-e6151c57bee7"> It also fixes #3577. Before: <img width="732" alt="katex_old_3" src="https://github.com/user-attachments/assets/52fc52bb-6515-44b2-89e2-ba8f2d948587"> After: <img width="737" alt="katex_new_3" src="https://github.com/user-attachments/assets/9c10197d-e401-4a19-8d8e-b719b50f1586"> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-11 17:58:57 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#8534