Ask Your Question

Revision history [back]

Python's subprocess module is a good tool for this.

sage: import subprocess
sage: ret = subprocess.call(['ls', '-al'])
drwxr-xr-x  17 palmieri  palmieri   578 May  5 09:02 Applications
drwx------+ 13 palmieri  palmieri   442 Aug 10 13:20 Desktop
drwx------+ 27 palmieri  palmieri   918 Jun  1 08:57 Documents
drwx------+ 15 palmieri  palmieri   510 Aug 10 13:17 Downloads
drwx------@ 74 palmieri  palmieri  2516 Aug  9 15:28 Library
sage: ret
0

The first argument to subprocess.call is a list: the first entry is the command, and the remaining entries are its arguments. It returns the return code. You should be able to put this into your code:

import subprocess
subprocess.call(['pdflatex', 'foo.tex'])

You could also use other functions from the subprocess module if you want other capabilities.