Sort TOC entries alphabetically including aliases
Add a Python sort step in the Makefile that sorts .songtoc by
the actual title text, stripping \textit{} wrappers so aliases
sort into their correct alphabetical position alongside main
titles.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
3
Makefile
3
Makefile
@@ -18,6 +18,9 @@ $(OUTDIR)/$(MAIN).pdf: $(MAIN).tex songbook-style.sty songs/*.tex | $(OUTDIR)
|
|||||||
@for i in 1 2 3 4 5; do \
|
@for i in 1 2 3 4 5; do \
|
||||||
echo "=== LaTeX pass $$i ==="; \
|
echo "=== LaTeX pass $$i ==="; \
|
||||||
$(TEXENV) $(ENGINE) $(FLAGS) $(MAIN).tex || true; \
|
$(TEXENV) $(ENGINE) $(FLAGS) $(MAIN).tex || true; \
|
||||||
|
if [ -f $(OUTDIR)/$(MAIN).songtoc ]; then \
|
||||||
|
python3 -c "import re;lines=open('$(OUTDIR)/$(MAIN).songtoc').readlines();lines.sort(key=lambda l:re.sub(r'[^a-zäöüß ]','',re.search(r'\{(?:\\\\textit\s*\{)?([^}]+)',l).group(1).lower()) if re.search(r'\{(?:\\\\textit\s*\{)?([^}]+)',l) else '');open('$(OUTDIR)/$(MAIN).songtoc','w').writelines(lines)" ; \
|
||||||
|
fi; \
|
||||||
if [ $$i -ge 3 ] && ! grep -q "Rerun" $(OUTDIR)/$(MAIN).log 2>/dev/null; then \
|
if [ $$i -ge 3 ] && ! grep -q "Rerun" $(OUTDIR)/$(MAIN).log 2>/dev/null; then \
|
||||||
echo "=== Stable after $$i passes ==="; \
|
echo "=== Stable after $$i passes ==="; \
|
||||||
break; \
|
break; \
|
||||||
|
|||||||
Reference in New Issue
Block a user