Skip to content

Instantly share code, notes, and snippets.

@3-24
Last active September 15, 2018 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3-24/ede668c50e21a70a51d1f1c20000d8b9 to your computer and use it in GitHub Desktop.
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.
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