Skip to content

fix(desktop): convert \slashed to \not for KaTeX compatibility#3750

Merged
esengine merged 2 commits into
esengine:main-v2from
lightfront:fix/slashed-katex-compat
Jun 10, 2026
Merged

fix(desktop): convert \slashed to \not for KaTeX compatibility#3750
esengine merged 2 commits into
esengine:main-v2from
lightfront:fix/slashed-katex-compat

Conversation

@lightfront

Copy link
Copy Markdown
Contributor

Convert \slashed to \not for KaTeX compatibility

Problem

KaTeX doesn't support the \slashed command from the LaTeX 'slashed' package, which is commonly used in physics for Feynman slash notation (\slashed{p}, \slashed{\partial}).

When the model emits these commands, Reasonix shows raw LaTeX source as red error text instead of rendering the formula.

Solution

Convert \slashed{X} to \not{X} in latexNormalizeForKatex. The \not command provides a similar visual effect (a slash through the character) and is supported by KaTeX.

Example:

  • Input: $\slashed{p}$
  • After normalization: $\not{p}$
  • Rendered: p with a slash through it (Feynman slash notation)

Changes

  • desktop/frontend/src/components/latexNormalize.ts: Added regex conversion
  • desktop/frontend/src/__tests__/math-golden.test.ts: Added 3 test cases

Tests

  • 3 new test cases for \slashed conversion
  • All tests pass (88 math-golden + 8 text-size + 6 provider-model-refresh = 102 total)

Related

KaTeX doesn't support the \\slashed command from the LaTeX 'slashed'
package, which is commonly used in physics for Feynman slash notation
(\\slashed{p}, \\slashed{\\partial}).

Convert \\slashed{X} to \\not{X} before passing to KaTeX. The \\not
command provides a similar visual effect (a slash through the character)
and is supported by KaTeX.

This prevents KaTeX parse errors when the model emits physics notation
using \\slashed.

Tests: 3 new cases added, 111/111 passing
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 10, 2026
…psilon(0)

The previous fix only handled \\\\slashed{X} (braced form). User-reported
issue: \\\\slashed\\\\epsilon(0) (Greek letter + function call, no braces)
was not being converted and still showed as red KaTeX error.

Extended the regex to handle two additional forms:
- \\\\slashed X       → \\\\not X       (single letter, no braces)
- \\\\slashed\\\\epsilon      → \\\\not{\\\\epsilon}    (backslash command)
- \\\\slashed\\\\epsilon(0)   → \\\\not{\\\\epsilon(0)}  (backslash command + function)
- \\\\slashed a       → \\\\not a       (single ASCII letter)

This covers the common physics notation \\\\slashed{p} where the model
sometimes forgets the braces around the argument.

Tests: 2 new cases added, 113/113 math-golden passing.
@lightfront lightfront force-pushed the fix/slashed-katex-compat branch from 795aa40 to 524b633 Compare June 10, 2026 02:43

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @lightfront — clean, well-scoped fix.

\slashed is a real gap (KaTeX ships no slashed package), and routing it to \not is the right approximation for Feynman slash notation. Since it runs inside latexNormalizeForKatex, the rewrite only touches recognized math spans — code blocks and prose are untouched — and the golden tests cover both the braced and unbraced forms. CI is green across the board.

One tiny thing I'll tidy in a follow-up (not blocking): a couple of the braced test inputs use a double backslash (\slashed{p}) where real model output is a single one (\slashed{p}); the regex handles both, so the tests pass either way. Merging now — appreciate the contribution!

@esengine esengine merged commit a6de668 into esengine:main-v2 Jun 10, 2026
13 checks passed
esengine added a commit that referenced this pull request Jun 10, 2026
#3761)

The \slashed -> \not cases (#3750) wrote their braced inputs with a
double backslash (\slashed{p}); real model output is a single one. The
regex matched either way so the tests passed, but they exercised a form
the model never emits. Switch them to single-backslash inputs and the
eq() helper the surrounding golden tests already use.

Co-authored-by: reasonix <reasonix@deepseek.com>
@lightfront lightfront deleted the fix/slashed-katex-compat branch June 10, 2026 07:32
SuMuxi66 pushed a commit to SuMuxi66/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…ine#3750)

* fix(desktop): convert \\slashed to \\not for KaTeX compatibility

KaTeX doesn't support the \\slashed command from the LaTeX 'slashed'
package, which is commonly used in physics for Feynman slash notation
(\\slashed{p}, \\slashed{\\partial}).

Convert \\slashed{X} to \\not{X} before passing to KaTeX. The \\not
command provides a similar visual effect (a slash through the character)
and is supported by KaTeX.

This prevents KaTeX parse errors when the model emits physics notation
using \\slashed.

Tests: 3 new cases added, 111/111 passing

* fix(desktop): handle unbraced \\\\slashed forms like \\\\slashed\\\\epsilon(0)

The previous fix only handled \\\\slashed{X} (braced form). User-reported
issue: \\\\slashed\\\\epsilon(0) (Greek letter + function call, no braces)
was not being converted and still showed as red KaTeX error.

Extended the regex to handle two additional forms:
- \\\\slashed X       → \\\\not X       (single letter, no braces)
- \\\\slashed\\\\epsilon      → \\\\not{\\\\epsilon}    (backslash command)
- \\\\slashed\\\\epsilon(0)   → \\\\not{\\\\epsilon(0)}  (backslash command + function)
- \\\\slashed a       → \\\\not a       (single ASCII letter)

This covers the common physics notation \\\\slashed{p} where the model
sometimes forgets the braces around the argument.

Tests: 2 new cases added, 113/113 math-golden passing.

---------

Co-authored-by: Xingbo Zhao <xbzhao@impcas.ac.cn>
SuMuxi66 pushed a commit to SuMuxi66/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
esengine#3761)

The \slashed -> \not cases (esengine#3750) wrote their braced inputs with a
double backslash (\slashed{p}); real model output is a single one. The
regex matched either way so the tests passed, but they exercised a form
the model never emits. Switch them to single-backslash inputs and the
eq() helper the surrounding golden tests already use.

Co-authored-by: reasonix <reasonix@deepseek.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants