I'm trying to execute latexmk from my web application and need to specify the path of its output directory. (I'm on Linux CentOS 6.9)

I have my .tex files in the directory /home/(the path) (this is the absolute path relative to root of the web app) and need to generate the .pdf in the same directory with the same name as the original .tex file.

The entire command I use goes as follows:

latexmk -pdf -jobname=/home/(the path)/filename /home/(the path)/filename.tex

This however, does not work; latexmk starts execution and stops with a message

I can't write on file filename.aux

Instead, if I run a similar command from terminal window with relative and not absolute paths of the files (suppose I'm in the parent directory of the target folder), such as

latexmk -pdf -jobname= target_dir/filename target_dir/filename.tex

then it works as expected. Also, skipping the jobname and using the absolute path to .tex file works fine, but the problem there is that the output goes into the root directory.

I am aware of this question, but still the problem with absolute paths remains.

How is it possible to give the absolute path of the output to latexmk?

  • 1
    The error message is from pdflatex, not latexmk; latexmk passes the -jobname option to pdflatex, and with the default security settings, an absolute path is prohibited. You can use the -output-directory option instead. Better still, since the output directory and the document directory are the same, you can use the -cd option to latexmk: latexmk -cd /home/(the path)/filename.tex. May 10, 2018 at 12:42
  • @JohnCollins: thanks a lot! both -output and -cd did the job.
    – Hayk
    May 10, 2018 at 13:46
  • I'll convert this to an answer. May 10, 2018 at 16:48

1 Answer 1


The error message is from pdflatex, not latexmk. Latexmk passes the -jobname option to pdflatex, but with the default security settings of TeXLive an absolute path is prohibited. The accepted answer in the question that is referred to, Specify -output-directory when using latexmk, is actually out of date, and it is the second answer that you should look at.

There are two simple solutions, the first being preferred for the situation in the question.

  1. Since your output directory is the same as the document directory, you can use the -cd option: latexmk -cd /home/(the path)/filename.tex. This causes latexmk to change directory to the document directory before processing the document.

  2. You can use the -output-directory option instead, for which an absolute path is permitted:

    latexmk -output-directory=/home/(the path) /home/(the path)/filename.tex

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .