Created
February 8, 2015 12:21
-
-
Save ischurov/45acc048c2c321486b56 to your computer and use it in GitHub Desktop.
creates a makefile to convert all ipynb-files to html and pdf
This file contains hidden or 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
import glob | |
import re | |
import os.path | |
import sys | |
published_dir=sys.argv[1] if len(sys.argv)>1 else "published" | |
ipynb=glob.glob("*.ipynb") | |
bns=map(lambda f: os.path.splitext(f)[0], ipynb) | |
bns=map(lambda f: re.sub(r' ','\\ ',f), bns) | |
print """.PHONY: all | |
all: """+" ".join("{1}/{0}.ipynb {1}/{0}.html {1}/{0}.pdf".format(f,published_dir) for f in bns) | |
for fn in bns: | |
print """{1}/{0}.ipynb: {0}.ipynb | |
\t-mkdir -p {1} | |
\tcp -v {0}.ipynb {1}/{0}.ipynb | |
\t-cp -v -r {0}_files {1}/ | |
{1}/{0}.html: {0}.ipynb | |
\t-mkdir -p {1} | |
\tipython nbconvert {0}.ipynb --to html --output {1}/{0} | |
{1}/{0}.pdf: {0}.ipynb | |
\tipython nbconvert {0}.ipynb --to latex --post PDF --template ruarticle | |
\tcp {0}.pdf {1}/ | |
""".format(fn,published_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment