[Tex/LaTex] How to specify the absolute path of the output directory with latexmk

centoslatexmkpaths

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?

Best Answer

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