0

Is this a bug in latexmk, or perhaps the standalone package, or is it expected behaviour?

If I start with a file containing an error such as too many closing } characters, and compile my latex file using

latexmk --pdf mwe.ltx

then it reports the error correctly. However, when I fix the error, and recompile using the same command, I still get an error such as the following, even though the latex file is correct.

(./mwe.sta)
! Extra }, or forgotten \endgroup.
l.555   }
         %

Here is the MWE; I named it mwe.ltx

\documentclass{article}
\usepackage[subpreambles=true]{standalone}
\begin{document}
test
} %% this is an error, and will correctly cause compilation to fail, but remove it and compilation still fails until you remove the mwe.st
\end{document}

To reproduce the error,

1) compile the file with latexmk --pdf mwe.ltx

2) after it reports an error, fix it by removing the extraneous } character

3) recompile the file with the same latexmk command line.

  • 2
    That has nothing to do with latexmk it also happens with standard pdflatex. The generated .sta file still contains the bad } and needs to be manually removed. It seems to be missing \endstandalonepreambles – daleif Jan 31 '20 at 10:51
  • Ahh, it seems to depend on how you stop latex when it goes into an error. If you press x to stop the compilation, then \endstandalonepreambles is never written to the .sta file and you get problems when the .sta is read next time. I tend to use -halt-on-error with latexmk but that is the same as pressing x thus the writing of the end part is never finished. – daleif Jan 31 '20 at 10:55
  • It seems that the implicit promise of latexmk is that it knows the .ltx file is newer than the .sta file so the .sta should be removed before rerunning. The same for the bibtex files etc. right?

    Simply removing the .sta file is not so easy when make is being called in a sequence of makefiles. I.e., how to know which .sta files to remove and which ones to leave in place?

    I wonder whether it would be possible in the makefile to detect the exit code of latexmk and remove the specific .sta, without removing all of them?

    – Jim Newton Jan 31 '20 at 13:53
  • latexmk never removes files without being asked to. And it probably does not know the .sta extension so I'm not sure latexmk -c will remove the .sta file. You can probably code some custom dependency for .sta files, though not sure if it is worth it. – daleif Jan 31 '20 at 13:55
  • I'm always afraid to use -c or -C for fear that latexmk will think the pdf needs to be regenerated, or that I may need to look at the log file if compilation fails. Such a case of a stranded .sta file may very likely occur in some case where I really need to keep the .log file. right? – Jim Newton Jan 31 '20 at 14:10
  • Unless you're document is very very large, recompiling so get a new log or pdf is not a big deal. – daleif Jan 31 '20 at 14:21
  • recompiling may take 15 minutes sometimes. – Jim Newton Jan 31 '20 at 14:22
  • I tend to trust latexmk -c file.tex a bit more. Have a collegue who wanted to delete some log files and wrote rm *;log note the ;, so he just deleted everything in this folder. He should have used latexmk -c *.tex – daleif Jan 31 '20 at 14:23
  • I've now tried to include the -c in the latexmk command line. But it seriously confuses latexmk's decision to rebuild the pdf files. If I change the .ltx file, make launches latexmk, but latexmk thinks no work is needed. If I remove the -c flag and repeat, everything compiles correctly. – Jim Newton Jan 31 '20 at 14:23
  • Strange document, why? Heavy tikz images? – daleif Jan 31 '20 at 14:24
  • Not understood, you probably need to explain more exactly what you are doing. latexmk -c file.tex will delete auto generated files except .pdf, .bbl etc. Is this one long files, or are files split into say separate files (for each chapter). Then changing chap4 does not touch the master file, and without the aux files to know which docs are a part of the project, latexmk does not know what it should recompile. – daleif Jan 31 '20 at 14:27
  • Yes, lots of lots of stuff. tikz, pgf, qtree, plus plus plus. Its a 300 page dissertation. I don't think huge latex documents are rare in the world. – Jim Newton Jan 31 '20 at 14:28
  • The nice think about latexmk is that it notices which files got read as a result of compiling, and it knows (somehow) what the dependency tree is. If I change something, even a graphics file it magically knows that it needs to recompile. It seems the -c flag interferes with this logic. :-( – Jim Newton Jan 31 '20 at 14:30
  • A runtime of 15min is rare. Why not each tikz image in its own standalone file with the standalone class, compile each separately and include their separeate PDFs. – daleif Jan 31 '20 at 14:43
  • And no I never use standalone as a package, only as a class. – daleif Jan 31 '20 at 14:45
  • I do have a document that does take about 30min to compile everything from scratch, but it has a lot of external graphics that needs to be compiled separately. Using compiling in parallel speeds up this quite a lot. – daleif Jan 31 '20 at 14:47
  • (a) To arrange for latexmk -c or latexmk -C to delete the .sta file, put $clean_ext .= ' sta'; in a latexmkrc file. (b) You can also set $cleanup_includes_generated to 1 (see the latexmk documentation), but that is rather dangerous. (c) If your Makefile calls latexmk on a single source file, surely it is possible to arrange the Makefile so that it deletes just the one top level .sta file. If all else fails, write a little script to call latexmk and do the deletion when needed; then use your script instead of latexmk. – John Collins Feb 02 '20 at 16:52
  • 1
    Try the following: Use $pdflatex = 'pdflatex %O %S|| (echo === Deleting %Y%R.sta ...; rm -v %Y%R.sta; false)'; in a latexmkrc file. That will delete the .sta file if pdflatex gives an error, and report an error back to latexmk. This definition should work on unix-like systems including linux (it was tested on macOS). – John Collins Feb 02 '20 at 17:19
  • The addition to the latexmkrc file seems to work according to my tests. Thanks for the nice suggestion, and for the magical %this-and-that symbols. – Jim Newton Feb 03 '20 at 14:07
  • @JohnCollins can you write an answer? – Dai Bowen May 08 '23 at 21:05

0 Answers0