Skip to content

Instantly share code, notes, and snippets.

@tarptaeya
Created January 16, 2022 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarptaeya/0f6bf8b04e708fa0d4e46412995b5d65 to your computer and use it in GitHub Desktop.
Save tarptaeya/0f6bf8b04e708fa0d4e46412995b5d65 to your computer and use it in GitHub Desktop.
init-book
import os, sys
import subprocess
if __name__ == "__main__":
if len(sys.argv) < 2:
print("[usage] init-book NAME")
sys.exit(0)
name = sys.argv[1]
subprocess.call(["mkdir", "-p", name])
os.chdir(name)
with open(os.path.join(os.path.dirname(__file__), "Makefile"), "r") as f:
makefile_text = f.read()
makefile_text = makefile_text.replace("%%NAME%%", name)
with open("Makefile", "w") as m:
m.write(makefile_text)
with open("metadata.yml", "w") as m:
m.write("")
subprocess.call(["mkdir", "-p", "src"])
subprocess.call(["touch", "src/0000.md"])
all:
pandoc metadata.yml `ls src/*.md | sort` -o %%NAME%%.pdf \
--table-of-contents \
--number-sections \
--pdf-engine=xelatex \
-V mainfont="Palatino" \
-V documentclass=report \
-V papersize=A4 \
-V geometry:margin=1in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment