@@ -366,35 +366,44 @@ def _break_up_by_substrings(self) -> Self:
366366 # Handle consecutive scripts as a group, matching by Y-position
367367 script_group , j = self ._group_consecutive_scripts (i )
368368 total_script_submobs = self ._total_submobs_for_scripts (script_group )
369- script_pool = self .submobjects [curr_index :curr_index + total_script_submobs ]
369+ script_pool = self .submobjects [
370+ curr_index : curr_index + total_script_submobs
371+ ]
370372
371373 self ._assign_script_group (script_group , script_pool , new_submobjects )
372374
373375 curr_index += total_script_submobs
374376 i = j
375377 else :
376378 # Base element processing: check if followed by scripts
377- next_is_script = (i + 1 < len (self .tex_strings ) and
378- self .tex_strings [i + 1 ].strip ().startswith (("^" , "_" )))
379+ next_is_script = i + 1 < len (self .tex_strings ) and self .tex_strings [
380+ i + 1
381+ ].strip ().startswith (("^" , "_" ))
379382
380383 if next_is_script and num_submobs > 0 :
381384 script_group , j = self ._group_consecutive_scripts (i + 1 )
382385 total_script_submobs = self ._total_submobs_for_scripts (script_group )
383386 total_needed = num_submobs + total_script_submobs
384387
385- all_submobs = self .submobjects [curr_index :curr_index + total_needed ]
388+ all_submobs = self .submobjects [
389+ curr_index : curr_index + total_needed
390+ ]
386391
387392 # Only use special handling if scripts have content (non-empty)
388393 if total_script_submobs > 0 and len (all_submobs ) == total_needed :
389394 # LaTeX may render base+scripts in unexpected order
390395 # Find base by Y-position: closest to baseline (Y=0)
391- base_submob = min (all_submobs , key = lambda m : abs (m .get_center ()[1 ]))
396+ base_submob = min (
397+ all_submobs , key = lambda m : abs (m .get_center ()[1 ])
398+ )
392399 sub_tex_mob .submobjects = [base_submob ]
393400
394401 script_pool = [m for m in all_submobs if m != base_submob ]
395402 new_submobjects .append (sub_tex_mob )
396403
397- self ._assign_script_group (script_group , script_pool , new_submobjects )
404+ self ._assign_script_group (
405+ script_group , script_pool , new_submobjects
406+ )
398407
399408 curr_index += total_needed
400409 i = j
@@ -421,7 +430,9 @@ def _group_consecutive_scripts(self, start_index: int) -> tuple[list[str], int]:
421430 """
422431 script_group = [self .tex_strings [start_index ]]
423432 j = start_index + 1
424- while j < len (self .tex_strings ) and self .tex_strings [j ].strip ().startswith (("^" , "_" )):
433+ while j < len (self .tex_strings ) and self .tex_strings [j ].strip ().startswith (
434+ ("^" , "_" )
435+ ):
425436 script_group .append (self .tex_strings [j ])
426437 j += 1
427438 return script_group , j
@@ -435,12 +446,19 @@ def _total_submobs_for_scripts(self, script_group: list[str]) -> int:
435446 for s in script_group :
436447 total += len (
437448 SingleStringMathTex (
438- s , tex_environment = self .tex_environment , tex_template = self .tex_template
449+ s ,
450+ tex_environment = self .tex_environment ,
451+ tex_template = self .tex_template ,
439452 ).submobjects
440453 )
441454 return total
442455
443- def _assign_script_group (self , script_group : list [str ], script_pool : list [VMobject ], new_submobjects : list [VMobject ]) -> None :
456+ def _assign_script_group (
457+ self ,
458+ script_group : list [str ],
459+ script_pool : list [VMobject ],
460+ new_submobjects : list [VMobject ],
461+ ) -> None :
444462 """Assign submobjects from ``script_pool`` to scripts in ``script_group``.
445463
446464 Selection strategy:
@@ -451,14 +469,20 @@ def _assign_script_group(self, script_group: list[str], script_pool: list[VMobje
451469 """
452470 for script_tex in script_group :
453471 script_mob = SingleStringMathTex (
454- script_tex , tex_environment = self .tex_environment , tex_template = self .tex_template
472+ script_tex ,
473+ tex_environment = self .tex_environment ,
474+ tex_template = self .tex_template ,
455475 )
456476 script_num_submobs = len (script_mob .submobjects )
457477
458478 if script_num_submobs > 0 and len (script_pool ) > 0 :
459479 is_superscript = script_tex .strip ().startswith ("^" )
460480 # Sort by Y-position: reverse=True for superscripts (highest first)
461- sorted_pool = sorted (script_pool , key = lambda mob : mob .get_center ()[1 ], reverse = is_superscript )
481+ sorted_pool = sorted (
482+ script_pool ,
483+ key = lambda mob : mob .get_center ()[1 ],
484+ reverse = is_superscript ,
485+ )
462486
463487 selected = sorted_pool [:script_num_submobs ]
464488 script_mob .submobjects = selected
0 commit comments