I am unable to put the -pvc (preview continuously) and -c (clean up) options together for latexmk.

latexmk -pdf -pvc -c file.tex

My observation: After giving -c option, the file gets compiled, (regeneratable) files are deleted and I am back to the command prompt.

Is it possible to achieve this?

-- Mike

  • I'm not quite understanding. -pvc implies continuous compilation, which needs the auxiliary files, which means they can't be deleted. Or are you wanting the auxiliary files to be regenerated whenever you make a change? Why not just leave them around? – Teepeemm Sep 29 '18 at 18:42
  • @Teepeemm This is precisely I want! I would like to regenerate all auxiliary files every time src file.tex is updated. and get deleted upon successful compilation. I need this as I have some restrictions on bandwidth and filesystem in terms of number of files. (Weird, huh?) – Mike V.D.C. Sep 30 '18 at 6:36

TL;DR is: Those options cannot work together. Below is why, after some research.

The latexmk man page documentation has the following:

In its new version, latexmk has a highly
general and efficient solution, ... and a
symptom is that latexmk generates an extra
file (with extension .fdb_latexmk, by default)
that contains the source file information.

Now regarding the -c option:

Clean up (remove) all regeneratable files
generated by latex and bibtex or biber except
dvi, postscript and pdf. These files are a
combination of log files, aux files, latexmk's
database file of source file information, and
those with extensions specified in the
@generated_exts configuration variable. In
addition, files specified by the $clean_ext
configuration variable are removed.

When I ran latexmk -pdf -pvc -c file, after having generated a clean and make via latexmk -pdf -pvc -gg file, the -c option caused all the generated files, including file.fdb_latexmk, to be deleted, save file.pdf and the original `file.tex'.

Now, here's the rub: file.fdb_latexmk contains a fair bit of info on what files were generated, what packages were loaded, and so on, as well as hashes of the files, including the source. One cannot simply touch file.tex and trigger a remake (as one might do with make). One must alter the file so that the hash changes. So if you delete the file with the hashes on all the generated files, then latexmk will enter a state in which it is "done" and it either halts on control-c or returns to the shell prompt.

In short, one cannot delete the file information database and the other generated files, expecting latexmk to work with similar jiggery-pokery as GNU make might. The shell script by @user5325 has a very different expectation of what "being modified" means than latexmk, as touch file.tex will trigger it, making it run latexmk, which then will not always work properly (if at all) and generate undocumented behavior like waiting on conditions that will never happen and necessitating a control-c.


You can write a small shell script:

touch $f
echo -e "$src -- $f\n";

while true
    if [ ${src} -nt ${f} ];
        echo "File modified";
        latexmk -c ${src}
        sleep 5;
    touch ${f};
    sleep 5;    # This is essential.
  • Welcome to TeX.SX! – Bobyandbob Sep 29 '18 at 18:26
  • 1
    If one has to use bash script, why use latexmk in that case? Just put pdflatex, followed by rm -f commands... I believe this can be achieved with the power of latexmk. – Mike V.D.C. Sep 29 '18 at 18:36
  • I may be overlooking things, but I'm not seeing how you accomplish the -pvc portion. – Teepeemm Sep 29 '18 at 18:40
  • @MikeV.D.C. latexmk can do much more than just a single rub of pdflatex - e.g. it will repeatedly compile the document until all the cross references, tables of contents, indexes, etc, are self-consistent, but only do the minimum number of recompiles to reach that state. (That's why it seems pointless to me to delete all the auxiliary files every time you run latexmk - it is just making latexmk work harder for no obvious reason). – alephzero Sep 29 '18 at 21:33
  • @Teepeemm, I suspect that @user5325 is using some *nix system (e.g. ubuntu). So the default previewer (e.g. evince on ubuntu), once opened, automatically update the document on every change. Thus achieving -pvc. – Mike V.D.C. Sep 30 '18 at 6:42

Your Answer

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

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