Skip to content

Commit

Permalink
Convert pandoc's RawInline("tex") to DisplayMath
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Jul 17, 2018
1 parent c17b525 commit 3f43216
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,29 @@ def markdown2rst(text):
except that it uses a pandoc filter to convert raw LaTeX blocks to
"math" directives (instead of "raw:: latex" directives).
NB: At some point, pandoc changed its behavior! In former times,
it converted LaTeX math environments to RawBlock ("latex"), at some
later point this was changed to RawInline ("tex").
Either way, we convert it to Math/DisplayMath.
"""

def displaymath(text):
return {
't': 'Math',
'c': [
{'t': 'DisplayMath', 'c': []},
# Special marker characters are removed below:
'\x0e:nowrap:\x0f\n\n' + text,
]
}

def rawlatex2math_hook(obj):
if obj.get('t') == 'RawBlock' and obj['c'][0] == 'latex':
obj['t'] = 'Para'
obj['c'] = [{
't': 'Math',
'c': [
{'t': 'DisplayMath', 'c': []},
# Special marker characters are removed below:
'\x0e:nowrap:\x0f\n\n' + obj['c'][1],
]
}]
obj['c'] = [displaymath(obj['c'][1])]
elif obj.get('t') == 'RawInline' and obj['c'][0] == 'tex':
obj = displaymath(obj['c'][1])
return obj

def rawlatex2math(text):
Expand Down

0 comments on commit 3f43216

Please sign in to comment.