Last active
December 22, 2015 12:39
-
-
Save jakobgager/6473761 to your computer and use it in GitHub Desktop.
pandoc filters to convert markdown with html and equations to latex
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
#!/usr/bin/env python | |
""" | |
Pandoc filter to conceal raw latex in json. | |
""" | |
from pandoc_2 import toJSONFilter | |
def concealLatex(key, value, format): | |
if key == 'RawInline': | |
if value[0] == 'tex': | |
return {"Str":"$$$"+value[1]+"$$$"} | |
if __name__ == "__main__": | |
toJSONFilter(concealLatex) |
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
#!/usr/bin/env python | |
""" | |
Pandoc filter to put concealed latex to correct | |
container. | |
""" | |
from pandoc_2 import toJSONFilter | |
def revealLatex(key, value, format): | |
if key == 'Str': | |
if value.startswith('$$$') and value.endswith('$$$'): | |
# raw latex | |
return {"RawInline":["tex",value[3:-3]]} | |
elif value.startswith('$$') and value.endswith('$$'): | |
# displaymath | |
return {"Math":["DisplayMath",value[2:-2]]} | |
elif value.startswith('$') and value.endswith('$'): | |
# inlinemath | |
return {"Math":["InlineMath",value[1:-1]]} | |
else: | |
pass | |
if __name__ == "__main__": | |
toJSONFilter(revealLatex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment