@@ -83,6 +83,15 @@ def code_by_symbol(sym):
83
83
return u'U%08X' % u
84
84
return None
85
85
86
+ def is_script (s ):
87
+ """
88
+ Subscript _... or superscript ^...
89
+ """
90
+ return s .startswith ('_' ) or s .startswith ('^' )
91
+
92
+ def get_script (s ):
93
+ return (s [0 ], list (s [1 :]))
94
+
86
95
def can_convert (view ):
87
96
"""
88
97
Determines if there are any regions, where symbol can be converted
@@ -98,6 +107,10 @@ def can_convert(view):
98
107
rep = symbol_by_name (p [0 ])
99
108
if rep :
100
109
return True
110
+ if get_settings ().get ('convert_sub_super' , True ) and is_script (p [0 ]):
111
+ (script_char , chars ) = get_script (p [0 ])
112
+ if all ([symbol_by_name (script_char + ch ) for ch in chars ]):
113
+ return True
101
114
if get_settings ().get ('convert_codes' , True ):
102
115
rep = symbol_by_code (p [0 ])
103
116
if rep :
@@ -142,9 +155,16 @@ def run(self, edit):
142
155
rep = symbol_by_name (p [0 ])
143
156
if rep :
144
157
self .view .replace (edit , p [1 ], rep )
158
+ continue
159
+ if is_script (p [0 ]):
160
+ (script_char , chars ) = get_script (p [0 ])
161
+ rep = '' .join ([symbol_by_name (script_char + ch ) for ch in chars ])
162
+ self .view .replace (edit , p [1 ], rep )
163
+ continue
145
164
rep = symbol_by_code (p [0 ])
146
165
if rep :
147
166
self .view .replace (edit , p [1 ], rep )
167
+ continue
148
168
149
169
class UnicodeMathInsertSpace (sublime_plugin .TextCommand ):
150
170
def run (self , edit ):
0 commit comments