diff options
author | Julian T <julian@jtle.dk> | 2021-02-15 00:15:15 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-15 00:15:15 +0100 |
commit | 4fd876a782407f346e53d581f3d0540cb6e6dc65 (patch) | |
tree | 7b8e774051b7028367603536a094e7ecd04dcc8e /render.py | |
parent | e02c08e47313e3941211fc17fd0e1cb225b47b7b (diff) |
Added latex render script
Diffstat (limited to 'render.py')
-rwxr-xr-x | render.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/render.py b/render.py new file mode 100755 index 0000000..0964547 --- /dev/null +++ b/render.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# Render a single document + +import argparse +import os +import jinja2 +import subprocess +import re + +tex_template = """\\documentclass[12pt]{article} +\\usepackage{amsmath} +\\usepackage{amsfonts} + +{% if p is not none %} +\\title{ {{title}} } +{% endif %} + +\\begin{document} + {% if title is not none %} + \maketitle + {% endif %} + + {{content}} +\\end{document} +""" + +parser = argparse.ArgumentParser() +parser.add_argument("file", help="The file to load") + +args = parser.parse_args() + +# Load the file +content = [] +title = None +with open(args.file, "r") as f: + for line in f: + m = re.findall("\\\\title\{(.*)\}", line) + if m: + title = m[0] + else: + content.append(line) + +content = "".join(content) +print(content) + +# Write to output +tmpl = jinja2.Template(tex_template) +output = tmpl.render(title=title,content=content) + +# Create build folder +if not os.path.exists("render_build"): + os.mkdir("render_build") + +os.chdir("render_build") +with open("input.tex", "w") as f: + f.write(output) + +subprocess.call(["pdflatex", "input.tex"]) |