spb/traite-evaluation-qc
Public
1#!/usr/bin/env python32"""Écrit un fichier d'étiquettes (\\newlabel) pour tous les chapitres et annexes, afin que \\cref{ch:NN} / \\cref{app:x}3se résolvent lors de la compilation isolée d'un chapitre (tools/compile_chapter.sh). Usage : make_labels.py <sortie.tex>"""4import json, sys, pathlib5ROOT = pathlib.Path(__file__).resolve().parents[1]6t = json.load(open(ROOT / "manuscript/chapters/TITRES.json", encoding="utf-8"))7out = ["\\makeatletter"]8def lab(name, ref, title, anchor, kind):9 out.append("\\@newl@bel{r}{%s}{{%s}{1}{%s}{%s}{}}" % (name, ref, title, anchor))10 out.append("\\@newl@bel{r}{%s@cref}{{[%s][%s][]%s}{[1][1][]1}{}{}{}}" % (name, kind, ref, ref))11for n, title in t.items():12 n = int(n); lab(f"ch:{n:02d}", str(n), title, f"chapter.{n}", "chapter")13 if n < 10: lab(f"ch:{n}", str(n), title, f"chapter.{n}", "chapter")14for L, k in zip("ABCDEF", ["glossaire", "formulaires-inspection", "modeles-rapport", "conventions-calcul", "scripts-classeurs", "solutions"]):15 lab(f"app:{k}", L, "", f"appendix.{L}", "chapter")16out.append("\\makeatother")17pathlib.Path(sys.argv[1]).write_text("\n".join(out) + "\n", encoding="utf-8")18