Created
January 25, 2016 14:00
-
-
Save AndiH/494d468791a1824dba25 to your computer and use it in GitHub Desktop.
Run script for Markdown —Pandoc&latexmk→ PDF Beamer presentation generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Small script to call Pandoc and latexmk | |
# Andreas Herten, Jan 2016 | |
import argparse, subprocess, os | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description = "Run LaTeX generation", prefix_chars="-+") | |
parser.add_argument("-v", "--verbose", action="count", help="Turns on verbose for latexmk (-v) and verbose for pandoc (-vv)") | |
parser.add_argument("-c", "--clean", action="store_true", help="Let latexmk clean all temporary files after typesetting") | |
parser.add_argument("-o", "--noopen", action="store_true", help="Do not open the PDF after typesetting") | |
parser.add_argument("filename", metavar="filename", type=str, help="File to process into slides; probably Markdown.") | |
parser.add_argument("paramsPandoc", metavar="paramsPandoc", nargs="?", type=str, help="Params passed to Pandoc for creating the .tex file", default="") | |
parser.add_argument("paramsLaTeX", metavar="paramsLaTeX", nargs="?", type=str, help="Params passed to latexmk for typsetting the PDF; most of the default ones are set in the .latexmkrc file.", default="") | |
args = parser.parse_args() | |
latexParams = str(args.paramsLaTeX) | |
if not (args.verbose): | |
args.paramsLaTeX += " -silent" | |
if (args.verbose > 1): | |
args.paramsPandoc += " -v" | |
filenameWOExtension = str(os.path.splitext(args.filename)[0]) | |
filenameTex = filenameWOExtension + ".tex" | |
filenamePdf = filenameWOExtension + ".pdf" | |
pandocInvokation = str("pandoc -t beamer -s " + str(args.filename) + " -o " + filenameTex + " --template modifieddefault.beamer " + str(args.paramsPandoc)) | |
latexmkInvokation = str("latexmk " + filenameTex + " " + str(args.paramsLaTeX)) | |
print("## Calling pandoc: " + pandocInvokation) | |
subprocess.call(pandocInvokation, shell=True) | |
print("## Calling latexmk: " + latexmkInvokation) | |
subprocess.call(latexmkInvokation, shell=True) | |
if not (args.noopen): | |
print("## Open " + filenamePdf) | |
subprocess.call("open " + filenamePdf, shell=True) | |
if (args.clean): | |
print("## Cleaning with latexmk") | |
subprocess.call("latexmk -c " + filenameTex, shell=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment