Skip to content

Commit

Permalink
Use custom role "nbsphinx-math" for inline LaTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Dec 11, 2018
1 parent a6783d7 commit 749315e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,15 @@ def parse(self, inputstring, document):
env.doc2path(env.docname, base=None) + ':\n' +
str(e))

rststring = """
.. role:: nbsphinx-math(raw)
:format: latex + html
:class: math
..
""" + rststring

# Create additional output files (figures etc.),
# see nbconvert.writers.FilesWriter.write()
for filename, data in resources.get('outputs', {}).items():
Expand Down Expand Up @@ -1059,16 +1068,6 @@ def markdown2rst(text):
"""

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

def parse_html(obj):
p = CitationParser()
p.feed(obj['c'][1])
Expand All @@ -1088,9 +1087,17 @@ def object_hook(obj):

if obj.get('t') == 'RawBlock' and obj['c'][0] == 'latex':
obj['t'] = 'Para'
obj['c'] = [displaymath(obj['c'][1])]
obj['c'] = [{
't': 'Math',
'c': [
{'t': 'DisplayMath'},
# Special marker characters are removed below:
'\x0e:nowrap:\x0f\n\n' + obj['c'][1],
]
}]
elif obj.get('t') == 'RawInline' and obj['c'][0] == 'tex':
obj = displaymath(obj['c'][1])
obj = {'t': 'RawInline',
'c': ['rst', ':nbsphinx-math:`{}`'.format(obj['c'][1])]}
elif obj.get('t') == 'RawInline' and obj['c'][0] == 'html':
p = parse_html(obj)
if p.starttag:
Expand Down

0 comments on commit 749315e

Please sign in to comment.