Skip to content

Instantly share code, notes, and snippets.

@jonathansick
Created September 2, 2012 03:49
Show Gist options
  • Save jonathansick/3594679 to your computer and use it in GitHub Desktop.
Save jonathansick/3594679 to your computer and use it in GitHub Desktop.
Run make whenever a LaTeX file is modified (using Python watchdog)
import subprocess
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ChangeHandler(FileSystemEventHandler):
"""React to modified .tex files."""
def on_any_event(self, event):
"""If a file or folder is changed."""
if event.is_directory:
return
if os.path.splitext(event.src_path)[-1].lower() == ".tex":
subprocess.call("make", shell=True)
def main():
handler = ChangeHandler()
observer = Observer()
observer.schedule(handler, '.')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment