"""Assemble and compile 'Where the Frame Goes on the Board'. Concatenates where_the_frame_goes_board_20261016/src/NN_*.tex in order into one self-contained where_the_frame_goes_on_the_board.tex beside the figures/ folder, then runs pdflatex three times (hidden, nonstop) and reports errors, undefined references and overfull boxes from the log. """ import re, subprocess, sys from pathlib import Path OUT = Path(__file__).resolve().parents[2] / 'where_the_frame_goes_board_20261016' NAME = 'where_the_frame_goes_on_the_board' def main(): parts = sorted((OUT / 'src').glob('[0-9][0-9]_*.tex')) text = ''.join(p.read_text(encoding='utf-8').rstrip('\n') + '\n\n' for p in parts) if '\\end{document}' not in text: text += '\\end{document}\n' (OUT / f'{NAME}.tex').write_bytes(text.encode('utf-8')) for i in range(3): r = subprocess.run(['pdflatex', '-interaction=nonstopmode', '-halt-on-error', f'{NAME}.tex'], cwd=OUT, capture_output=True, text=True, encoding='latin-1', creationflags=0x08000000) log = (OUT / f'{NAME}.log').read_text(encoding='latin-1') errors = [l for l in log.splitlines() if l.startswith('!')] undef = sorted(set(re.findall(r"Reference `([^']+)' on page", log)) | set(re.findall(r"Citation `([^']+)'", log))) overfull = re.findall(r'Overfull \\hbox \(([\d.]+)pt too wide\)[^\n]*lines? (\d+)', log) pages = re.search(r'Output written on .*?\((\d+) pages', log) print('exit', r.returncode, 'pages', pages.group(1) if pages else None) print('errors', errors[:10]) print('undefined', undef) print('overfull >2pt', [(w, l) for w, l in overfull if float(w) > 2]) return 0 if r.returncode == 0 and not errors else 1 if __name__ == '__main__': sys.exit(main())