Skip to content

Normalize math rendering in docs panel and LSP tooltips#8315

Merged
mscolnick merged 3 commits intomarimo-team:mainfrom
LiquidGunay:fix/math-rendering-docs-tooltips
Feb 23, 2026
Merged

Normalize math rendering in docs panel and LSP tooltips#8315
mscolnick merged 3 commits intomarimo-team:mainfrom
LiquidGunay:fix/math-rendering-docs-tooltips

Conversation

@LiquidGunay
Copy link
Contributor

@LiquidGunay LiquidGunay commented Feb 14, 2026

📝 Summary

This PR fixes math rendering consistency for documentation shown in both the docs explorer and LSP tooltips by normalizing additional math syntaxes in the backend markdown path and frontend LSP docs path.

🔍 Description of Changes

  • Extended backend markdown preprocessing in DisplayMathPreprocessor to normalize:
    • .. math::
    • :math:...``
    • :math:...
    • (...)
    • [...]

while preserving existing $$...$$ spacing behavior.

  • Kept backend docstring conversion path thin in completion flow so math docs reliably go through markdown rendering.

  • Added frontend LSP normalization utility and applied it to:

    • hover
    • completion item docs
    • completion resolve docs
    • signature help docs
  • Preserved fenced code and inline code literals (no unwanted math conversion inside code examples).

  • Added concise comments for regex patterns to clarify exactly what each pattern matches.

Tests

  • Python:
    • test_md.py
    • test_complete.py
  • Frontend:
    • normalize-markdown-math.test.ts
    • notebook-lsp.test.ts

Screenshot

math-rendering-after math-rendering-after_1

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.

@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 21, 2026 3:57pm

Request Review

@github-actions
Copy link

github-actions bot commented Feb 14, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@LiquidGunay
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. It looks great, but does feel like a lot of code. I think breaking out into marimo/_utils/normalize_math.py might be better for the backed.

It's also not immediately obvious how the extraction works. Top level comments on the regex and maybe some doc strings on the more complex functions could go a long way!

# We also add '/' for file path completion.
COMPLETION_TRIGGER_CHARACTERS = frozenset({".", "(", ",", "/"})

_MATH_ROLE_PATTERN = re.compile(r"(?<!`):math:`([^`\n]+)`")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a lot of code. I wonder if it could go somewhere else? Can you give examples of the patterns you are trying to match as well?

@dmadisetti dmadisetti added the enhancement New feature or request label Feb 17, 2026
@manzt manzt removed their request for review February 18, 2026 20:26
@LiquidGunay
Copy link
Contributor Author

Sorry for the late reply, should I abort this in lieu of #8348 ?

@github-actions github-actions bot added documentation Improvements or additions to documentation bash-focus Area to focus on during release bug bash labels Feb 21, 2026
@LiquidGunay LiquidGunay marked this pull request as draft February 21, 2026 15:05
@LiquidGunay
Copy link
Contributor Author

@dmadisetti even with #8348 I was getting issues with the math rendering in optax documentation. I have extended display_math.py to handle more formats that were failing before. I have also added normalize-markdown-math.ts so that this math is also rendered in tooltips/ other docs. Examples corresponding to each regex pattern have also been added.

@LiquidGunay LiquidGunay marked this pull request as ready for review February 21, 2026 15:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR normalizes math rendering in documentation displayed in both the docs explorer and LSP tooltips by extending the backend markdown preprocessing and adding frontend LSP normalization utilities to handle multiple math syntax variants commonly used in Python docstrings.

Changes:

  • Extended backend DisplayMathPreprocessor to normalize RST math directives (:math:, .. math::), LaTeX delimiters (\(...\), \[...\]), and HTML code-tag variants while preserving fenced code blocks and inline code literals
  • Added frontend normalize-markdown-math.ts utility with similar normalization logic applied to LSP documentation responses (hover, completion, signature help)
  • Modified docstring conversion flow in complete.py to prefer markdown rendering when math syntax is detected, ensuring consistent TeX pipeline usage

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
marimo/_output/md_extensions/display_math.py Extended DisplayMathPreprocessor with methods to normalize RST math directives, LaTeX delimiters, and handle inline code/fenced blocks; fixes escape sequence in test expectations
marimo/_runtime/complete.py Added math syntax detection, error handling for docstring_to_markdown.UnknownFormatError, and math-aware fallback path in docstring conversion
tests/_output/test_md.py Added tests for RST math directive normalization, math role/delimiter conversion, fenced code preservation; fixed escape sequences in LaTeX macro tests
tests/_runtime/test_complete.py Added comprehensive tests for math directive normalization in docstrings, including edge cases like unindented blocks, fenced code, and class init handling
frontend/src/core/codemirror/lsp/normalize-markdown-math.ts New utility implementing math syntax normalization for LSP documentation with fenced/inline code preservation
frontend/src/core/codemirror/lsp/notebook-lsp.ts Integrated math normalization into hover, completion, completionItemResolve, and signatureHelp responses
frontend/src/core/codemirror/lsp/tests/normalize-markdown-math.test.ts Tests for frontend math normalization covering RST directives, LaTeX delimiters, code block preservation
frontend/src/core/codemirror/lsp/tests/notebook-lsp.test.ts Integration tests verifying math normalization across all LSP response types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mscolnick mscolnick merged commit 9a24902 into marimo-team:main Feb 23, 2026
37 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants