Clarity pass over the main text (36-item audit), Discussion rewrite and cut, acknowledgements, Souly et al. as ref 62, lettered SI panels, model section moved under Results; plus the untracked curriculum/society/compose/smol configs, runners, figures, stats and tests that the SI already cites. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y64o8FKP7rCuXzC48pxpMm
61 lines
2.4 KiB
Python
61 lines
2.4 KiB
Python
"""Build the student-level figure guide (figure_legends_for_students.md -> .tex -> PDF).
|
|
|
|
The Markdown is the source of truth. Lines of the form ```` become figure includes
|
|
(paths relative to paper/pnas/); ``## `` headings become unnumbered sections; everything else goes
|
|
through build.py's inline() converter, so the same Markdown subset and unicode handling apply.
|
|
|
|
Usage: python paper/pnas/build_lay_legends.py && (cd paper/pnas && tectonic figure_legends_for_students.tex)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(HERE))
|
|
from build import inline # noqa: E402
|
|
|
|
SRC = HERE / "figure_legends_for_students.md"
|
|
OUT = HERE / "figure_legends_for_students.tex"
|
|
|
|
PREAMBLE = r"""\ifdefined\XeTeXversion\else\ifdefined\pdfoutput\pdfoutput=1\fi\fi
|
|
\documentclass[11pt]{article}
|
|
\usepackage[a4paper, margin=1.0in]{geometry}
|
|
\usepackage{graphicx}
|
|
\usepackage{amsmath, amssymb}
|
|
\usepackage[hidelinks]{hyperref}
|
|
\usepackage{microtype}
|
|
\setlength{\parskip}{0.5em}
|
|
\setlength{\parindent}{0pt}
|
|
\begin{document}
|
|
"""
|
|
|
|
|
|
def convert(text: str) -> str:
|
|
out: list[str] = []
|
|
blocks = [b for b in re.split(r"\n\s*\n", text) if b.strip()]
|
|
for block in blocks:
|
|
first = block.strip()
|
|
if first.startswith("# ") and not first.startswith("## "):
|
|
out.append(f"\\begin{{center}}{{\\LARGE\\bfseries {inline(first[2:])}}}\\end{{center}}")
|
|
elif first.startswith("## "):
|
|
out.append(f"\\section*{{{inline(first[3:])}}}")
|
|
elif first == "---":
|
|
out.append("\\medskip\\hrule\\medskip")
|
|
elif re.match(r"^!\[\]\((.+)\)$", first):
|
|
path = re.match(r"^!\[\]\((.+)\)$", first).group(1)
|
|
assert (HERE / path).exists(), f"missing figure {path}"
|
|
out.append(f"\\begin{{center}}\\includegraphics[width=\\textwidth]{{{path}}}\\end{{center}}")
|
|
elif first.startswith("- "):
|
|
items = [re.sub(r"^- ", "", l.strip()) for l in block.split("\n") if l.strip().startswith("- ")]
|
|
out.append("\\begin{itemize}\n" + "\n".join(f"\\item {inline(i)}" for i in items) + "\n\\end{itemize}")
|
|
else:
|
|
out.append(inline(re.sub(r"\s+", " ", block.strip())))
|
|
return PREAMBLE + "\n\n".join(out) + "\n\\end{document}\n"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
OUT.write_text(convert(SRC.read_text()))
|
|
print(f"wrote {OUT}")
|