Skip to content

Commit 749315e

Browse files
committed
Use custom role "nbsphinx-math" for inline LaTeX
1 parent a6783d7 commit 749315e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/nbsphinx.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,15 @@ def parse(self, inputstring, document):
835835
env.doc2path(env.docname, base=None) + ':\n' +
836836
str(e))
837837

838+
rststring = """
839+
.. role:: nbsphinx-math(raw)
840+
:format: latex + html
841+
:class: math
842+
843+
..
844+
845+
""" + rststring
846+
838847
# Create additional output files (figures etc.),
839848
# see nbconvert.writers.FilesWriter.write()
840849
for filename, data in resources.get('outputs', {}).items():
@@ -1059,16 +1068,6 @@ def markdown2rst(text):
10591068
10601069
"""
10611070

1062-
def displaymath(text):
1063-
return {
1064-
't': 'Math',
1065-
'c': [
1066-
{'t': 'DisplayMath', 'c': []},
1067-
# Special marker characters are removed below:
1068-
'\x0e:nowrap:\x0f\n\n' + text,
1069-
]
1070-
}
1071-
10721071
def parse_html(obj):
10731072
p = CitationParser()
10741073
p.feed(obj['c'][1])
@@ -1088,9 +1087,17 @@ def object_hook(obj):
10881087

10891088
if obj.get('t') == 'RawBlock' and obj['c'][0] == 'latex':
10901089
obj['t'] = 'Para'
1091-
obj['c'] = [displaymath(obj['c'][1])]
1090+
obj['c'] = [{
1091+
't': 'Math',
1092+
'c': [
1093+
{'t': 'DisplayMath'},
1094+
# Special marker characters are removed below:
1095+
'\x0e:nowrap:\x0f\n\n' + obj['c'][1],
1096+
]
1097+
}]
10921098
elif obj.get('t') == 'RawInline' and obj['c'][0] == 'tex':
1093-
obj = displaymath(obj['c'][1])
1099+
obj = {'t': 'RawInline',
1100+
'c': ['rst', ':nbsphinx-math:`{}`'.format(obj['c'][1])]}
10941101
elif obj.get('t') == 'RawInline' and obj['c'][0] == 'html':
10951102
p = parse_html(obj)
10961103
if p.starttag:

0 commit comments

Comments
 (0)