Buckets:

glennmatlin's picture
download
raw
2.48 kB
#!/usr/bin/env python3
"""One-shot: slice sections/appendix.tex into per-section files under sections/appendix/.
The main appendix.tex becomes a thin wrapper that \\input{}s each piece in order.
Writes nothing if any destination already exists with different content.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
APPENDIX_PATH = Path("sections/appendix.tex")
APPENDIX_DIR = Path("sections/appendix")
# Slot 0 in the slug list is the prefix (lines before the first \section), saved
# as the leading content of the new wrapper.
SLUGS = [
"01-taxonomy",
"02-attribution-pipeline",
"03-format-bars",
"04-paired-topics",
"05-correctness",
"06-snarks",
"07-extended-benchmarks",
"08-unlearning-setup",
"09-bin-characterization",
"10-corpus",
"11-compute",
]
def main() -> int:
text = APPENDIX_PATH.read_text()
lines = text.splitlines(keepends=True)
section_starts: list[int] = []
for i, ln in enumerate(lines):
if re.match(r"^\\section\{", ln):
section_starts.append(i)
if len(section_starts) != len(SLUGS):
print(
f"Mismatch: appendix has {len(section_starts)} \\section starts but "
f"SLUGS has {len(SLUGS)}",
file=sys.stderr,
)
return 2
APPENDIX_DIR.mkdir(parents=True, exist_ok=True)
prefix = "".join(lines[: section_starts[0]])
slices: list[tuple[Path, str]] = []
for idx, slug in enumerate(SLUGS):
start = section_starts[idx]
end = section_starts[idx + 1] if idx + 1 < len(section_starts) else len(lines)
body = "".join(lines[start:end])
slices.append((APPENDIX_DIR / f"{slug}.tex", body))
for dest, body in slices:
if dest.exists():
existing = dest.read_text()
if existing != body:
print(f"Refused overwrite: {dest}", file=sys.stderr)
return 2
continue
dest.write_text(body)
print(f" wrote {dest} ({body.count(chr(10))} lines)")
new_wrapper_lines = [prefix.rstrip() + "\n", "\n"]
for slug in SLUGS:
new_wrapper_lines.append(f"\\input{{sections/appendix/{slug}}}\n\n")
new_wrapper = "".join(new_wrapper_lines).rstrip() + "\n"
APPENDIX_PATH.write_text(new_wrapper)
print(f" rewrote {APPENDIX_PATH} ({new_wrapper.count(chr(10))} lines)")
return 0
if __name__ == "__main__":
raise SystemExit(main())

Xet Storage Details

Size:
2.48 kB
·
Xet hash:
ac8b43e6c4eb651ba58fe39e47bf6614a18405f82d37c83b78ec6eb24eb6655a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.