Skip to content

feat: support bracket LaTeX math delimiters - #4

Open
Yash-Singh1 wants to merge 1 commit into
software-mansion-labs:masterfrom
Yash-Singh1:feat/latex-alternate-delimiters
Open

Yash-Singh1 wants to merge 1 commit into
software-mansion-labs:masterfrom
Yash-Singh1:feat/latex-alternate-delimiters

Conversation

@Yash-Singh1

Copy link
Copy Markdown

What and why

Recognize bracket math delimiters through the existing ENRMRKD_FLAG_LATEXMATHSPANS extension:

  • \(...\) emits the existing inline math span.
  • \[...\] emits the existing display math span.

The parser passes the formula contents verbatim to the existing math callbacks. For example, Answer: \(x_1 + 1\). can render as inline math instead of ordinary parentheses and underscores.

Consumer dependency

software-mansion/enriched-markdown#1043 depends on this parser PR. This needs to merge first; the consumer can then fetch the merged parser through scripts/fetch-md4c.sh and keep its vendored C/H files byte-identical to this fork.

This is submitted to Software Mansion's maintained MD4C fork, which supplies Enriched Markdown's prefixed ENRMRKD_ / enrmrkd_ parser sources. The consumer PR contains the native/web integration, WASM rebuild, documentation and Android/iOS before/after evidence.

Parsing behavior

Bracket math stays within the current Markdown block and preserves block precedence. Doubled backslashes escape delimiters. Unmatched or incomplete delimiters retain ordinary Markdown escape behavior. Failed closer searches are cached per delimiter kind to avoid repeated scans of incomplete input.

This extends the existing math flag. With math enabled, matching escaped parentheses and brackets become math delimiters; with math disabled, ordinary Markdown escaping is unchanged. Existing dollar-delimited math remains supported.

Validation

  • The normal build and existing test runner pass at cdf931f8d2ce4673829eaa69cc2fa90c1bcead09: 1,012 spec examples and 31 pathological cases.
  • All 25 math spec examples pass. Against unchanged fork parser 76c5fb301d4c952e93c8f9a2be8919d6888555ba, 13 feature regressions fail and 12 controls pass.
  • Coverage includes inline/display forms, backslash parity, escaped closers, disabled math, mismatched/unmatched/incomplete input, code spans/fences, dollar coexistence, containers, links and GFM table cells.
  • CMake and the test runner are unchanged. Coverage uses the existing test/spec-latex-math.txt workflow.
  • git diff --check passes.

Generated by GPT-6.1 Sol using the Codex harness.

shivamhwp pushed a commit to shivamhwp/enriched-markdown that referenced this pull request Nov 9, 2026
Copied line for line from software-mansion#1043
(parser change also in software-mansion-labs/md4c#4) for T3's bracket math;
the web WASM bundle is rebuilt in a separate commit.

(cherry picked from commit c37b5d3)
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.

1 participant