SPB Git

spb/wp44_uqo

Public
2.6 KB · 26 lines python
1#!/usr/bin/env python32"""Generate Appendix F (supplementary tables: every generated table not \\input elsewhere in the manuscript) and3Appendix G (figure documentation: file, caption, generating script, source artefacts) from manuscript/tables/TABLES.json and4figures/FIGURES.json. Run after tables/make_tables.py and figures/make_figures.py."""5import json, os, re, glob, sys6R = sys.argv[1] if len(sys.argv) > 1 else os.path.dirname(os.path.dirname(os.path.abspath(__file__)))7M = os.path.join(R, "manuscript")8used = set()9for 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")]:10    used |= set(re.findall(r"\\input\{tables/([A-Za-z0-9_]+)\}", open(f).read()))11tables = json.load(open(f"{M}/tables/TABLES.json"))12rest = [t for t in tables if t["file"].replace(".tex", "") not in used]13esc = lambda s: str(s).replace("_", "\\_").replace("&", "\\&").replace("%", "\\%")14out = ["\\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.", ""]15for t in rest:16    out.append(f"\\input{{tables/{t['file'].replace('.tex','')}}}\n\\clearpage")17open(f"{M}/appendices/appF_supplementary_tables.tex", "w").write("\n".join(out) + "\n")18figs = json.load(open(f"{R}/figures/FIGURES.json"))19g = ["\\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.", "",20     "\\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"]21for f in figs:22    g.append(f"\\texttt{{{esc(f['file'])}.pdf}} & {esc(f['caption'])} & {esc('; '.join(os.path.basename(s) for s in f['sources']))} \\\\")23g += ["\\bottomrule", "\\end{longtable}"]24open(f"{M}/appendices/appG_figure_documentation.tex", "w").write("\n".join(g) + "\n")25print(len(rest), "supplementary tables;", len(figs), "figures documented")26
Files · b5f2466340ff2eae3cf29e0ba6c839fa7c448b0e
Menu

Theme