-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathstripHiddenCode.py
More file actions
executable file
·29 lines (28 loc) · 1.2 KB
/
stripHiddenCode.py
File metadata and controls
executable file
·29 lines (28 loc) · 1.2 KB
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
import sys
inVerbatim = 0
for line in sys.stdin:
# correct for missing package that is used in typesetting tables
if (line.find("usepackage{longtable}") > -1):
print(r"\usepackage{booktabs}")
# correct for the bug in nbconvert that is naming jpg files using .jpe
if (line.find("maketitle") > -1):
print(r"\DeclareGraphicsRule{.jpe}{jpg}{*}{}")
if ((line.find("\\begin{Verbatim}") > -1) or (line.find("\\begin{verbatim}") > -1)):
inVerbatim = 1
vblock = line
elif inVerbatim:
vblock = vblock + line
if ((line.find('\\end{Verbatim}') > -1) or (line.find('\\end{verbatim}') > -1)):
inVerbatim = 0
# Things that we omit as verbatim: blocks containing
# hide_code_in_slideshow
# %matplotlib
# IPython.core.display.HTML
# %%html
if ((vblock.find('hide\\PYZus{}code\\PYZus{}in\\PYZus{}slideshow') < 0)
and (vblock.find('\\PY{k}{matplotlib}') < 0)
and (vblock.find('IPython.core.display.HTML') < 0)
and (vblock.find('\\PY{o}{\\PYZpc{}\\PYZpc{}}\\PY{k}{html}') < 0)):
print(vblock, end=" ")
else:
print (line, end=" ")