2

I found out that some simple documents which only needs one compilation will compile twice when I use latexmk -lualatex:

$ latexmk -lualatex Homework_5.tex
Rc files read:
  /home/firestar/.latexmkrc
Latexmk: This is Latexmk, John Collins, 7 Jan. 2023. Version 4.79.
No existing .aux file, so I'll make a simple one, and require run of *latex.
Latexmk: applying rule 'lualatex'...
Rule 'lualatex':  Reasons for rerun
Category 'other':
  Rerun of 'lualatex' forced or previously required

------------
Run number 1 of rule 'lualatex'
------------
------------
Running 'lualatex  -recorder  "Homework_5.tex"'
------------
...
...
Changed files or newly in use/created:
  Homework_5.aux

------------
Run number 2 of rule 'lualatex'
------------
------------
Running 'lualatex  -recorder  "Homework_5.tex"'
------------
Output written on Homework_5.pdf (2 pages, 86722 bytes).
Transcript written on Homework_5.log.
Latexmk: Getting log file 'Homework_5.log'
Latexmk: Examining 'Homework_5.fls'
Latexmk: Examining 'Homework_5.log'
Latexmk: Log file says output to 'Homework_5.pdf'
Latexmk: All targets () are up-to-date

But I still cannot find out why it rerun lualatex and how to stop it rerunning lualatex

I found out that very simple documents compile only once, but I do not know what triggered rerunning compilation.

This is an example which will compile twice: Homework_5.tex

This is my latexmkrc:

sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
2
  • you shouldn't use \usepackage[T1]{fontenc} and the textcomp package in documents with lualatex. Beside this your log tells you why there is a second compilation: "No existing .aux file, so I'll make a simple one, and require run of latex.". For me even simplest documents are rerun if there is no aux. (which means you shouldn't clean up all the time if you want to avoid that). Jan 27, 2023 at 9:55
  • ... it compiles twice because doing tex.stackexchange.com/questions/673076/… routinely is a bad idea Jan 27, 2023 at 10:17

1 Answer 1

3

The reason for the second run is a change in the last line of the .aux file. This last line gives the number of the last page in the document. On the next run of lualatex, the compilation reads the .aux file. The document or packages it loads can use the information about the last page, e.g., to refer to it earlier in the document.

Before the first run of lualatex from a pristine state, latexmk makes a simple .aux file suitable for a trivial one-page document with no cross references, etc:

\relax
\gdef \@abspage@last{1}

Since the document is two pages long, the first compilation results in an .aux file with the 1 replaced by 2. Latexmk has no idea whether or not the document actually uses the last-page information; if the document did use the information, then the first compilation will have used the wrong information. Therefore, after finding that the .aux file was changed by the first run of lualatex, latexmk runs lualatex a second time. There is no further change in the .aux file, so no further runs of lualatex are needed.

In advance of having run lualatex, latexmk doesn't know the number of pages in the document, so it has no way to provide a better initial .aux file. Moreover longer documents typically have various kinds of cross reference. Documents with equations, like the OP's, typically have equations that are numbered. These all need at least the second run of *latex.

Note Suppose you now make a small change in the document that doesn't change the number of pages and doesn't result in other changes to the aux file. Then the next time latexmk is invoked, it will only run lualatex once, if the .aux file hasn't been deleted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .