Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
DOC: Dynamically resize mathtext symbol tables (#26143)#30682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
0NIKHIL0 wants to merge3 commits intomatplotlib:mainChoose a base branch from0NIKHIL0:dynamic-symbol-table
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
240 changes: 98 additions & 142 deletionsdoc/sphinxext/math_symbol_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,152 +1,108 @@ | ||
| """ | ||
| Sphinx extension that generates the math symbol table documentation | ||
| for Matplotlib. | ||
| """ | ||
| from __future__ import annotations | ||
| from textwrap import dedent | ||
| from docutils.statemachine import StringList | ||
| from docutils import nodes | ||
| from sphinx.util.docutils import SphinxDirective | ||
| from matplotlib import _mathtext | ||
| class MathSymbolTableDirective(SphinxDirective): | ||
| """Generate tables of math symbols grouped by category.""" | ||
| has_content = False | ||
| def run(self): | ||
| # Build RST lines to be parsed. We include a small CSS style and | ||
| # simple HTML wrappers so the result is responsive in the browser. | ||
| lines: list[str] = [] | ||
| # Add responsive CSS styling | ||
| style = dedent( | ||
| "\n".join( | ||
| [ | ||
| "", | ||
| "", | ||
| ".mpl-symbol-grid {", | ||
| " display: grid;", | ||
| " grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));", | ||
| " gap: 8px;", | ||
| " margin: 16px 0;", | ||
| "}", | ||
| ".mpl-symbol-cell {", | ||
| " display: flex;", | ||
| " flex-direction: column;", | ||
| " align-items: center;", | ||
| " padding: 8px;", | ||
| " border: 1px solid #ddd;", | ||
| " border-radius: 4px;", | ||
| "}", | ||
| ".mpl-symbol-cell .math {", | ||
| " font-size: 1.2em;", | ||
| " margin-bottom: 4px;", | ||
| "}", | ||
| ".mpl-symbol-cell .label {", | ||
| " font-family: monospace;", | ||
| " font-size: 0.9em;", | ||
| " color: #666;", | ||
| "}", | ||
| "", | ||
| "", | ||
| ] | ||
| ) | ||
| ) | ||
| # Insert the style as raw HTML block | ||
| lines.append(".. raw:: html") | ||
| lines.append("") | ||
| for style_line in style.splitlines(): | ||
| lines.append(" " + style_line) | ||
| lines.append("") | ||
| # Get symbol categories from matplotlib mathtext internals | ||
| try: | ||
| categories = _mathtext._get_sphinx_symbol_table() | ||
| except Exception: | ||
| categories = [] | ||
| for category, _, syms in categories: | ||
| # Ensure consistent ordering for reproducible output | ||
| syms_list = sorted(list(syms), key=lambda s: str(s)) | ||
| lines.append(f"**{category}**") | ||
| lines.append("") | ||
| lines.append(".. raw:: html") | ||
| lines.append("") | ||
| lines.append(' <div class="mpl-symbol-grid" node="_65">') | ||
| lines.append(' ') | ||
| for sym in syms_list: | ||
| s = str(sym) | ||
| # Use raw TeX inside \( ... \) so MathJax (Sphinx) renders it | ||
| tex = s | ||
| html_line = ( | ||
| ' <div class="mpl-symbol-cell" node="_74">' | ||
| f'<span class="math" node="_76">\\({tex}\\)</span>' | ||
| f'<span class="label" node="_78">`{s}`</span>' | ||
| "</div>" | ||
| ) | ||
| lines.append(html_line) | ||
| lines.append(" </div>") | ||
| lines.append(" ") | ||
| lines.append("") | ||
| # Let Sphinx parse the lines so roles and references work | ||
| text = "\n".join(lines) | ||
| node = nodes.paragraph() | ||
| self.state.nested_parse(StringList(text.splitlines()), 0, node) | ||
| return [node] | ||
| def setup(app): | ||
| """Register the Sphinx directive.""" | ||
| app.add_directive("math_symbol_table", MathSymbolTableDirective) | ||
| return {"parallel_read_safe": True, "parallel_write_safe": True} |
67 changes: 67 additions & 0 deletionslib/matplotlib/_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.