The phenomena reported in the question are a consequence of pandoc's use of a temporary directory for the intermediate files (input.tex
and input.pdf
). A new temporary directory is used on each run, with a different name. Then the warning message(s) given by latexmk result from the combination of this and the use of latexmk with an auxdir to preserve information between runs. Since latexmk adjusts to the situation on the current run, correct results are obtained, and the warnings can be safely ignored.
However, the warnings do indicate that latexmk detected a potentially anomalous situation that the user may need to know about. In this case, the workflow can be improved to get more advantages from the use of latexmk, without the messages. (In addition, the messages need to be improved, which I've done for the next release of latexmk, probably v. 4.76.)
Detailed diagnosis
Pandoc puts an input.tex
file generated from the source file in a temporary directory. It compiles it to an input.pdf
file in the same directory, with the use of the --output-directory
option to latexmk (or to pdflatex if that is used instead). It then copies/moves the .pdf file to the final destination, and finally removes the temporary directory. The next time pandoc is used, the temporary directory is different. Between runs of latexmk, information about the state of files is preserved in the input.fdb_latexmk
file mentioned in the warning messages from latexmk; this include information on the input.pdf
file. With the changed name of the temporary directory on the next run, latexmk reports what it sees, since it does not correspond to the situations it usually deals with. It adjusts to the new conditions. The directory part of name of the 'input.tex` file also changes, but that's handled correctly by latexmk's usual method of detecting changes of source files, so it doesn't report that.
Solution 1
Use an output directory by giving pandoc the appropriate option, e.g.,
--pdf-engine-opt=-output-directory=out
or
--pdf-engine-opt=-outdir=out
Then pandoc generates both the intermediate input.tex
and input.pdf
files in the specified directory, but doesn't delete them at the end of the run. This actually works with both latexmk and pdflatex as the pdf engines used by pandoc.
A small advantage of this is that if the .md source file hasn't changed when you rerun pandoc, latexmk no longer does any run of pdflatex, since the input.tex
file hasn't changed in location. The original method always results in at least one run of pdflatex by latexmk.
You could also just use an output directory, without separate use of an aux directory. That is documented in the current pandoc manual.
I tested that this solution does work with at least the current version, 2.16.1 of pandoc.
Solution 2
It is also possible to use pandoc only to generate a (stand-alone) .tex file, and then apply latexmk to that. Under a Unix-like operating system (e.g., Linux, macOS), the following command works, when the source file is trymd.md
pandoc trymd.md -s -o aux/trymd.tex \
&& latexmk -auxdir=aux -outdir=. -emulate-aux-dir -pdf -quiet aux/trymd.tex \
&& rm trymd.fls
(If you use MS-Windows, you will have to use a suitable equivalent, of course.)
Now all the intermediate files are in the aux directory only. They also have the same base name as the .md source file, so applying this method to multiple source files doesn't result in interference between files. (In contrast, leaving all the work to pandoc results in intermediate files with a single base name, input
.)
Solution 3 (proposed)
(I haven't implemented this, at least not yet.) It should be possible to configure latexmk to get pandoc to do a conversion from an .md (or other file) to an intermediate .tex file before it runs pdflatex. Then you could just do latexmk file.md
, without mentioning pandoc except in a latexmk configuration file.
This is a practical example of a more general situation where a .tex file is not written by the user but is generated programmatically from other source files.