I have a problem with latexmk on my Mac. I'm using emacs as my latex editor, and have configured it to use latexmk. I have specified an output directory, but for synctex to work I need the pdf and .synctex file in the working directory.

On my Windows computer this works perfectly fine with the following lines in my .latexmkrc file:

$out_dir = 'build';
$pdflatex = 'cmd /c lualatex -interaction=nonstopmode -synctex=1 %O %S && copy %D %R.pdf && copy %Z%B.synctex.gz';

If however, I try to use the same line on my Mac, only the pdf is copied, the .synctex file stays untouched. I cannot figure out why it does not work. I have not yet tested it on Linux to see if it works there.

This is the line I use on the Mac:

$out_dir = 'build';
$pdflatex = 'lualatex -interaction=nonstopmode -synctex=1 %O %S;cp %D %R.pdf;cp %Z%B.synctex.gz';

According to latexmks manual the syntax and placeholders should be correct, and as I said it does work on Windows. I tried things like adressing the 'build' directory directly instead of using the placeholder %Z, but it didn't do the trick.

I hope that someone can help me with that problem, thanks in advance ;-)

  • Windows copy should take a single argument as 'copy the argument to the current working directory'. Unix (including OS X) will not take a single argument for cp. You'll need to provide it a destination directory, either as an absolute or relative path. If %Z is one directory below your real destination, you should be able to use %Z/.., as in cp %Z%B.synctex.gz %Z/.. -- you might get away with cp %Z%B.synctex.gz ., too. – Mike Renfro Mar 1 '16 at 12:48
  • it works perfectly now, thanks a lot for your answer. :D – Florian Mar 1 '16 at 12:56
up vote 4 down vote accepted

(Copied from comment, so the question can later be marked as answered)

Windows copy should take a single argument as 'copy the argument to the current working directory'. Unix (including OS X) will not take a single argument for cp. You'll need to provide it a destination directory, either as an absolute or relative path. If %Z is one directory below your real destination, you should be able to use %Z/.., as in cp %Z%B.synctex.gz %Z/.. -- you might get away with cp %Z%B.synctex.gz ., too.

This sounds like the ideal use-case for ltx2any instead of latexmk.

  • it automatically uses a build directory
  • automatically copies back the pdf file
  • with -synctex it copies back the synctex file to your working directory
  • Thanks, I'll have a look at this. Copying works fine with the answer above, but my latexmk setup somehow does not always compile the appropriate number of times so maybe ltx2any works better. – Florian Jan 13 at 0:25
  • @Florian My personal impression: ltx2any is pretty good with the determination of required runs - with one limitation: it always compiles at least once. – samcarter Jan 13 at 13:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.