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.
Last active
May 25, 2024 14:37
-
-
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
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment