Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. parser = argparse.ArgumentParser()
  2. parser.add_argument("target", help="the path of the file you want to preprocess")
  3. parser.add_argument("fileName", help="the path/name of the post-processed file")
  4. parser.add_argument("-nsm", "--nonstopMode", help="turns on or off nonstopmode when generating the pdf with pdflatex", action="store_true")
  5. parser.add_argument("-fv", "--fancyVerbatim", help="turns on or off fancy verbatim being generated for the pdf", action="store_true")
  6. parser.add_argument("-v", "--verbose", help="turns on or off more verbose terminal output", action="store_true")
  7. args = parser.parse_args()
  8.  
  9. fancyVerbatim = True
  10. if not args.fancyVerbatim:
  11. fancyVerbatim = False
  12.  
  13. target = args.target
  14. fileName = args.fileName
  15.  
  16. if args.verbose:
  17. print "Fetching file to preprocess..."
  18. fileToEdit = open(target, "r")
  19. fileAsString = fileToEdit.read()
  20. fileToEdit.close()
  21.  
  22. if args.verbose:
  23. print "Processing Latex inputs..."
  24. processedString = ProcessLatexInputs(fileAsString)
  25. processedString = MoveLatexPackages(processedString)
  26.  
  27. if args.verbose:
  28. print "Processing %@vars...."
  29. processedString = ProcessVariables(processedString)
  30.  
  31. if args.verbose:
  32. print "Processing %@imports..."
  33. processedString = ProcessImports(processedString, fancyVerbatim)
  34.  
  35. if args.verbose:
  36. print "Processing %@execs..."
  37. processedString = ProcessExecutions(processedString, fancyVerbatim)
  38.  
  39. if args.verbose:
  40. print "Generating header for formatting..."
  41. processedString = GenerateHeader(processedString)
  42. #print processedString
  43.  
  44. if args.verbose:
  45. print "Generating "+fileName
  46. testfile = open(fileName, "w")
  47. testfile.write(processedString)
  48. testfile.close()
  49.  
  50. command = ""
  51. if args.nonstopMode:
  52. command = "pdflatex -file-line-error -interaction=nonstopmode "+fileName
  53. else:
  54. command = "pdflatex -file-line-error "+fileName
  55. """
  56. command2 = []
  57. command2.append("pdflatex")
  58. command2.append("-file-line-error")
  59. command2.append("-interaction=nonstopmode")
  60. command2.append(fileName)
  61. """
  62. if args.verbose:
  63. pdfName = fileName[:-4]+".pdf"
  64. print "Generating "+pdfName
  65.  
  66. process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  67.  
  68. output, err = process.communicate()
  69.  
  70. output2 = re.search(r".*\n.*$", output)
  71.  
  72. print "\n", "last two lines of pdflatex output:\n", output2.group(0),"\n"
  73. print "pdflatex error messages:\n", err
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement