-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix #3548: Match MathTex subscripts/superscripts by position #4457
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
base: main
Are you sure you want to change the base?
Fix #3548: Match MathTex subscripts/superscripts by position #4457
Conversation
…ition Use geometric matching for script elements to handle LaTeX reordering while preserving sequential matching for non-script elements.
for more information, see https://pre-commit.ci
|
Thanks for the PR. I have tried to run your new test without the suggested changes to the Similarly I have tested the full PR on the two scenes ( |
|
@henrikmidtiby Thanks for pointing that out. I had initially overlooked the fix, and since the test passed, I missed verifying whether the original issue was actually resolved. I’ve now updated the test and revised my approach. The test correctly fails on the main branch now. |
for more information, see https://pre-commit.ci
|
Good progress. I have tried to apply the current PR to the following test case (from #3548) Which renders as shown here.
Which is more consistent than if I render the scene using the current main branch, that produces this output.
I still think that the coloring is off in both cases, as I would expect the summation signs to be blue. In addition I wonder if it is possible to extract some of the functionality into a separate method. The intention here is to make it easier to understand what the code is actually doing. |
@henrikmidtiby does it look correct now?
|
|
@Nikhil172913832 Much better! |
…_break_up_by_substrings function to improve understandability
for more information, see https://pre-commit.ci
|
@henrikmidtiby I’ve made the necessary changes related to the colors. Please let me know if everything looks good. |






Overview: What does this pull request change?
Fixes issue where
MathTexsubmobjects did not correctly correspond to theirtex_stringswhen using subscripts and superscripts in different orders. The fix uses geometric position matching specifically for script elements (^,_) to handle LaTeX's reordering while preserving sequential matching for non-script elements.Motivation and Explanation: Why and how do your changes improve the library?
Problem: LaTeX compiles expressions like
A ^n _1andA _1 ^nto identical SVG output where subscripts and superscripts may appear in a different order than specified. This causedMathTex('A', '^n', '_1')andMathTex('A', '_1', '^n')to have submobjects that didn't match their originaltex_strings, breaking operations likeget_parts_by_tex()andset_color_by_tex().Solution: Modified
_break_up_by_substrings()method to detect script elements (tex strings starting with^or_) and match them to rendered submobjects based on geometric position (center point). Non-script elements continue using sequential matching to maintain backward compatibility and avoid issues with complex formulas.Impact: Users can now reliably access and manipulate subscripts/superscripts by their tex strings regardless of the order they're specified.
Links to added or changed documentation pages
No documentation changes required.
Further Information and Comments
MathTexmay not correspond to their tex strings #3548test_texmobject.py)test_tex_strings_with_subscripts_and_superscripts()Reviewer Checklist