Skip to content

Commit 14359f4

Browse files
committed
Added converting sub- and superscripts
1 parent 2ac8c00 commit 14359f4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

UnicodeMath.sublime-settings

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
// Syntaxes to ignore
1616
"ignore_syntax": ["latex"],
1717
// Convert \uXXXX and \UXXXXXXXX to symbol
18-
"convert_codes": true
18+
"convert_codes": true,
19+
// Convert multichar subscript and superscript \^abc → \^a\^b\^c and \_abc → \_a\_b\_c
20+
"convert_sub_super": true
1921
}

unicodecomplete.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def code_by_symbol(sym):
8383
return u'U%08X' % u
8484
return None
8585

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+
8695
def can_convert(view):
8796
"""
8897
Determines if there are any regions, where symbol can be converted
@@ -98,6 +107,10 @@ def can_convert(view):
98107
rep = symbol_by_name(p[0])
99108
if rep:
100109
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
101114
if get_settings().get('convert_codes', True):
102115
rep = symbol_by_code(p[0])
103116
if rep:
@@ -142,9 +155,16 @@ def run(self, edit):
142155
rep = symbol_by_name(p[0])
143156
if rep:
144157
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
145164
rep = symbol_by_code(p[0])
146165
if rep:
147166
self.view.replace(edit, p[1], rep)
167+
continue
148168

149169
class UnicodeMathInsertSpace(sublime_plugin.TextCommand):
150170
def run(self, edit):

0 commit comments

Comments
 (0)