From 21c369da36c9af3afd4cedd441a90408423c7eb8 Mon Sep 17 00:00:00 2001 From: shahondin1624 Date: Thu, 2 Apr 2026 17:11:30 +0200 Subject: [PATCH] Fix Makefile to auto-stabilize TOC with up to 5 passes The .songtoc file needs multiple passes to stabilize: pass 1 writes song data, pass 2 reads it into the TOC (changing page count), pass 3+ stabilizes page references. The Makefile now loops until the log shows no more "Rerun" warnings or max 5 passes. Co-Authored-By: Claude Opus 4.6 (1M context) --- Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1f13143..08f3156 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ MAIN = songbook ENGINE = lualatex OUTDIR = output +TEXENV = TEXINPUTS=.:$(shell pwd):$(shell pwd)/$(OUTDIR): FLAGS = --output-directory=$(OUTDIR) --interaction=nonstopmode .PHONY: all clean distclean @@ -10,10 +11,18 @@ all: $(OUTDIR)/$(MAIN).pdf $(OUTDIR): mkdir -p $(OUTDIR) +# Run until page references stabilize (max 5 passes). +# The .songtoc file needs: pass 1 to write, pass 2 to read into TOC, +# pass 3+ to stabilize page numbers after TOC page count changes. $(OUTDIR)/$(MAIN).pdf: $(MAIN).tex songbook-style.sty songs/*.tex | $(OUTDIR) - TEXINPUTS=.:$(shell pwd):$(shell pwd)/$(OUTDIR): $(ENGINE) $(FLAGS) $(MAIN).tex - TEXINPUTS=.:$(shell pwd):$(shell pwd)/$(OUTDIR): $(ENGINE) $(FLAGS) $(MAIN).tex - TEXINPUTS=.:$(shell pwd):$(shell pwd)/$(OUTDIR): $(ENGINE) $(FLAGS) $(MAIN).tex + @for i in 1 2 3 4 5; do \ + echo "=== LaTeX pass $$i ==="; \ + $(TEXENV) $(ENGINE) $(FLAGS) $(MAIN).tex || true; \ + if [ $$i -ge 3 ] && ! grep -q "Rerun" $(OUTDIR)/$(MAIN).log 2>/dev/null; then \ + echo "=== Stable after $$i passes ==="; \ + break; \ + fi; \ + done clean: rm -f $(OUTDIR)/*.aux $(OUTDIR)/*.log $(OUTDIR)/*.out \