feat: add setting to disable inline math ($...$) parsing by briannnelson · Pull Request #4231 · marktext/marktext · GitHub
Skip to content

feat: add setting to disable inline math ($...$) parsing - #4231

Closed
briannnelson wants to merge 1 commit into
marktext:developfrom
briannnelson:feat/disable-inline-math-setting
Closed

briannnelson wants to merge 1 commit into
marktext:developfrom
briannnelson:feat/disable-inline-math-setting

Conversation

@briannnelson

@briannnelson briannnelson commented May 16, 2026 •

Copy link
Copy Markdown

Closes #2002

Summary

  • Adds an opt-in Inline math ($...$) toggle in Preferences → Markdown → Extensions (default: on, preserving current behavior)
  • When disabled, $...$ is treated as literal text — dollar signs in prose like $5 and $10 no longer trigger broken LaTeX rendering
  • Block math ($$...$$) is unaffected regardless of the setting

Problem

Users writing documents with currency or other dollar signs frequently get unexpected KaTeX render errors because $5 and $10 is parsed as inline math syntax. There was no way to opt out of inline math without also losing block math.

Implementation

Parser layer (src/muya/lib/):

  • Introduces a new inlineMath option (default true) separate from the existing math flag (which gates block math)
  • Gates the inline_math token in the WYSIWYG tokenizer (parser/index.js) via inlineMath !== false
  • Gates inline math in the marked InlineLexer (parser/marked/inlineLexer.js) — used for export and copy/paste — with the same guard for backward compat with old configs that lack the key
  • Block math (multiplemath) in the block lexer is unchanged

Preferences system:

  • src/renderer/src/store/preferences.js — Pinia state default inlineMath: true
  • static/preference.json — static default
  • src/main/preferences/schema.json — JSON schema entry

Editor wiring (src/renderer/src/components/editorWithTabs/editor.vue):

  • Extracted in storeToRefs, passed in onMounted options, and watched with needRender: true so toggling re-renders all blocks immediately (no restart needed)

Settings UI (src/renderer/src/prefComponents/markdown/index.vue):

  • New <bool> toggle in the Extensions compound, after Footnote

i18n: Added "inlineMath" keys to all 9 supported locale files (English placeholder for non-English locales — translations welcome).

Test plan

  • Default behavior unchanged: $E = mc^2$ renders as KaTeX inline math
  • With setting OFF: $E = mc^2$ renders as literal $E = mc^2$; $5 and $10 renders as plain text
  • Block math unaffected: $$E = mc^2$$ renders as KaTeX block regardless of setting
  • Toggle re-renders immediately without app restart
  • Setting persists across sessions
  • pnpm run test:unit passes

🤖 Generated with Claude Code

Adds an opt-in preference `inlineMath` (default: true) that lets users
turn off inline math parsing so dollar signs in regular prose (e.g.
"$5 and $10") render as literal characters instead of broken LaTeX.
Block math ($$...$$) is unaffected.

- Split the shared `math` parser flag into `math` (block) + `inlineMath`
  (inline), with `inlineMath !== false` guard for backward compat
- Gate `inline_math` token in the WYSIWYG tokenizer (parser/index.js)
- Gate inline math in the marked InlineLexer (export/copy path)
- Wire the new preference through Pinia store, schema, static defaults,
  editor.vue (storeToRefs + watch + onMounted options), and the
  Markdown preferences UI (Extensions section)
- Add i18n strings to all 9 supported locales

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@Jocs

Jocs commented May 16, 2026

Copy link
Copy Markdown
Member

@briannnelson

Copy link
Copy Markdown
Author

Why is it necessary to disable inline math? You can just escape it directly using \.

@Jocs $ is a workaround that pollutes the source file, doesn't survive copy/paste, and requires the user to think about math syntax in documents that have no math. The setting removes the friction at its root.

@Jocs

Jocs commented May 18, 2026 •

Copy link
Copy Markdown
Member

If inline math can be controlled via settings, shouldn't block math also be? My thinking is that math is not supported by GFM and CommonMark Spec, so it should be configurable. Should block math and inline math use a single configuration item, or be configured separately?

