Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Refactor math_symbol_table.py to dynamically determine column number #30105

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

BeiChenStanly
Copy link

Fixed Issue #26143

  • Remove hardcoded column numbers; now columns are auto-calculated based on symbol length and page width constraints. Future changes to symbol lists require no manual column adjustment.

PR summary

This PR refactors math_symbol_table.py so that the symbol tables in the mathtext documentation dynamically determine the number of columns, instead of relying on hardcoded values.

What was changed

  • The column count is now determined automatically for each symbol group according to the content and layout constraints.
  • The minimum number of columns is set to 4, and the maximum is 6.
  • Original sorting and special symbol handling logic is preserved.
  • The directive and extension interface remain unchanged.

@github-actions github-actions bot added the Documentation: build building the docs label May 25, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@BeiChenStanly BeiChenStanly force-pushed the dynamic-math-symbol-table branch 3 times, most recently from 679cb47 to 2420e6a Compare May 25, 2025 05:56
doc/sphinxext/math_symbol_table.py Outdated Show resolved Hide resolved
@BeiChenStanly BeiChenStanly force-pushed the dynamic-math-symbol-table branch 2 times, most recently from b726525 to 8fe5cb2 Compare May 25, 2025 10:39
@BeiChenStanly BeiChenStanly requested a review from rcomer May 25, 2025 11:26
…for symbol tables(Issue matplotlib#26143)

- Remove hardcoded column numbers; now columns are auto-calculated based on symbol length and page width constraints. Future changes to symbol lists require no manual column adjustment.
@BeiChenStanly BeiChenStanly force-pushed the dynamic-math-symbol-table branch from 8fe5cb2 to 76e8873 Compare May 26, 2025 05:05
Copy link
Member

@rcomer rcomer 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 this @BeiChenStanly. I think this is a nice clean solution and the table renders well for me on both laptop and tablet screen. I just have some minor style comments.

doc/sphinxext/math_symbol_table.py Outdated Show resolved Hide resolved
doc/sphinxext/math_symbol_table.py Outdated Show resolved Hide resolved
@rcomer rcomer mentioned this pull request May 26, 2025
@story645
Copy link
Member

story645 commented May 26, 2025

Any chance you can get this working w/ 1-2 columns for cell phones?

Also thank you very much for picking this up!

@timhoffm
Copy link
Member

Can't we defer the column layout to CSS? I'm not an expert in these things, but flexbox with flex-wrap could likely do the job.

@BeiChenStanly BeiChenStanly force-pushed the dynamic-math-symbol-table branch from 5d25f17 to 9ea11da Compare May 26, 2025 15:14
@BeiChenStanly
Copy link
Author

@story645 @timhoffm
Thank you for your feedback!

  • For mobile devices, the symbol table supports horizontal scrolling.
  • Currently, the symbol table is rendered as a styled HTML <table>, and switching to a flexbox-based layout would require changing the output to <div> elements instead of <table>. This could introduce breaking changes across the documentation and affect existing styles
    For now, I've kept the table structure for consistency, but if there's interest in a more flexible layout in the future, we could consider a larger refactor.

Let me know if you have any further suggestions!

@story645
Copy link
Member

This could introduce breaking changes across the documentation and affect existing styles

Why if you only apply the css style to the div class for the math table? We have other custom css classes in https://github.com/matplotlib/matplotlib/blob/main/doc/_static/mpl.css

@rcomer rcomer removed their request for review May 27, 2025 07:33
@rcomer
Copy link
Member

rcomer commented May 27, 2025

Apologies, I did not read the issue carefully enough and missed the bit about checking how it responds to window resizing. I think a few potential contributors also missed that so I took the liberty of editing the issue OP to hopefully make it obvious.

@BeiChenStanly
Copy link
Author

Why if you only apply the css style to the div class for the math table? We have other custom css classes in https://github.com/matplotlib/matplotlib/blob/main/doc/_static/mpl.css

Thank you for your suggestion!

The current table styles are provided by the documentation theme, which ensures consistent look and feel (including things like row highlighting on hover, alternating row colors, and compatibility with theme changes) across all tables—certainly not just the math table. While it’s possible to apply a custom CSS class to a <div>-based structure, that would require us to rewrite all existing <table> elements as <div>s and reimplement all table-related styles and behaviors (such as row hover effects, responsive adjustments, etc.) in custom CSS.

This could lead to duplicated effort, potential inconsistencies, and more maintenance if the theme changes in the future.

In addition, I’d like to confirm the original intent of this issue, just to make sure we’re on the same page.

Is the main goal to:

  • Achieve a fully responsive layout for the symbol table (e.g., adapting the number of columns automatically based on screen size, like showing 1-2 columns on mobile and more on desktop)? or
  • Simply avoid hardcoding the number of columns in the code that generates the table, and instead compute the optimal column count based on content and available width (but still use a fixed table layout)?
    If the intention is to support true responsive layouts (for example, using CSS to adapt the number of columns on different devices), it would be helpful to state this explicitly in the issue description so we can design the solution accordingly.

Thanks again for your feedback!

@story645
Copy link
Member

The goal is more truly responsive layout, w/ avoiding fixed column size being a kinda of iterative step.

One of the ways we get responsive grids in other parts of the docs is by using https://sphinx-design.readthedocs.io/en/latest/grids.html. Is there a way to maybe use that here - have the directive auto generate/populate a sphinx design grid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: build building the docs
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Doc]: dynamically resize the mathtext symbol tables
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.