MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / subsuper

Method subsuper

site-packages/matplotlib/mathtext.py:2829–3015  ·  view source on GitHub ↗
(self, s, loc, toks)

Source from the content-addressed store, hash-verified

2827 return False
2828
2829 def subsuper(self, s, loc, toks):
2830 assert len(toks)==1
2831
2832 nucleus = None
2833 sub = None
2834 super = None
2835
2836 # Pick all of the apostrophes out, including first apostrophes that have
2837 # been parsed as characters
2838 napostrophes = 0
2839 new_toks = []
2840 for tok in toks[0]:
2841 if isinstance(tok, str) and tok not in ('^', '_'):
2842 napostrophes += len(tok)
2843 elif isinstance(tok, Char) and tok.c == "'":
2844 napostrophes += 1
2845 else:
2846 new_toks.append(tok)
2847 toks = new_toks
2848
2849 if len(toks) == 0:
2850 assert napostrophes
2851 nucleus = Hbox(0.0)
2852 elif len(toks) == 1:
2853 if not napostrophes:
2854 return toks[0] # .asList()
2855 else:
2856 nucleus = toks[0]
2857 elif len(toks) in (2, 3):
2858 # single subscript or superscript
2859 nucleus = toks[0] if len(toks) == 3 else Hbox(0.0)
2860 op, next = toks[-2:]
2861 if op == '_':
2862 sub = next
2863 else:
2864 super = next
2865 elif len(toks) in (4, 5):
2866 # subscript and superscript
2867 nucleus = toks[0] if len(toks) == 5 else Hbox(0.0)
2868 op1, next1, op2, next2 = toks[-4:]
2869 if op1 == op2:
2870 if op1 == '_':
2871 raise ParseFatalException("Double subscript")
2872 else:
2873 raise ParseFatalException("Double superscript")
2874 if op1 == '_':
2875 sub = next1
2876 super = next2
2877 else:
2878 super = next1
2879 sub = next2
2880 else:
2881 raise ParseFatalException(
2882 "Subscript/superscript sequence is too long. "
2883 "Use braces { } to remove ambiguity.")
2884
2885 state = self.get_state()
2886 rule_thickness = state.font_output.get_underline_thickness(

Callers

nothing calls this directly

Calls 15

get_stateMethod · 0.95
symbolMethod · 0.95
kernMethod · 0.95
hpackMethod · 0.95
is_overunderMethod · 0.95
is_dropsubMethod · 0.95
is_slantedMethod · 0.95
ParseFatalExceptionClass · 0.90
HboxClass · 0.85
HlistClass · 0.85
maxFunction · 0.85
HCenteredClass · 0.85

Tested by

no test coverage detected