Skip to content

Conversation

@Abhijay007
Copy link
Collaborator

Related Issue : #3858 and Discussion : #5737

PR Description

This PR adds LaTeX math rendering to markdown messages using KaTeX. It supports inline math ($...$) and block math ($$...$$) with proper styling for both light and dark themes. It also fixes the issue where math and scientific expressions were shown as raw LaTeX (e.g., \frac, \sqrt) instead of rendered symbols.

Changes Made

In ui/desktop/src/components/MarkdownContent.tsx file

  • Imported remark-math, rehype-katex, and KaTeX CSS
  • Added remarkMath to remarkPlugins
  • Added rehypeKatex to rehypePlugins with error handling

In ui/desktop/src/styles/main.css file

  • Added KaTeX styling

In ui/desktop/package.json file : Added katex@^0.16.25 , Added remark-math@^6.0.0 , Added rehype-katex@^7.0.1

Type of Change

  • Feature

AI Assistance

  • This PR was created or reviewed with AI assistance – used Goose to decide between using KaTeX or MCP UI and to validate the approach.

Testing

Tested in the desktop UI with multiple test messages, both with and without math blocks, in dark and light modes.

Screenshots / Demos (for UX changes)

Before:

beforeMaths

After:

afterMath

Copilot AI review requested due to automatic review settings November 17, 2025 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds LaTeX math rendering support to the desktop UI using KaTeX, enabling proper display of mathematical and scientific expressions in markdown messages. Previously, LaTeX expressions were shown as raw text (e.g., \frac, \sqrt), but now they render as proper mathematical symbols with support for both inline ($...$) and block ($$...$$) math syntax.

Key Changes

  • Integrated KaTeX rendering into the markdown pipeline using remark-math and rehype-katex plugins
  • Added custom styling for math expressions with theme-aware colors and proper layout
  • Added three new dependencies: katex, remark-math, and rehype-katex

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
ui/desktop/src/components/MarkdownContent.tsx Added KaTeX plugins to the ReactMarkdown component with error handling configuration
ui/desktop/src/styles/main.css Added CSS styling for math expressions with proper theme support for light and dark modes
ui/desktop/package.json Added three new dependencies for KaTeX rendering support
ui/desktop/package-lock.json Lock file updates for new dependencies and their transitive dependencies
Files not reviewed (1)
  • ui/desktop/package-lock.json: Language not supported

@michaelneale
Copy link
Collaborator

I like this - tagging @zanesq who may have thoughts as well. Only possible downside are those new dependencies but they seem pretty well maintained and nice, kudos @Abhijay007 !

@michaelneale michaelneale self-assigned this Nov 24, 2025
Copy link
Collaborator

@zanesq zanesq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@zanesq zanesq merged commit 3490822 into block:main Nov 24, 2025
21 checks passed
michaelneale added a commit that referenced this pull request Nov 25, 2025
* main:
  docs: add DataHub MCP server extension documentation (#5769)
  docs: lowercase goose in remaining topics (#5861)
  docs: lowercase goose in getting-started and guides topics (#5857)
  Fix multi tool calling (#5855)
  fix(#5626 #5832): handle multiple content chunks & images better (#5839)
  chore: some old code hanging around, and mention configure cli (#5822)
  feat : add support for math / science symbology via katex (#5773)
  feat : add ability to see error message in toast (#5851)
kskarthik pushed a commit to kskarthik/goose that referenced this pull request Nov 25, 2025
kskarthik pushed a commit to kskarthik/goose that referenced this pull request Nov 26, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
alex-ameen added a commit to alex-ameen/goose that referenced this pull request Dec 17, 2025
Fixes issue where underscores and dollar signs in plain text were being
interpreted as LaTeX/KaTeX syntax, causing rendering issues in the UI.

The problem was introduced in PR block#5773 which added KaTeX support via
remarkMath and rehypeKatex plugins. These plugins interpret:
- `_` as subscript markers
- `$...$` as inline math delimiters

This caused issues with:
- Shell commands like: cmd "$FOO" --opt="$BAR"
- Variable names: variable_name, another_variable
- File paths: /path/to/my_file_name.txt
- Log output with underscores and dollar signs

Solution:
- Added escapeLatexOutsideCode() function that identifies code blocks
  and inline code sections
- Escapes `_` to `\_` and `$` to `\$` only in plain text
- Preserves original characters inside code blocks and inline code
- Also escapes backslashes to prevent double-escaping issues

Added comprehensive tests covering:
- Underscores in plain text vs code
- Dollar signs in shell commands vs code blocks
- Mixed content scenarios
- File paths and environment variables
- Log output with special characters
@zanesq
Copy link
Collaborator

zanesq commented Dec 18, 2025

@Abhijay007 we've had some reports internally about LaTeX text rendering issues. Do you want to look into it or revert this for now?

Screenshot 2025-12-17 at 4 40 04 PM image (31)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants