I'm creating a shell script that performs several steps before running lualatex to create a final pdf document. The first step I have in this script is to clear out a "build" directory and start fresh.
BUILD=$DIR/build
if [ ! -d "$BUILD" ]; then
mkdir $BUILD
fi
rm $BUILD/*
lualatex --output-directory build --interaction=batchmode main.tex
For the most part this works fine, however neither the table of contents nor the section headers appear in the output PDF. But If I modify the script to run lualatex twice:
lualatex --output-directory build --interaction=batchmode main.tex
lualatex --output-directory build --interaction=batchmode main.tex
...the PDF is perfect!
Under what circumstances would running the command twice cause everything to work fine?