0

I have this minimal example:

\begin{document}
    \begin{abstract}
        \pdfbookmark[0]{First Chapter}{abs:1}
        ...things...
    \end{abstract}
    \begin{abstract}
        \pdfbookmark[0]{Second Chapter}{abs:2}
        ...things...
    \end{abstract}
\end{document}

Unfortunately, practically randomly, no bookmarks show in the document or they appea rin bad place or on bad level. What is going on, what is the exact meaning of the first parameter?

peterh
  • 331
  • latex never acts randomly. Just as for a standard table of contents within the document you need to run latex at least twice, as documented, and as as the message in the log will inform you. – David Carlisle Nov 15 '23 at 19:13
  • @DavidCarlisle Not long ago, you answered a question (mine) that would be very helpful for this kind of situation. It could write a very prominent message, in capitals, at the very end of Terminal outout (for those who compile using Terminal): YOU MUST COMPILE AGAIN. I recommend that your code, or something like it, be added as a regular part of LaTeX and friends. See https://tex.stackexchange.com/questions/699701/print-to-terminal-after-final-compiler-message/699703?noredirect=1#comment1739072_699703 – rallg Nov 15 '23 at 20:35
  • 1
    @rallg latex is already putting a re-run message on the terminal and log just saying it again, and just for luatex wouldn't really help I think. – David Carlisle Nov 15 '23 at 20:37
  • Yes. But finding that post by google, I am not sure if I had read so much from it. – peterh Dec 16 '23 at 00:03

1 Answers1

0

After a lot of debugging and hunting, I found this sentence in this answer:

You must compile the document twice.

And suddenly I understood, that these files with .log, .out and so on, they represent some type of intermediate state. They must be cleaned up, and then we need to twice execute the latex command.

Hopefully there will be another answer which shares more details, but the clearly phenomenological solution for the problem is something like this. This is what I use to compile all.tex into a working pdf:

rm -vf all.log all.out all.pdf all.aux
pdflatex all.tex
pdflatex all.tex

So, first I delete the intermediary files and then I execute pdflatex twice.

peterh
  • 331
  • If a better answer arrives with more details, that will get the pipe. We need details, why is it so. Honestly, I am not very happy on such surprises. – peterh Nov 15 '23 at 17:51
  • 4
    it is normally not necessary to clean up (and it slows down later compilation as you then always start from the beginning). Apart from this: lots of things in LaTeX need more than one compilation and normally you find a warning in the log if that is needed, for the bookmarks e.g. there is Package rerunfilecheck Warning: File `test-utf8.out' has changed. Rerun to get outlines right. – Ulrike Fischer Nov 15 '23 at 18:05
  • you will usually need more than 2 runs – David Carlisle Nov 15 '23 at 19:14
  • @DavidCarlisle Oh thanks. If there will be some problem even so, I will give a try to a third run. :-) Possible alternative solution would be to execute latex in a loop until the result pdf won't change any more. – peterh Nov 16 '23 at 08:49
  • most systems check ror re-run latex in the log to decide if to re-run. but in practice this is rarely needed for hand written documents as you run multiple times anyway in the course of editing. but any forward \ref takes two runs to resolve cross references, if you have table of contents and have not used i,ii,iii for the front matter the table of contents will appear on the second run but change all the pages so you need another run to regenerate the page numbers, longtable can take an arbitrary number of runs to stabilise (basically the number of overlapping multicolumn cells) ... – David Carlisle Nov 16 '23 at 09:01
  • 1
    Don't remove all .aux files! That's where TOC and cross-reference entries are written! – barbara beeton Dec 15 '23 at 19:52
  • @barbarabeeton Uhh, actually my whole build runs from a gnu make. I can clean up everything with a make clean and then recompile with a make. It is also doing a lot of complex task (like converting .svg to latex and then including into the document, or various pdf post-processing tasks, jpeg optimization before injection and similars. It is also doing that on the maximally possible parallel way). In my workflow, it is absolutely not a problem to clean up something completely and then completely recompile it. – peterh Dec 15 '23 at 23:57
  • But if you remove .aux files, then you have to recompile at least twice, and the .aux files created during the first run have to be present for the second run. Otherwise, the second run will just be another first run. – barbara beeton Dec 16 '23 at 01:41