Skip to content

Instantly share code, notes, and snippets.

@cben
Created March 18, 2014 04:52
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 cben/9613755 to your computer and use it in GitHub Desktop.
Save cben/9613755 to your computer and use it in GitHub Desktop.
pandoc filter to convert $..$ and $$...$$ math to \\(..\\) and \\[...\\] respectively.
#!/usr/bin/env python2
r"""
Use via ``pandoc --filter pandoc_filter_math2doublebackslashmath.py``
to convert math (in any syntax pandoc will recognize)
to \\(..\\) and \\[...\\] syntaxes (``tex_math_double_backslash`` extension).
"""
from pandocfilters import toJSONFilter, Math, RawInline, RawBlock
import sys, json
def math2math(key, value, format, meta):
if key == 'Math':
#print >>sys.stderr, key, value, format#, meta
[flavor, formula] = value
if format == 'latex':
format = 'tex'
if flavor['t'] == 'InlineMath':
return RawInline(format, r'\\(' + formula + r'\\)')
elif flavor['t'] == 'DisplayMath':
return RawInline(format, r'\\[' + formula + r'\\]')
if __name__ == '__main__':
toJSONFilter(math2math)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment