I am using latexmk and calling it from within python, with the following command:
latex_params = ' -pdf -interaction=nonstopmode -gg -silent' latexmk_string = str("latexmk -cd " + '"' + str(path/filename) + '"' + latex_params) subprocess.call(latexmk_string, shell=True)
Note that the '"' double-quotation marks in the latexmk_string are used in cases where the path name has special characters (such as parenthesis).
The code above works just fine. The problem I am having is with the -c option to clean up the aux files. I couldn't find any way to include it in the latex_params string and get it to work.
I was able to get it to work if I used the following code after the code above, essentially calling the cleanup function on its own:
subprocess.call('latexmk -c', shell=True)
Except, that this ONLY works if the file path is the current directory. In my case, the .tex file is NOT in the current directory and the -cd option above handles that for the creation of the pdf file. But then I am not able to get the -c cleanup command to work.
subprocess.call('latexmk -cd "' + str(path) + '" -c', shell=True)
But this doesn't work.