@Jocs

Jocs commented May 21, 2026

Copy link
Copy Markdown
Member

@claude review this PR

@claude

claude Bot commented May 21, 2026 •

Copy link
Copy Markdown

@Jocs Jocs closed this Jun 15, 2026
@Frutus Frutus mentioned this pull request Jul 25, 2026
8 of 11 tasks
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Aug 13, 2026
Port of upstream PR marktext#5004 (follow-up to marktext#4231, related to marktext#2002).

Adds a default-on 'Inline math' preference under Preferences ->
Markdown -> Extensions. When disabled, single-dollar expressions stay
literal text — currency-heavy prose like $13B is no longer swallowed
into KaTeX — while double-dollar display math keeps rendering. The
option threads through every parse/render entry point: live editing,
markdown import, clipboard HTML, TOC text, and static HTML/export.

Deviations from the upstream PR: the schema.json hunk is re-applied on
top of this fork's separator fixes (e197fb8), and the ja / zh-CN /
zh-TW locale strings are translated instead of the English
placeholders.

Round-trip serialization (marktext#4934 concern) verified: muya spec suites
including roundTrip.spec pass, and the PR's own test pins
getMarkdown() identity with inlineMath disabled.
Jocs added a commit that referenced this pull request Sep 19, 2026
…5446) (#5450)

`math` was a half-finished master switch: it gated only the marked path
(import, HTML export, clipboard), the live editor ignored it entirely,
and MarkText never set it — no schema entry, no UI, no setOptions call.
So the option that was supposed to control dollar math could not turn it
off, and where it did apply it made the editor disagree with its export.

It is now `texMathDollars`, named after the pandoc extension it
implements, with the live-editor gate it never had and a preference
under Preferences → Markdown → Extensions beside the other pandoc-named
toggles. Default on, as in pandoc's own `markdown` dialect.

It covers `$…$` and `$$…$$` together, because that is the granularity
pandoc gives the extension — the question #4231 stalled on, answered by
adopting an existing definition rather than inventing one. This is also
the switch #2002, #4231 and #5243 asked for, the last of them patching
app.asar to get it.

With the option off the syntax is neither read nor offered: the inline
and begin rules skip it, `$$` + Enter stays a paragraph, and the menus
that list blocks — quick insert, the front menu's Turn Into, and the
desktop Paragraph menu — drop Math Block. `canInsertLabel` is the single
rule behind that, consulted by those menus and by the builder every
insertion path funnels through, so the ⌥⌘M shortcut cannot slip past a
list it never reads.

Task 2 of #5446.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Wangqkoe pushed a commit to Wangqkoe/marktext that referenced this pull request Oct 21, 2026
…arktext#5446) (marktext#5450)

`math` was a half-finished master switch: it gated only the marked path
(import, HTML export, clipboard), the live editor ignored it entirely,
and MarkText never set it — no schema entry, no UI, no setOptions call.
So the option that was supposed to control dollar math could not turn it
off, and where it did apply it made the editor disagree with its export.

It is now `texMathDollars`, named after the pandoc extension it
implements, with the live-editor gate it never had and a preference
under Preferences → Markdown → Extensions beside the other pandoc-named
toggles. Default on, as in pandoc's own `markdown` dialect.

It covers `$…$` and `$$…$$` together, because that is the granularity
pandoc gives the extension — the question marktext#4231 stalled on, answered by
adopting an existing definition rather than inventing one. This is also
the switch marktext#2002, marktext#4231 and marktext#5243 asked for, the last of them patching
app.asar to get it.

With the option off the syntax is neither read nor offered: the inline
and begin rules skip it, `$$` + Enter stays a paragraph, and the menus
that list blocks — quick insert, the front menu's Turn Into, and the
desktop Paragraph menu — drop Math Block. `canInsertLabel` is the single
rule behind that, consulted by those menus and by the builder every
insertion path funnels through, so the ⌥⌘M shortcut cannot slip past a
list it never reads.

Task 2 of marktext#5446.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3e9e91c)
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.

Allow disable inline math format ($)

2 participants