When I use MiKTeX normally, I call this:

pdflatex --aux-directory="C:\Users\doncherry\Documents\LaTeX\AUXI_global" foo.tex

For latexmk outputting pdf (via pdfLaTeX) with continuous previewing, my attempt is

latexmk -pvc -pdf foo

with a file in the same directory called latexmkrc (see p. 9 of the manual), containing

$pdflatex = 'pdflatex --aux-directory="C:\Users\doncherry\Documents\LaTeX\AUXI_global" %O %S';
$pdf_previewer = 'start "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" %O %S';

This doesn't work, latexmk just runs pdflatex once and the table of contents isn't generated. Latexmk produces the error message:

Latexmk: Errors, so I did not complete making targets
Latexmk: (Pdf)LaTeX failed to generate a log file

How can I use the --aux-directory option through latexmk?

  • Did you try something along the lines of the 'Options to commands' section in the latexmk manual?
    – Joseph Wright
    Commented Oct 4, 2011 at 18:25
  • Yes, at least I think so; the line $pdflatex = 'pdflatex --aux-directory="C:\Users\doncherry\Documents\LaTeX\AUXI_global" %O %S'; was my attempt to apply that syntax.
    – doncherry
    Commented Oct 4, 2011 at 19:49
  • Have you tried using the -jobname option for latexmk? The problem seems to be getting latexmk to find the dependencies etc. and -jobname seems to help in this regard.
    – mforbes
    Commented Oct 6, 2011 at 5:02
  • 2
    Is this too much of a hack? It uses a symlink and copies the completed pdf file (if it exists). The only problem I see (other than the symlink) is that your reader will be reading the version in the aux folder (not the copy). 1) Symlink your global directory to a local directory aux. 2) Add $pdflatex = 'pdflatex %O %S;if [ -f aux/%D ]; then cp aux/%D .; fi' to your latexmkrc file. 3) Run latexmk -pvc -pdf -jobname=aux/<file> <file>. If this is acceptable, I will write it up and add some references and comments (about why the absolute path fails).
    – mforbes
    Commented Oct 6, 2011 at 17:33
  • 1
    Never used Win7. On unix systems, a "symlink" or symbolic link is a way of linking some other directory to your current directory. Sometimes they are called "aliases". It seems there might be some an analogy for windows. Try using mklink as the article suggests to link your global directory to you current directory and see if you can use the -jobname option (the link will be a relative path). I don't think that latexmk supports this out of the box, but perhaps contact the author: [email protected]
    – mforbes
    Commented Oct 7, 2011 at 8:22

