Add the capability to actually compile the generated tex file.
Now it's a matter of improving the is_valid function and the looks of the written table.
This commit is contained in:
parent
2c0ce4c9e1
commit
d81d4a6db8
1 changed files with 26 additions and 2 deletions
|
@ -9,6 +9,10 @@ if you're one of those people.
|
|||
# STL imports
|
||||
import random
|
||||
import pprint
|
||||
import subprocess
|
||||
import tempfile
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
# Auxiliary Functions
|
||||
|
@ -222,8 +226,28 @@ def write_grid(grid, screen=False, out_file="table.tex"):
|
|||
texfile.write("\end{tabular}\n")
|
||||
texfile.write("\end{document}\n")
|
||||
|
||||
# Compile
|
||||
# TODO
|
||||
# Compile in a temp folder
|
||||
# (inspired by
|
||||
# https://stackoverflow.com/questions/19683123/compile-latex-from-python)
|
||||
if not screen:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
# Save current directory
|
||||
original_dir = os.getcwd()
|
||||
|
||||
# Copy the latex source to the temporary directory
|
||||
shutil.copy(out_file, tmpdir)
|
||||
|
||||
# Move to the temp directory
|
||||
os.chdir(tmpdir)
|
||||
|
||||
# Rename .tex file to generic name "out"
|
||||
os.rename(out_file, "out.tex")
|
||||
|
||||
# Compile
|
||||
proc = subprocess.call(['pdflatex', "out.tex"])
|
||||
|
||||
# Copy PDF back to the original directory
|
||||
shutil.copy("out.pdf", original_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue