Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Parse \limits and \nolimits in mathtext - #32333

Open
ahmed5145 wants to merge 1 commit into
matplotlib:mainfrom
ahmed5145:parse-limits-mathtext
Open

ENH: Parse \limits and \nolimits in mathtext#32333
ahmed5145 wants to merge 1 commit into
matplotlib:mainfrom
ahmed5145:parse-limits-mathtext

Conversation

@ahmed5145

Copy link
Copy Markdown
Contributor

PR summary

Closes #28051.

\limits and \nolimits are TeX commands that control where an operator's sub- and superscripts go: \limits places them directly above and below the operator, \nolimits places them to the side. mathtext didn't parse them at all, so $\int\limits_a^b$ raised ParseFatalException: Unknown symbol: \limits.

mathtext already has the over/under layout machinery: it uses it automatically for symbols like \sum and \prod and for functions like \lim. So the missing piece was really just parsing the commands and letting them steer that existing decision. I added \limits/\nolimits to the subsuper grammar rule and made the parse action honor them: \limits forces over/under placement of the nucleus, \nolimits forces side placement, and otherwise the default (is_overunder) behavior is unchanged. Both commands also parse when no sub/superscript follows (e.g. $\int\limits$), matching TeX's leniency.

Because the over/under path is reused, the visual results line up with the existing defaults: \sum\limits_a^b renders identically to a plain \sum_a^b, and \int\nolimits_a^b renders identically to a plain \int_a^b. I leaned on that for testing: a check_figures_equal test asserts both equalities, so no new baseline images are needed. There's also a parse-only test covering the commands, including the no-subscript case.

AI Disclosure

I used Claude Code to navigate the mathtext parser and locate the subsuper grammar rule and its parse action. I decided on the approach, reuse the existing over/under machinery and let \limits/\nolimits override the placement, and reviewed and directed the edits and tests. My environment can't do a full FreeType build, so instead of running the image-comparison suite I verified behavior by loading the modified parser against an installed matplotlib: I confirmed the issue's example and other cases now parse, that all existing mathtext test expressions still parse (no regression), and that \sum\limits/\int\nolimits render pixel-identically to their plain-operator equivalents (which is what the new check_figures_equal test relies on).

  • Use an expressive title
  • New and changed code is tested: a new check_figures_equal test (test_limits) and a parse test (test_limits_parse). No new baseline images are required because the test compares against the existing default layouts.
  • N/A: no new plotting feature to demonstrate in a gallery example.
  • New feature documented: an entry in the subscripts/superscripts section of the mathtext user guide and a doc/release/next_whats_new/ note.
  • N/A: no other documentation changes needed.

Adds support for the \limits and \nolimits commands, which force the
sub- and superscripts of the preceding operator to be placed above/below
it or to its side, respectively. Previously these commands raised a
ParseFatalException (Unknown symbol).

Closes matplotlib#28051
@github-actions github-actions Bot added topic: text/mathtext Documentation: user guide files in galleries/users_explain or doc/users labels Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: user guide files in galleries/users_explain or doc/users topic: text/mathtext

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Parse "\limits" in mathtext

1 participant