#!/usr/bin/env python3 """Generate Appendix F (supplementary tables: every generated table not \\input elsewhere in the manuscript) and Appendix G (figure documentation: file, caption, generating script, source artefacts) from manuscript/tables/TABLES.json and figures/FIGURES.json. Run after tables/make_tables.py and figures/make_figures.py.""" import json, os, re, glob, sys R = sys.argv[1] if len(sys.argv) > 1 else os.path.dirname(os.path.dirname(os.path.abspath(__file__))) M = os.path.join(R, "manuscript") used = set() for f in glob.glob(f"{M}/sections/*.tex") + [p for p in glob.glob(f"{M}/appendices/*.tex") if not p.endswith("appF_supplementary_tables.tex")]: used |= set(re.findall(r"\\input\{tables/([A-Za-z0-9_]+)\}", open(f).read())) tables = json.load(open(f"{M}/tables/TABLES.json")) rest = [t for t in tables if t["file"].replace(".tex", "") not in used] esc = lambda s: str(s).replace("_", "\\_").replace("&", "\\&").replace("%", "\\%") out = ["\\section{Supplementary tables}\\label{app:supp-tables}", "This appendix collects the generated tables not shown in the main text. Every table is produced by \\texttt{tables/make\\_tables.py} from the result file(s) named in its first comment line; none is edited by hand.", ""] for t in rest: out.append(f"\\input{{tables/{t['file'].replace('.tex','')}}}\n\\clearpage") open(f"{M}/appendices/appF_supplementary_tables.tex", "w").write("\n".join(out) + "\n") figs = json.load(open(f"{R}/figures/FIGURES.json")) g = ["\\section{Figure documentation}\\label{app:figures}", "All figures are generated by \\texttt{figures/make\\_figures.py} (matplotlib, vector PDF) with the validated palette of \\texttt{figures/style.py}; the table lists, for each figure, its caption and the result artefacts it reads. Colours follow a fixed categorical order; one axis per panel; direct labels for at most four series; the 2022-11-30 reference date is drawn as a dashed line and never as a series.", "", "\\begin{longtable}{p{0.22\\linewidth}p{0.46\\linewidth}p{0.26\\linewidth}}", "\\caption{Figure inventory.}\\label{tab:figure-inventory}\\\\", "\\toprule \\textbf{File} & \\textbf{Caption} & \\textbf{Sources} \\\\ \\midrule \\endfirsthead", "\\toprule \\textbf{File} & \\textbf{Caption} & \\textbf{Sources} \\\\ \\midrule \\endhead"] for f in figs: g.append(f"\\texttt{{{esc(f['file'])}.pdf}} & {esc(f['caption'])} & {esc('; '.join(os.path.basename(s) for s in f['sources']))} \\\\") g += ["\\bottomrule", "\\end{longtable}"] open(f"{M}/appendices/appG_figure_documentation.tex", "w").write("\n".join(g) + "\n") print(len(rest), "supplementary tables;", len(figs), "figures documented")