Skip to content

[Feature Request] Native LaTeX/MathJax rendering for chat messages #2501

Description

@dungphan0038

Description

Currently, OpenWork's chat interface renders LaTeX math expressions (wrapped in $$...$$ or $...$) as plain monospace text instead of typeset mathematical notation. This makes it difficult for users to discuss mathematical content — formulas, equations, integrals, matrices — within sessions.

Expected Behavior

When a user writes LaTeX math expressions in a chat message, they should be rendered as formatted mathematical notation, similar to how GitHub renders math in Markdown (via MathJax or KaTeX).

For example:

  • $$\int_0^\infty e^{-x^2} \, dx = \frac{\sqrt{\pi}}{2}$$ should render as a display equation
  • $E = mc^2$ should render as inline math

Actual Behavior

LaTeX expressions appear as plain text like $$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$ without any rendering.

Workaround (DevTools Snippet)

I created a JavaScript snippet that can be run from DevTools (Sources > Snippets) to inject MathJax 3 into the page. It works reasonably well for most formulas but has limitations (detailed below).

How to use the workaround:

  1. Open DevTools: Ctrl+Shift+I / Cmd+Option+I
  2. Sources tab → Snippets → New snippet
  3. Paste the code from openwork-mathjax-inject.js → Save → Run

Console output when running:

[MathJax] Loading from CDN...
[MathJax] Ready!
[MathJax] Injected successfully!
[MathJax] Watching for new messages...

Features of the workaround:

  • Renders $$...$$ as display math, left-aligned
  • Renders $...$ as inline math
  • MutationObserver with debounce (500ms) to auto-render new messages
  • Exposes window.renderMath() for manual re-rendering in Console
  • CSS overrides to prevent line breaks and ensure proper alignment
  • Fallback CDN (cdnjs.cloudflare.com) if primary CDN is unreachable

Workaround code: (see attached file openwork-mathjax-inject.js)

Known Limitations of the Workaround

Despite solving basic math rendering, the following LaTeX environments fail to render multi-line content — everything collapses into a single line:

  • \begin{cases} ... \\ ... \end{cases} — system of equations
  • \begin{vmatrix} ... \\ ... \end{vmatrix} — matrix determinant
  • \begin{bmatrix} ... \\ ... \end{bmatrix} — bracketed matrix
  • \begin{pmatrix} ... \\ ... \end{pmatrix} — parenthesized matrix

The \\ line-break operator within these environments is not being processed correctly. The \begin{aligned} environment with & alignment markers works, but true matrix/cases environments do not render properly.

I suspect this is because MathJax is injected into a React-rendered DOM where text nodes are split across multiple elements, or the \\ syntax is being mangled during the $$ → \[ preprocessing step.

Suggested Solution

It would be great if OpenWork could add native MathJax or KaTeX support to the chat message renderer. This would:

  1. Eliminate the need for DevTools workarounds
  2. Render all LaTeX environments correctly (matrices, cases, aligned, etc.)
  3. Provide a seamless experience for users discussing mathematics in their sessions

A good reference implementation would be Obsidian's MathJax support or GitHub's native math rendering.

Attachments

  • openwork-mathjax-inject.js — The workaround DevTools Snippet for MathJax injection

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions