Skip to content

Commit

Permalink
LaTeX: Work around sphinxuseclass environments
Browse files Browse the repository at this point in the history
... which have been introduced in Sphinx 4.1.0.
  • Loading branch information
mgeier committed Aug 1, 2021
1 parent 9c6c308 commit 45244b1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,11 +2170,21 @@ def depart_codearea_latex(self, node):
if lines[0].startswith(r'\fvset{'): # Sphinx >= 1.6.6 and < 1.8.3
out.append(lines[0])
del lines[0]
assert 'Verbatim' in lines[0]
out.append(lines[0])
# Sphinx 4.1.0 added "sphinxuseclass" environments around "sphinxVerbatim"
for begin_verbatim, line in enumerate(lines):
if line.startswith(r'\begin{sphinxVerbatim}'):
break
else:
assert False
for end_verbatim, line in enumerate(reversed(lines)):
if line == r'\end{sphinxVerbatim}':
break
else:
assert False
out.extend(lines[:begin_verbatim + 1])
code_lines = (
[''] * node.get('empty-lines-before', 0) +
lines[1:-1] +
lines[begin_verbatim + 1:-end_verbatim - 1] +
[''] * node.get('empty-lines-after', 0)
)
prompt = node['prompt']
Expand All @@ -2185,8 +2195,7 @@ def depart_codearea_latex(self, node):
assert code_lines
code_lines[0] = prefix + code_lines[0]
out.extend(code_lines)
assert 'Verbatim' in lines[-1]
out.append(lines[-1])
out.extend(lines[-end_verbatim - 1:])
out.append('}') # End of scope for colors
out.append('')
self.body.append('\n'.join(out))
Expand Down

0 comments on commit 45244b1

Please sign in to comment.