Skip to content

Feature request: Normalize \(...\) and \[...\] to $$ ... $$ #323

@shloimy-wiesel

Description

@shloimy-wiesel

Bug Description

According to the docs, Streamdown only renders mathematical expressions when they are wrapped in double dollar signs ($$).
However, AI-generated content (and many LaTeX sources) commonly use \(...\) for inline math and \[...\] for block math.

As a result, valid mathematical expressions produced by AI models are not rendered unless manually converted to $$.

This creates a mismatch between Streamdown’s expected syntax and common AI/LaTeX output.

Steps to Reproduce

  1. Use Streamdown with the default math configuration.
  2. Generate mathematical content using an AI model, for example openai/gpt-oss-120b, without explicitly specifying the required math delimiter format.
  3. The AI may output math using common LaTeX conventions, such as:
## Inline math with \(...\)

This is inline math: \(x = \frac{1}{2}\) and another one \(E = mc^2\).

## Block math with \[...\]

\[
\int_{0}^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
\]
  1. Render the generated Markdown using Streamdown.
  2. Observe how the mathematical expressions are displayed.

Expected Behavior

Streamdown should render mathematical expressions correctly, including those using LaTeX-style delimiters (\(...\) for inline math and \[...\] for block math), without requiring manual conversion to $$ ... $$.

Actual Behavior

  • Mathematical expressions wrapped with \(...\) and \[...\] are rendered as plain text.
  • KaTeX is not invoked for these expressions.
  • Only expressions wrapped with $$ ... $$ are detected and rendered as math.

Code Sample

function normalizeMathDelimiters(input: string): string[] {
  return [
    input
      .replace(/\\\[/g, `$$$`)
      .replace(/\\\]/g, `$$$`)
      .replace(/\\\(/g, `$$$`)
      .replace(/\\\)/g, `$$$`)
  ];
}

Streamdown Version

1.6.10

React Version

19.2.3

Node.js Version

24.12.0

Browser(s)

No response

Operating System

None

Additional Context

See: vercel/ai-chatbot#716

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions