[PR #5655] [MERGED] fix: Fix KaTeX Rendering #44778

Closed
opened 2026-04-29 18:58:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: dev


📝 Commits (6)

  • 2145463 fix: fix katex rendering
  • 377cc42 fix: Remove unnecessary logging
  • 0bfbace fix: Simplify regex
  • e48d66f fix: Remove unnecessary logging
  • 3f1255b fix: Change inline and block delimiters
  • 30e65b3 fix: Add comments

📊 Changes

2 files changed (+88 additions, -91 deletions)

View changed files

📝 src/lib/utils/index.ts (+0 -18)
📝 src/lib/utils/marked/katex-extension.ts (+88 -73)

📄 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

This PR attempts to fix some issues in KaTex rendering, including:

  • Inline KaTeX not rendering when using delimiters other than $...$
  • Block KaTeX rendering as inline KaTeX

Changed

  • $$...$$ is now correctly registered as displaymath
  • Add start token computation for every math delimiter
  • Correctly mark block KaTeX

Screenshots or Videos

Here is the screenshot of previous version. The model is Qwen 2.5, which notably uses \(...\) and \[...\] as math delimiters.
katex_old
Notice that block math equation is rendered as inline math equations, and some inline equations are not rendered.

In comparison, here is the screenshot after this PR:
katex_new


🔄 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/5655 **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 (6) - [`2145463`](https://github.com/open-webui/open-webui/commit/214546399a89a5e3ce50a424b017b2b4aad895f1) fix: fix katex rendering - [`377cc42`](https://github.com/open-webui/open-webui/commit/377cc427b6701708a38ce5af01508cc649e27ce2) fix: Remove unnecessary logging - [`0bfbace`](https://github.com/open-webui/open-webui/commit/0bfbace9aa38ec93e99b6d48d14e3f75acaa8428) fix: Simplify regex - [`e48d66f`](https://github.com/open-webui/open-webui/commit/e48d66f918d61440ebd3cff950004709f83a0c3b) fix: Remove unnecessary logging - [`3f1255b`](https://github.com/open-webui/open-webui/commit/3f1255b39e8cef8ee37ab147d107bda67549c27b) fix: Change inline and block delimiters - [`30e65b3`](https://github.com/open-webui/open-webui/commit/30e65b33f6ca25b462d0657171d949286d19c45d) fix: Add comments ### 📊 Changes **2 files changed** (+88 additions, -91 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/utils/index.ts` (+0 -18) 📝 `src/lib/utils/marked/katex-extension.ts` (+88 -73) </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? - [x] **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 This PR attempts to fix some issues in KaTex rendering, including: - Inline KaTeX not rendering when using delimiters other than `$...$` - Block KaTeX rendering as inline KaTeX ### Changed - `$$...$$` is now correctly registered as displaymath - Add start token computation for every math delimiter - Correctly mark block KaTeX --- ### Screenshots or Videos Here is the screenshot of previous version. The model is Qwen 2.5, which notably uses `\(...\)` and `\[...\]` as math delimiters. <img width="815" alt="katex_old" src="https://github.com/user-attachments/assets/b1e3a85e-878a-4743-861d-1556054fb965"> Notice that block math equation is rendered as inline math equations, and some inline equations are not rendered. In comparison, here is the screenshot after this PR: <img width="809" alt="katex_new" src="https://github.com/user-attachments/assets/95ee84da-2578-4b77-8496-511febde79db"> --- <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 2026-04-29 18:58:48 -05: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#44778