1515beginCodeBlockTag = "BeginCodeSnippet"
1616endCodeBlockTag = "EndCodeSnippet"
1717
18- validCodeBlockTypes = [' Latex' , ' CodeSnippet' ]
18+ validCodeBlockTypes = [" Latex" , " CodeSnippet" ]
1919
2020## This class is initialized with a the starting line of
2121## the command processing, and the block of text for
2222## this command invocation
2323
2424
25- class OneDocBlock () :
25+ class OneDocBlock :
2626 def __init__ (self , sourceFile , id , codeblock ):
2727 self .sourceFile = sourceFile
2828 self .id = id
2929 self .codeblock = codeblock
30- self .blockType = ' Unknown' # Something other than items in validCodeBlockTypes
30+ self .blockType = " Unknown" # Something other than items in validCodeBlockTypes
3131
3232 def Print (self ):
3333 blockline = self .id
@@ -40,16 +40,16 @@ def Print(self):
4040
4141 def GetCodeBlockString (self ):
4242 blockstring = ""
43- if self .blockType == ' Latex' :
43+ if self .blockType == " Latex" :
4444 for blocktext in self .codeblock :
4545 blockstring += "{0}\n " .format (blocktext )
4646 pass
47- elif self .blockType == ' CodeSnippet' :
47+ elif self .blockType == " CodeSnippet" :
4848 # blockstring += "\\small\n"
4949 # blockstring += "\\begin{verbatim}\n"
5050 # blockstring += "\\begin{itklisting}[language=C++]\n"
5151 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"
5353 for blocktext in self .codeblock :
5454 blockstring += "{0}" .format (blocktext )
5555 blockstring += "\\ end{minted}\n "
@@ -70,7 +70,7 @@ def ParseOneFile(sourceFile):
7070 # Read each line and Parse the input file
7171 #
7272 # Get the command line args from the source file
73- sf = open (sourceFile , 'r' )
73+ sf = open (sourceFile , "r" )
7474 INFILE = sf .readlines ()
7575 sf .close ()
7676 parseLine = 0
@@ -90,7 +90,7 @@ def ParseOneFile(sourceFile):
9090 checkForBlankLine = True
9191 elif thisline .count (endLatexTag ) == 1 : # end of LatexCodeBlock
9292 ocb = OneDocBlock (sourceFile , starttagline , codeBlock )
93- ocb .blockType = ' Latex'
93+ ocb .blockType = " Latex"
9494 thisFileCommandBlocks .append (ocb )
9595 starttagline = 0
9696 elif thisline .count (beginCodeBlockTag ) == 1 : # start of CodeSnippet
@@ -99,28 +99,27 @@ def ParseOneFile(sourceFile):
9999 codeBlock = []
100100 elif thisline .count (endCodeBlockTag ) == 1 : # end of CodeSnippet
101101 ocb = OneDocBlock (sourceFile , starttagline , codeBlock )
102- ocb .blockType = ' CodeSnippet'
102+ ocb .blockType = " CodeSnippet"
103103 thisFileCommandBlocks .append (ocb )
104104 starttagline = 0
105105 elif starttagline > 0 : # Inside a codeBlock
106106 if isLatexBlock == True :
107- thisline = commentPattern .sub ("" ,thisline )
107+ thisline = commentPattern .sub ("" , thisline )
108108 thisline = thisline .lstrip ().rstrip ()
109109 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
116122 )
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- )
124123 )
125124 codeBlock .append (thisline )
126125 else : # non-codeBlock line
@@ -142,11 +141,15 @@ def GetPreambleString(examplefilename):
142141
143142The source code for this section can be found in the file\\ \\
144143\\ texttt{2}{1}{3}.
145- """ .format (examplefilename , os .path .basename (examplefilename ), '{' , '}' )
144+ """ .format (
145+ examplefilename , os .path .basename (examplefilename ), "{" , "}"
146+ )
146147 return preamble
147148
149+
148150if __name__ == "__main__" :
149151 import sys
152+
150153 if len (sys .argv ) < 2 :
151154 print ("Usage: {0} <input file> <output file>" .format (argv [0 ]))
152155 sys .exit (- 1 )
@@ -166,7 +169,7 @@ def GetPreambleString(examplefilename):
166169 else :
167170 raise
168171
169- outPtr = open (outputfilename , 'w' )
172+ outPtr = open (outputfilename , "w" )
170173 outPtr .write (GetPreambleString (inputfilename ))
171174 for cb in thisCodeBlocks :
172175 outPtr .write (cb .GetCodeBlockString ())
0 commit comments