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.

I tried:

subprocess.call('latexmk -cd "' + str(path) + '" -c', shell=True)

But this doesn't work.


John Collins provided the answer. The error was that the command to clean up needs to include the .tex filename and not just the path.

Instead of:

subprocess.call('latexmk -cd "' + str(path) + '" -c', shell=True)

In needs to be:

subprocess.call('latexmk -cd "' + str(path/filename) + '" -c', shell=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.