Last active
September 15, 2018 02:23
-
-
Save 3-24/ede668c50e21a70a51d1f1c20000d8b9 to your computer and use it in GitHub Desktop.
Typora sets the math equations delimiters as ($,$) and ((<p class='md-mathblock>)$,$) for HTML source. This file converts the delimiters to (\( , \)) and ( \[, \] ) to use in Mathjax using in-line inputs and output.txt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkInline(s): | |
i = 0 | |
while True: | |
try: | |
if s[i] == '$': | |
return i | |
except IndexError: | |
return -1 | |
i += 1 | |
def checkOutline(s): | |
return s == "<p class='md-math-block'>$" | |
def main(): | |
f = open("./output.txt", "w") | |
while True: | |
print('newline') | |
s = input() | |
if s == ':qa!': | |
f.close() | |
break | |
else: | |
if checkOutline(s): | |
f.write('<p>\[\n') | |
while True: | |
t = input() | |
if t == '$</p>': | |
f.write('\]</p>\n') | |
break | |
else: | |
f.write(t+'\n') | |
elif checkInline(s) >= 0: | |
i = checkInline(s) | |
j = checkInline(s[i+1:]) | |
f.write(s[:i] + '\(' + s[i+1:i+j+1] + '\)' + s[i+j+2:] + '\n') | |
else: | |
f.write(s+'\n') | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment