This is a follow up on How to configure latexmk to work recursively? (PDF Thumbnails) and latexmk with external references.

Let me first say what I'm trying to achieve. I have a latex project that consists of multiple files, eg. /myproj/main.tex, /myproj/a/a.tex, /myproj/b/b.tex, where main.tex depends on a.tex and a.tex depends on b.tex. And by "depends on", I mean I'm using the package xr to do some cross-referencing between these files via \externaldocument. For example, in a.tex, I would have \externaldocument{../b/b.tex}. My goal is to set up latexmk in such a way that makes it recompile main.tex when b.tex changes.

The first answer of latexmk with external references provides a way to notify latexmk about the dependency relation between the files by printing something to stdout which latexmk will capture. Then, the first answer of How to configure latexmk to work recursively? (PDF Thumbnails) provides a way to make latexmk run recursively. However, as far as I can see, when files are placed in different directories, it fails for two reasons:

  1. Subsequent runs of latexmk (which I invoke via latexmk -cd) don't have access to the same .latexmkr anymore since now, it's in a different directory.
  2. Latexmk records ../b/b.tex as the dependency for main.tex, which does not make sense, since the path ../b/b.tex is relative to a/a.tex rather than to main.tex.

To fix 1., I hacked .latexmkrc so that it copies a version of .latexmkrc everywhere it goes (and clean up later). It's not the best solution, but it works in the sense that the first time I call latexmk, it compiles everything.

However, latexmk still fails to detect changes to b/b.tex, and I think it's due to 2. I've tried to modify latexmk with external references so that absolute path is expanded from the relative path and printed out, but didn't have that much success.

I would really appreciate it if someone could help, either with fixing problem 2 mentioned above or with a completely new solution altogether.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.