4 Answers 4


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


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.

  • 7
    Welcome to tex.sx, John, and thanks for supporting and improving latexmk! (I'm still grateful for your fast response to my [Thomas Titz] bug reports with regard to latexmk 4.22b and MiKTeX.)
    – lockstep
    Commented Oct 11, 2011 at 19:28
  • $aux_dir and $out_dir work with MiKTeX 2.9 on Win7-64bit. Thanks a lot again!
    – doncherry
    Commented Oct 12, 2011 at 18:25

Update: John Collins just pointed me at an unreleased version of latexmk which provides --aux-directory-functionality. He said he should be able to release this soon and he's planning on responding here directly.

Meanwhile, thank you for your responses so far.

I contacted John Collins, the author of latexmk, and he replied as follows:


The problem is that this causes MiKTeX to write all the extra files to the other directory, including the log file. Latexmk needs to read the log file to find out what happened during a run of pdflatex, but it doesn't know that the location of the log file has changed from its usual place. This is the cause of the error message

Latexmk: (Pdf)LaTeX failed to generate a log file

This situation is unfortunately not supported by the current version of latexmk. It would obviously be a good idea to support this, but would need significant changes. It's now on my list of improvements for latexmk.

Unfortunately, I don't see a good workaround.


Well, as doncherry already posted there is no option for this in the current version. Find a rough patch against version 4.26 below, or download the patched script directly.

You need to add the following setting to the config file:

$auxdir = 'C:/Users/doncherry/Documents/LaTeX/AUXI_global/'

Make sure that the directory ends with a /!

This worked fine in my test which actually included TeXLive with the similar -output-directory option as long I symlinked the PDF file. I couldn't test it with MikTeX under Windows yet, but it should work there as well.


--- /usr/local/bin/latexmk  2011-08-12 02:21:46.000000000 +0200
+++ latexmk 2011-10-09 21:46:12.145915149 +0200
@@ -839,6 +839,7 @@
                         # tex, etc.  (If $jobname is non-empty, then
                         # the --jobname=... option is used on tex.)

+$auxdir = '';

 ## default flag settings.
 $recorder = 0;          # Whether to use recorder option on latex/pdflatex
@@ -1281,6 +1282,10 @@
   elsif (/^-jobname=(.*)$/) {
       $jobname = $1;
+  elsif (/^-auxdir="(.*)"$/) {
+      $auxdir = $1;
+      $auxdir .= '/' if ($auxdir !~ /\/$/);
+  }
   elsif (/^-l$/)     { $landscape_mode = 1; }
   elsif (/^-l-$/)    { $landscape_mode = 0; }
   elsif (/^-latex=(.*)$/) {
@@ -1707,7 +1712,7 @@
     # Initialize basic dependency information:

     # For use under error conditions:
-    @default_includes = ($texfile_name, "$root_filename.aux");  
+    @default_includes = ($texfile_name, "$auxdir$root_filename.aux");  

     $fdb_file = "$root_filename.$fdb_ext";

@@ -1748,7 +1753,7 @@
         else {
             # No fdb file, so do inferior job by parse_logB
-            print "$My_name: Examining log file '$root_filename.log' for generated files...\n";
+            print "$My_name: Examining log file '$auxdir$root_filename.log' for generated files...\n";

             # Variables set by parse_logB. Can I remove them
             local %generated_log = ();
@@ -1840,7 +1845,7 @@

     $have_fdb = 0;
-    if ( (! -e $fdb_file) && (! -e "$root_filename.aux") ) {
+    if ( (! -e $fdb_file) && (! -e "$auxdir$root_filename.aux") ) {
         # No aux and no fdb file => set up trivial aux file 
         #    and corresponding fdb_file.  Arrange them to provoke one run 
         #    as minimum, but no more if actual aux file is trivial.
@@ -1860,7 +1865,7 @@
    rdb_recurseA( [keys %possible_primaries],
              sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} }
-        if ( -e "$root_filename.log" ) {
+        if ( -e "$auxdir$root_filename.log" ) {
        rdb_for_some( [keys %possible_primaries], \&rdb_set_latex_deps );
@@ -2170,7 +2175,7 @@
     # 2. Write a corresponding fdb file
     # 3. Provoke a run of (pdf)latex (actually of all primaries). 

-    local $aux_file = "$root_filename.aux";
+    local $aux_file = "$auxdir$root_filename.aux";
     open( aux_file, '>', $aux_file )
         or die "Cannot write file '$aux_file'\n";
     print aux_file "\\relax \n";
@@ -3150,7 +3155,7 @@
     $bad_reference = 0;
     $bad_citation = 0;

-    my $log_name = "$root_filename.log";
+    my $log_name = "$auxdir$root_filename.log";
     my $log_file = new FileHandle;
     if ( ! open( $log_file, "<$log_name" ) ) {
         return 0;
@@ -4204,7 +4209,7 @@
     # $reference_changed, $bad_reference $bad_citation

-    my $fls_file = "$root_filename.fls";
+    my $fls_file = "$auxdir$root_filename.fls";
     if ($recorder && test_gen_file($fls_file) ) {
         parse_fls( $fls_file, \%source_fls, \%generated_fls );
         foreach (keys %source_fls) {
@@ -5573,7 +5578,7 @@
     if (-e $$Pdest) { $missing_dvi_pdf = '';}

     ######### Analyze results of run:
-    if ( ! -e "$root_filename.log" ) {
+    if ( ! -e "$auxdir$root_filename.log" ) {
         $failure = 1;
         $$Plast_result = 2;
         $$Plast_message = $failure_msg = "(Pdf)LaTeX failed to generate a log file";
  • I looked into the Win7 symlink info @mforbes provided. Is it correct that I would need to establish the symlink first for each directory (or pdf file?) that I'm using before I can use latexmk? That would kill the entire thing again; I'm looking for a solution that's automatic to the point that I just need to enter the latexmk call.
    – doncherry
    Commented Oct 10, 2011 at 15:31
  • @doncherry: No, the symlink was only needed for the output file (PDF) for TeXLive which puts ALL files included the PDF in another directory when -output-directory option is used. With MikTeX's --aux-directory it should work without any symlinks. Commented Oct 10, 2011 at 15:40

As the other authors have already noted, latexmk currently doesn't support the --aux-directory flag.

Since I also find it quite annoying to have all the aux and what not files flying around in the folder of the latex file I helped myself with the latexmk option -jobname=.

For this a subfolder needs to exist (e.g. the folder "build"). With this you can run the following command:

latexmk -pvc -pdf -jobfile=build/foo foo

This will put all files, that latexmkgenerated into that subfolder. This has three downsides:

  1. The folder "build" needs to be there.
  2. The resulting PDF is also in that subfolder.
  3. You have to type the filename twice.

To overcome the last point I'm using this bash function:

function latexme() {
  jobname=`echo $@|sed 's/\.tex$//g'`;
  latexmk -pvc -pdf -jobname=build/$jobname "$@";

With this I only need to call this:

latexme foo.tex

Since this uses Bash I'm not sure, how to do this with Windows. But at least you can put all the generated files into another folder.

You must log in to answer this question.

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