' + " ".join(big(a, b, c) for a, b, c in tiles) + "
\n") def cite(s: dict | None) -> str: if not s: return "" return (f'{s["stage"]} ({who(s["operator"])}): **{s["outcome"]}**' + (f' ([source]({s["url"]}))' if s.get("url", "").startswith("http") else "")) def person(name: str) -> str: mine = [s for s in independent_ok if s["operator"] == name] more = f", and {len(mine) - 1} more" if len(mine) > 1 else "" return f'**{name}**: {mine[0]["stage"]} — {mine[0]["outcome"]}{more} ([source]({mine[0]["url"]}))' def listing(items) -> str: """Several records in one table cell, one per line.""" items = list(items) return items[0] if len(items) == 1 else "
scripts/build_readme.py from the record of "
f"{as_of}. Do not edit this file by hand.\n")
return "\n".join(L)
BLACKBOARD = {"C": "ℂ", "N": "ℕ", "Q": "ℚ", "R": "ℝ", "Z": "ℤ"}
def mathsafe(text: str) -> str:
"""Adapt the mathematics to GitHub's renderer, which turns TeX into MathML and lets the browser
draw it: < and > as \\lt and \\gt (some are otherwise escaped twice); no \\operatorname, which
GitHub refuses ("macro not allowed"); and an explicit thin space after a function name such as
\\log when a letter, digit or symbol follows, because browsers put no space there; the letters
of \\mathbb as Unicode characters (browsers ignore the variant of a plain letter); and a strut
under a radical over a single letter, which is otherwise drawn too small."""
def fix(m):
seg = m.group(0).replace("<", "\\lt ").replace(">", "\\gt ")
seg = re.sub(r"\\operatorname\{([A-Za-z]+)\}(?=[A-Za-z])", r"\\mathrm{\1}\\,", seg)
seg = re.sub(r"\\operatorname\{([A-Za-z]+)\}", r"\\mathrm{\1}", seg)
seg = re.sub(r"\\mathbb\s*(?:\{([A-Z])\}|([A-Z]))",
lambda b: " " + BLACKBOARD[b.group(1) or b.group(2)], seg)
seg = re.sub(r"\\sqrt\s*(?:\{([a-z])\}|([a-z])(?![A-Za-z]))",
lambda r: "\\sqrt{\\mathstrut " + (r.group(1) or r.group(2)) + "}", seg)
return re.sub(r"\\(log|exp|max|min)(?![A-Za-z])\s*(?=[A-Za-z0-9]|\\(?!bigl|Bigl|left|lvert|,|;|!)[A-Za-z])",
r"\\\1\\,", seg)
text = re.sub(r"```math\n.*?\n```", fix, text, flags=re.S)
inline = lambda m: "$`" + fix(m)[1:-1] + "`$"
return re.sub(r"(? list[str]:
out = []
refused = sorted(set(re.findall(r"\\(?:operatorname|href|require|newcommand|def|unicode|class|style)\b", text)))
if refused:
out.append("TeX macros that GitHub refuses: " + ", ".join(refused))
formulas = re.findall(r"```math\n(.*?)\n```", text, flags=re.S) + re.findall(r"\$`([^`]*)`\$", text)
for f in formulas:
if f.count("{") - f.count("\\{") != f.count("}") - f.count("\\}"):
out.append("unbalanced braces in the formula " + f[:60])
if re.search(r"private:" + "//", text):
out.append("a link into a private place")
for target in sorted(set(re.findall(r"\]\((?!https?://|#)([^)\s]+)\)", text) + re.findall(r'(?:src|href)="(?!https?://|#)([^"]+)"', text))):
if not (ROOT / target.split("#")[0]).exists():
out.append(f"relative link to a missing file: {target}")
anchors = {re.sub(r"[^a-z0-9 -]", "", h.lower()).strip().replace(" ", "-") for h in re.findall(r"(?m)^#{1,4} (.+)$", text)}
for a in sorted(set(re.findall(r"\]\(#([^)]+)\)", text) + re.findall(r'href="#([^"]+)"', text))):
if a not in anchors:
out.append(f"link to a missing section: #{a}")
return out
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("--check", action="store_true")
a = ap.parse_args()
text = mathsafe(build())
bad = problems(text)
if bad:
print("readme: " + "; ".join(bad))
return 1
target = ROOT / "README.md"
if a.check:
ok = target.exists() and target.read_text(encoding="utf-8") == text
print("readme: up to date" if ok else "readme: README.md is not what the data give; run `make readme`")
return 0 if ok else 1
target.write_text(text, encoding="utf-8")
print(f"readme: README.md, {len(text.splitlines())} lines, {len(text) // 1024} KiB")
return 0
if __name__ == "__main__":
sys.exit(main())