Python equivalent to Bash: `latexmk file.tex && la

2019-08-01 03:14发布

问题:

The issue of converting && in Bash to Python has been resolved with the assistance of Xymostech, whose help is greatly appreciated -- thank you!

The command line at issue (from the Bash terminal) is: latexmk file.tex && latexmk -c file.tex.

Here is the plugin if anyone is interested:

https://github.com/lawlist/ST2-plugin-latexmk-save-build-clean

回答1:

The && is a feature that is supported by bash. You can do the same thing in python though, using subprocess's check_call:

import subprocess

try:
    subprocess.check_call(["latexmk", "file.tex"])
except subprocess.CalledProcessError:
    print "Failed making"
else:
    subprocess.call(["latexmk", "-c", "file.tex"])