Skip to content

Keep the whitespace before \\(...\\) math - #908

Merged
mishig25 merged 2 commits into
mainfrom
claude/upbeat-herschel-5ea849
Nov 8, 2026
Merged

mishig25 merged 2 commits into
mainfrom
claude/upbeat-herschel-5ea849

Conversation

@mishig25

@mishig25 mishig25 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Problem

markKatex in kit/preprocessors/mdsvex/index.js matched inline math written as \\(...\\) together with the whitespace before it, and replaced both with the bare KaTeX marker. The space disappeared from the rendered page:

  • "the paper's :math:g parameter" rendered as "paper'sg parameter". rst-style :math: is converted to \\(...\\) by convert_rst_to_mdx.py, so this affects docstrings as well as page bodies.
  • A newline before \\(...\\) was dropped too. Math at the start of the line after a heading was merged into the heading's text.

The $...$ replacement in the same function already keeps its surrounding whitespace.

Fix

  • markKatex captures the whitespace before \\( and returns it in front of the marker, so a space stays a space and a newline stays a newline.
  • check_links.py mirrors these placeholders to predict heading anchors, so _mark_katex_placeholders keeps the same whitespace. Otherwise its anchors would no longer match the renderer's. For example, ## Loss \\(L\\) function now gets loss-katexparse0marker-function from both. Before, both gave losskatexparse0marker-function.

Tests

  • index.test.js: a space and a newline before \\(...\\) are kept.
  • test_check_links.py: heading anchors with \\(...\\) math, and a \\(...\\) line under a heading no longer joining that heading.
  • Both fail without the fix.
  • Golden snapshot: page.html changes only in legacy_function, where "and \(x + y\)" gets its space back. The formatter writes that space as a line break before the <span>. page.mdx is unchanged.

cd kit && npm test (15/15) and pytest tests/test_docstring_snapshots.py tests/test_check_links.py (49) pass.

Interaction with #905

#905 adds a mix_embeddings sample to tests/data/docstring_snapshots/. That sample has :math: after a space in parameter descriptions, e.g. "timestep :math:t" and "the paper's :math:g parameter". Once both PRs are on main, those spans get their space back too. Whichever of the two PRs merges second must regenerate page.html:

UPDATE_SNAPSHOTS=1 python -m pytest tests/test_docstring_snapshots.py
cd kit && UPDATE_SNAPSHOTS=1 npm test

The two PRs edit different functions in kit/preprocessors/mdsvex/index.js: markKatex here, renderKatex in #905.

🤖 Generated with Claude Code

mishig25 and others added 2 commits November 5, 2026 10:23
markKatex consumed the whitespace before inline math written as
`\\(...\\)` and replaced it with the bare marker, so "the paper's
:math:`g` parameter" rendered as "paper'sg parameter" (rst `:math:` is
converted to `\\(...\\)`). Return the captured whitespace before the
marker, as the `$...$` replacement already does; a newline stays a
newline, so math at the start of the line after a heading no longer
joins the heading.

check_links mirrors these placeholders to predict heading anchors, so
it keeps the whitespace too: "## Loss \\(L\\) function" is now
`loss-katexparse0marker-function`, matching the renderer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l-5ea849

# Conflicts:
#	kit/preprocessors/mdsvex/index.test.js
@mishig25
mishig25 merged commit f464098 into main Nov 8, 2026
5 checks passed
@mishig25
mishig25 deleted the claude/upbeat-herschel-5ea849 branch November 8, 2026 18:42
mishig25 added a commit that referenced this pull request Nov 9, 2026
Keeps the tests of both sides, and the snapshot now has the space before `:math:` that #908 keeps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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