[Tex/LaTex] Latexmk with makeglossaries and auxdir and outdir

glossarieslatexmk

How can I use glosseries with latexmk if I use outdir and auxdir parameters?
I keep getting the .gls not found…

Here is my latexmk build script:

latexmk -outdir=out -auxdir=out -g -f -bibtex -dvi- -pvc -pdflatex="xelatex -synctex=0 %O %S" -pdf $1

If I remove the auxdir and outdir param, everything works fine. Any help appreciated.

EDIT: Stop up-voting the answer unless you checked it yourself and it works! Because it does not work for me.

Best Answer

The problem is that the makeglossaries script fails when it is called with a filename with a path component, e.g., makeglossaries out/try. This can be worked around by defining the necessary custom dependency as follows

add_cus_dep('glo', 'gls', 0, 'makeglossaries');
sub makeglossaries {
   my ($base_name, $path) = fileparse( $_[0] );
   pushd $path;
   my $return = system "makeglossaries $base_name";
   popd;
   return $return;
}

(Note that pushd and popd are subroutines defined by latexmk that do the same as the corresponding commands in UNIX shells.)