Skip to content

Instantly share code, notes, and snippets.

@dact221
Last active May 25, 2024 14:37
Show Gist options
  • Save dact221/29ab3fc2bf473cb7097384b9acc3d045 to your computer and use it in GitHub Desktop.
Save dact221/29ab3fc2bf473cb7097384b9acc3d045 to your computer and use it in GitHub Desktop.
Simple Python program that monitors changes in SVG files and export them as PDF+LaTeX
import os
import time
import subprocess
INKSCAPE = "C:/Program Files/Inkscape/bin/inkscape.exe"
while True:
for f in os.listdir():
root, ext = os.path.splitext(f)
if ext != ".svg":
continue
svg = f
pdf = root + ".pdf"
try:
export = os.path.getmtime(svg) > os.path.getmtime(pdf)
except OSError:
# If getmtime raises error then pdf does not exist; so export first time
export = True
if export:
print(time.ctime(), f"Exporting {svg} as PDF+LaTeX...", end=" ")
subprocess.run([INKSCAPE, "--export-type=pdf", "--export-latex", "--export-area-drawing", "--export-dpi", "300", svg])
print("OK")
time.sleep(5)

SVG to PDF+LaTeX

Simple Python program that monitors changes in the SVG files of the current directory and export them as PDF+LaTeX using inkscape commandline options. See this example in CTAN for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment