I've made a new version of latexmk, which supports -aux-directory
and -output-directory
. It's v. 4.27a and can be found at
http://www.phys.psu.edu/~collins/latexmk/versions.html
This version will be submitted to CTAN fairly soon, but some feedback would be useful, since I have not tested the new features extensively, especially as I don't have current access to MiKTeX or a more recent one can be found on CTAN as well.
Latexmk now has options -auxdir
, -aux-directory
, -outdir
, and -out-directory
, plus corresponding configuration variables $aux_dir
and $out_dir
. See the documentation for more details. To achieve what the original poster wanted, it's sufficient to put
$aux_dir = 'C:/Users/doncherry/Documents/LaTeX/AUXI_global';
in a latexmkrc file. (I've used forward slashes in directory names since these are acceptable to MS-Windows, and avoid running afoul of quoting conventions.)
I've done some tests with the -output-directory
option, and the only problem that needs sorting out is that the combination of biblatex with bibtex doesn't work because a file needed by bibtex isn't in its usual place. (Biblatex with biber works, as do ordinary uses of bibtex.) If you don't use biblatex, the last issue doesn't affect you.
If you want to use AUCTeX so desperately:
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Latex_outdir" "%`pdflatex --output-directory=/tmp %(mode)%' %t"
TeX-run-TeX nil (latex-mode doctex-mode)
:help "Run pdflatex with output in /tmp")
TeX-command-list)))
The question you linked to in your last comment is still unanswered, and will cause a serious problem with this setup: AUCTeX won't be able to locate your auxiliary files, and thus deduce the next step in the compilation step.
I suggest you use latexmk
for the whole process instead:
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Make" "latexmk -outdir=/tmp %t" TeX-run-TeX nil t
:help "Make pdf output using latexmk.")
TeX-command-list)))
Latexmk is aware of the option outdir
, and will automatically search for the auxiliary files in this directory.
Either way, note the following point (from man latexmk
):
Commonly, the directory specified for output files is a subdirectory of the current working directory. However, if you specify some other directory, e.g., "/tmp/foo" or "../output", be aware that this could cause problems, e.g., with makeindex or bibtex. This is because modern versions of these programs, by default, will refuse to work when they find that they are asked to write to a file in a directory that appears not to be the current working directory or one of its subdirectories. This is part of security measures by the whole TeX system that try to prevent malicious or errant TeX documents from incorrectly messing with a user's files. If for $out_dir or $aux_dir you really do need to specify an absolute pathname (e.g., "/tmp/foo") or a path (e.g., "../output") that includes a higher-level directory, then you need to disable the security measures (and assume any risks). This can be done by temporarily setting the operating system's environment variable openout_any to "a" (as in "all"), to override the default "paranoid" setting.
Another potential problem with this setting is that all your documents will share the same temporary directory, so you will need to make sure they all have different names.
For your cp
step, you can use this line in your .latexmkrc
:
$pdflatex .= ' && cp -v %Z/%D %D';
Note that most of this is untested, please let me know if it doesn't work.
Best Answer
For the following, it is assumed that two folders are needed to host all the generated files: one for the output PDF file (suppose the folder name is PDF) and the other for all the auxiliary files generated by pdflatex (I neamed the folder AuxDirectory). Two approaches are considered: TeXstudio and Latexmk.
TeXstudio
First, TeXstudio needs to understand where to put the output files. SO, two options will be changed:
--aux-directory
for auxiliary files and--output-directory
for PDF output file.Go to
Options > Configure TeXstudio > Commands
. In pdfLaTeX field, add--aux-directory=AuxDirectory --output-directory=PDF before %.tex
.In case of using BibTeX:
In BibTeX field, change it from
bibtex.exe %
tobibtex.exe AuxDirectory/% -include-directory=AuxDirectory
. This is very important step to make the bibliography tool able to find aux files.In case of using Biber:
In Biber field, change it from
biber.exe %
tobibtex.exe AuxDirectory/%
.To make TeXstudio able to locate PDF output file for external pdf readers, in the left tab menu, go to
Build > Additional Search Paths:
and write the folder name you wish to store log file into (I chose AuxDirectory) and the folder name that TeXstudio asks the external PDF viewer to go there to open the file.Now, you are able to make a clean and well organized directory for the LaTeX project.
Latexmk
Latexmk is a powerful automation tool and also smart. More information is given in its documentation. The same previous options (
--aux-directory
and--output-directory
) are used since the same engine/compiler is given.For example, if you want to compile a file named
main.tex
using latexmk you have to run this command (providing that the command current directory is the same as the one hostingmain.tex
)Latexmk is very smart and able to determine the required number of pdfLaTeX and BibTeX runs to properly generate the PDF output file.
Additionally, if you found it very annoying to open the command window each time you want to compile your document, you can create a bash file that opens the command window and runs the previous command by just double-clicking it.
In order to do so, create a file with extension
.bat
in the same working directory ofmain.tex
and edited it to haveAny other suggestions/improvements are highly appreciated.