1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#!/usr/bin/env python3
"""
Pandoc filter to convert divs with latex="true" to LaTeX
environments in LaTeX output. The first class
will be regarded as the name of the latex environment
e.g.
<div latex="true" class="note abc">...</div>
will becomes
\begin{note}...\end{note}
"""
from pandocfilters import toJSONFilter, RawBlock, Div
def latex(x):
return RawBlock('latex', x)
def latexdivs(key, value, format, meta):
if key == 'Div':
[[ident, classes, kvs], contents] = value
if ["latex","true"] in kvs:
if format == "latex":
if ident == "":
label = ""
else:
label = '\\label{' + ident + '}'
return([latex('\\begin{' + classes[0] + '}' + label)] + contents +
[latex('\\end{' + classes[0] + '}')])
if __name__ == "__main__":
toJSONFilter(latexdivs)
|