Skip to content

Instantly share code, notes, and snippets.

@jakobgager
Last active December 22, 2015 12:39
Show Gist options
  • Save jakobgager/6473761 to your computer and use it in GitHub Desktop.
Save jakobgager/6473761 to your computer and use it in GitHub Desktop.
pandoc filters to convert markdown with html and equations to latex
#!/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)
#!/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