Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parser = argparse.ArgumentParser()
- parser.add_argument("target", help="the path of the file you want to preprocess")
- parser.add_argument("fileName", help="the path/name of the post-processed file")
- parser.add_argument("-nsm", "--nonstopMode", help="turns on or off nonstopmode when generating the pdf with pdflatex", action="store_true")
- parser.add_argument("-fv", "--fancyVerbatim", help="turns on or off fancy verbatim being generated for the pdf", action="store_true")
- parser.add_argument("-v", "--verbose", help="turns on or off more verbose terminal output", action="store_true")
- args = parser.parse_args()
- fancyVerbatim = True
- if not args.fancyVerbatim:
- fancyVerbatim = False
- target = args.target
- fileName = args.fileName
- if args.verbose:
- print "Fetching file to preprocess..."
- fileToEdit = open(target, "r")
- fileAsString = fileToEdit.read()
- fileToEdit.close()
- if args.verbose:
- print "Processing Latex inputs..."
- processedString = ProcessLatexInputs(fileAsString)
- processedString = MoveLatexPackages(processedString)
- if args.verbose:
- print "Processing %@vars...."
- processedString = ProcessVariables(processedString)
- if args.verbose:
- print "Processing %@imports..."
- processedString = ProcessImports(processedString, fancyVerbatim)
- if args.verbose:
- print "Processing %@execs..."
- processedString = ProcessExecutions(processedString, fancyVerbatim)
- if args.verbose:
- print "Generating header for formatting..."
- processedString = GenerateHeader(processedString)
- #print processedString
- if args.verbose:
- print "Generating "+fileName
- testfile = open(fileName, "w")
- testfile.write(processedString)
- testfile.close()
- command = ""
- if args.nonstopMode:
- command = "pdflatex -file-line-error -interaction=nonstopmode "+fileName
- else:
- command = "pdflatex -file-line-error "+fileName
- """
- command2 = []
- command2.append("pdflatex")
- command2.append("-file-line-error")
- command2.append("-interaction=nonstopmode")
- command2.append(fileName)
- """
- if args.verbose:
- pdfName = fileName[:-4]+".pdf"
- print "Generating "+pdfName
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
- output, err = process.communicate()
- output2 = re.search(r".*\n.*$", output)
- print "\n", "last two lines of pdflatex output:\n", output2.group(0),"\n"
- print "pdflatex error messages:\n", err
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement