15
15
beginCodeBlockTag = "BeginCodeSnippet"
16
16
endCodeBlockTag = "EndCodeSnippet"
17
17
18
- validCodeBlockTypes = [' Latex' , ' CodeSnippet' ]
18
+ validCodeBlockTypes = [" Latex" , " CodeSnippet" ]
19
19
20
20
## This class is initialized with a the starting line of
21
21
## the command processing, and the block of text for
22
22
## this command invocation
23
23
24
24
25
- class OneDocBlock () :
25
+ class OneDocBlock :
26
26
def __init__ (self , sourceFile , id , codeblock ):
27
27
self .sourceFile = sourceFile
28
28
self .id = id
29
29
self .codeblock = codeblock
30
- self .blockType = ' Unknown' # Something other than items in validCodeBlockTypes
30
+ self .blockType = " Unknown" # Something other than items in validCodeBlockTypes
31
31
32
32
def Print (self ):
33
33
blockline = self .id
@@ -40,16 +40,16 @@ def Print(self):
40
40
41
41
def GetCodeBlockString (self ):
42
42
blockstring = ""
43
- if self .blockType == ' Latex' :
43
+ if self .blockType == " Latex" :
44
44
for blocktext in self .codeblock :
45
45
blockstring += "{0}\n " .format (blocktext )
46
46
pass
47
- elif self .blockType == ' CodeSnippet' :
47
+ elif self .blockType == " CodeSnippet" :
48
48
# blockstring += "\\small\n"
49
49
# blockstring += "\\begin{verbatim}\n"
50
50
# blockstring += "\\begin{itklisting}[language=C++]\n"
51
51
blockstring += "\\ begin{minted}[baselinestretch=1,fontsize=\\ footnotesize,linenos=false,bgcolor=ltgray]{c++}\n "
52
- # blockstring += "\\begin{minted}[baselinestretch=1,fontsize=\small,linenos=false,bgcolor=ltgray]{c++}\n"
52
+ # blockstring += "\\begin{minted}[baselinestretch=1,fontsize=\small,linenos=false,bgcolor=ltgray]{c++}\n"
53
53
for blocktext in self .codeblock :
54
54
blockstring += "{0}" .format (blocktext )
55
55
blockstring += "\\ end{minted}\n "
@@ -70,7 +70,7 @@ def ParseOneFile(sourceFile):
70
70
# Read each line and Parse the input file
71
71
#
72
72
# Get the command line args from the source file
73
- sf = open (sourceFile , 'r' )
73
+ sf = open (sourceFile , "r" )
74
74
INFILE = sf .readlines ()
75
75
sf .close ()
76
76
parseLine = 0
@@ -90,7 +90,7 @@ def ParseOneFile(sourceFile):
90
90
checkForBlankLine = True
91
91
elif thisline .count (endLatexTag ) == 1 : # end of LatexCodeBlock
92
92
ocb = OneDocBlock (sourceFile , starttagline , codeBlock )
93
- ocb .blockType = ' Latex'
93
+ ocb .blockType = " Latex"
94
94
thisFileCommandBlocks .append (ocb )
95
95
starttagline = 0
96
96
elif thisline .count (beginCodeBlockTag ) == 1 : # start of CodeSnippet
@@ -99,28 +99,27 @@ def ParseOneFile(sourceFile):
99
99
codeBlock = []
100
100
elif thisline .count (endCodeBlockTag ) == 1 : # end of CodeSnippet
101
101
ocb = OneDocBlock (sourceFile , starttagline , codeBlock )
102
- ocb .blockType = ' CodeSnippet'
102
+ ocb .blockType = " CodeSnippet"
103
103
thisFileCommandBlocks .append (ocb )
104
104
starttagline = 0
105
105
elif starttagline > 0 : # Inside a codeBlock
106
106
if isLatexBlock == True :
107
- thisline = commentPattern .sub ("" ,thisline )
107
+ thisline = commentPattern .sub ("" , thisline )
108
108
thisline = thisline .lstrip ().rstrip ()
109
109
if checkForBlankLine :
110
- if thisline != "" :
111
- print ("{filename}:{line}: warning: Line after start of LaTeX block should be a newline -- instead got {value}" .format (
112
- filename = sourceFile ,
113
- line = parseLine ,
114
- value = thisline
115
- )
110
+ if thisline != "" :
111
+ print (
112
+ "{filename}:{line}: warning: Line after start of LaTeX block should be a newline -- instead got {value}" .format (
113
+ filename = sourceFile , line = parseLine , value = thisline
114
+ )
115
+ )
116
+ checkForBlankLine = False
117
+
118
+ if not isLatexBlock and (len (thisline ) > 80 ):
119
+ print (
120
+ "{filename}:{line}:80: warning: Line length too long for LaTeX printing" .format (
121
+ filename = sourceFile , line = parseLine
116
122
)
117
- checkForBlankLine = False
118
-
119
- if not isLatexBlock and ( len (thisline ) > 80 ):
120
- print ("{filename}:{line}:80: warning: Line length too long for LaTeX printing" .format (
121
- filename = sourceFile ,
122
- line = parseLine
123
- )
124
123
)
125
124
codeBlock .append (thisline )
126
125
else : # non-codeBlock line
@@ -142,11 +141,15 @@ def GetPreambleString(examplefilename):
142
141
143
142
The source code for this section can be found in the file\\ \\
144
143
\\ texttt{2}{1}{3}.
145
- """ .format (examplefilename , os .path .basename (examplefilename ), '{' , '}' )
144
+ """ .format (
145
+ examplefilename , os .path .basename (examplefilename ), "{" , "}"
146
+ )
146
147
return preamble
147
148
149
+
148
150
if __name__ == "__main__" :
149
151
import sys
152
+
150
153
if len (sys .argv ) < 2 :
151
154
print ("Usage: {0} <input file> <output file>" .format (argv [0 ]))
152
155
sys .exit (- 1 )
@@ -166,7 +169,7 @@ def GetPreambleString(examplefilename):
166
169
else :
167
170
raise
168
171
169
- outPtr = open (outputfilename , 'w' )
172
+ outPtr = open (outputfilename , "w" )
170
173
outPtr .write (GetPreambleString (inputfilename ))
171
174
for cb in thisCodeBlocks :
172
175
outPtr .write (cb .GetCodeBlockString ())
0 commit comments