#!/usr/bin/env python3 """Compile the v3 manuscript and embed its reproducibility supplement. Requires pdflatex on PATH and Python pypdf. Run from the folder containing this script, the .tex, both verification scripts, test harness and execution record: python build_omega_pdf.py LEAN_ARCHIVE.docx JULIA_ARCHIVE.zip The supplied archives are attached unchanged. No Lean or Julia run is performed. """ import argparse from hashlib import sha256 from pathlib import Path import subprocess from tempfile import TemporaryDirectory from pypdf import PdfReader, PdfWriter def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('lean_docx',type=Path) parser.add_argument('julia_zip',type=Path) parser.add_argument('--output',type=Path,default=None) args=parser.parse_args() here=Path(__file__).resolve().parent source=here/'OMEGA_NS_Geometric_Extension.tex' attachments=[source,here/'audit_omega_sources.py',here/'verify_omega_ns.py', here/'test_omega_auditor.py',Path(__file__).resolve(), here/'OMEGA_V3_Verification_Record.txt', args.lean_docx.resolve(),args.julia_zip.resolve()] for path in attachments: if not path.is_file():raise ValueError('Missing supplement file: '+str(path)) if len({p.name for p in attachments})!=len(attachments): raise ValueError('Duplicate attachment filenames') for path,digest in zip(attachments[-2:],[ '275da4ea14130d21aa1b797b643ec78192e195780bfd8352bac699a75b73542e', 'ef8f1eb75b83f1e5763d280374eb8b73d9ab00b8dcb76b1824aee771869cd27a']): if sha256(path.read_bytes()).hexdigest()!=digest: raise ValueError('Source archive identity mismatch: '+path.name) output=args.output.resolve() if args.output else here/'OMEGA_NS_Geometric_Extension_v3.pdf' with TemporaryDirectory(prefix='omega_pdf_') as tmp: command=['pdflatex','-interaction=nonstopmode','-halt-on-error', '-output-directory='+tmp,str(source)] for _ in range(2): result=subprocess.run(command,cwd=here,capture_output=True,text=True) if result.returncode:raise RuntimeError(result.stdout+result.stderr) log=(Path(tmp)/(source.stem+'.log')).read_text() if 'Overfull' in log or 'undefined references' in log or 'Rerun to get cross-references' in log: raise ValueError('LaTeX layout or reference warning; inspect the build') writer=PdfWriter(clone_from=str(Path(tmp)/(source.stem+'.pdf'))) for path in attachments:writer.add_attachment(path.name,path.read_bytes()) writer.add_metadata({'/Title':'OMEGA and Navier–Stokes: Geometric Transport and Exact Invariants (Version 3.0)', '/Author':'Matthew Alan Newman','/Subject':'Revised mathematical manuscript with source and verification supplement'}) with output.open('wb') as stream:writer.write(stream) reader=PdfReader(output) for path in attachments: recovered=reader.attachments[path.name] if len(recovered)!=1 or recovered[0]!=path.read_bytes(): raise ValueError('Embedded supplement bytes differ: '+path.name) print('Created',output.name,'with',len(reader.pages),'pages and',len(attachments),'verified attachments.') print('SHA256',sha256(output.read_bytes()).hexdigest()) if __name__=='__main__':main()