-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathpweaveAll.py
More file actions
executable file
·88 lines (77 loc) · 2.23 KB
/
pweaveAll.py
File metadata and controls
executable file
·88 lines (77 loc) · 2.23 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
import os
from pweave import Pweb, PwebTexPweaveFormatter
filenames = [
"expdistribution",
"constructiondiscretetime",
"constructioncontinuoustime",
"ratestability",
"empericalperfmeasures",
"levelcrossing",
"random_walk",
"ratestability",
"mm1",
"mnmn1",
"pasta",
"little",
"usefulidentities",
"mg1",
"batcharrivals",
"mg1distributionqueuelength",
"mg1density",
"gg1",
"serviceInterruptions",
"process_batches",
"tandem",
"convolution",
"mva",
"mda",
]
# to select some files temporarily
# filenames = [
# "mnmn1",
# ]
current_dir = os.path.dirname(os.path.realpath(__file__))
chunk_dir = current_dir + "/chunks/"
tex_dir = current_dir + "/tex_files/"
class ToFile(PwebTexPweaveFormatter):
chunks = []
def preformat_chunk(self, chunk):
ToFile.chunks.append(chunk.copy()) # Store the chunks
if chunk['type'] == 'code':
source = os.path.basename(self.source)
source = os.path.splitext(source)[0]
fname = chunk_dir + "{}_{}.tex".format(source, chunk['number'])
with open(fname, "w") as f:
if chunk['term']:
f.write(chunk['result'])
chunk['result'] = r"\lstinputlisting{"+fname+"}"
else:
f.write(chunk['content'])
f.write(chunk['result'])
chunk['content'] = r"\lstinputlisting{"+fname+"}"
chunk['result'] = "\n\n"
return(chunk)
for fname in filenames:
doc = Pweb(tex_dir + fname+r".tex", format="texpweave",
output=chunk_dir+fname+r".tx")
doc.setformat(Formatter=ToFile)
doc.updateformat({
"outputstart": "\n",
"outputend": "\n",
"codestart": "\n",
"codeend": "\n",
"termstart": "\n",
"termend": "\n",
}
)
# doc.updateformat({
# "outputstart": r"\begin{lstlisting}",
# "outputend": r"\end{lstlisting}",
# "codestart": r"\begin{lstlisting}",
# "codeend": r"\end{lstlisting}",
# "termstart": r"\begin{lstlisting}",
# "termend": r"\end{lstlisting}",
# }
# )
doc.weave()