import sys, re, datetime from docx import Document from docx.shared import Pt from docx.enum.text import WD_ALIGN_PARAGRAPH path = sys.argv[1]; doc = Document(path) paras = doc.paragraphs norm = lambda p: re.sub(r"\s+", " ", p.text.replace(" ", " ")).strip() title = "Does the Language of Artificial Intelligence Move Markets?" # --- title page: everything before the Abstract block is centred i_abs = next(i for i, p in enumerate(paras) if norm(p) == "Abstract") for p in paras[:i_abs - 1]: p.alignment = WD_ALIGN_PARAGRAPH.CENTER if norm(p) == title: for r in p.runs: r.font.size = Pt(18); r.font.bold = True elif norm(p).startswith("A Semantic Analysis"): for r in p.runs: r.font.size = Pt(13) # --- move References (pandoc appends it at the end) before the appendix, as in the PDF h1 = [p for p in paras if p.style.name == "Heading 1"] refs = next(p for p in h1 if norm(p) == "References") appA = next(p for p in h1 if re.match(r"^A [A-Z]", norm(p))) body = doc.element.body; kids = list(body) i_refs, i_app = kids.index(refs._p), kids.index(appA._p) moved = [k for k in kids[i_refs:] if k.tag.endswith("}sectPr") is False] for k in moved: appA._p.addprevious(k) # --- page breaks where the LaTeX source has \newpage breaks = 0 paras[i_abs - 1].paragraph_format.page_break_before = True; breaks += 1 for p in h1: t = norm(p) if t.startswith("1 Introduction") or t == "References" or p is appA: p.paragraph_format.page_break_before = True; breaks += 1 # --- document properties cp = doc.core_properties cp.title = title cp.subject = "A Semantic Analysis of S&P 500 SEC Filings and the Cross-Section of Stock Returns, 2010–2026" cp.author = "Manel Kammoun; Djerrycharli Tandjambianda; Simon-Pierre Boucher" cp.keywords = "textual analysis, sentence embeddings, artificial intelligence, disclosure, cross-section of returns" cp.comments = "UQO Working Paper No. 17, Version 1.1, October 26, 2026" cp.created = cp.modified = datetime.datetime(2026, 10, 26, 12, 0) doc.save(path) print(f"post-processed: {i_abs-1} title-page paragraphs centred, {len(moved)} reference paragraphs moved before appendix, {breaks} page breaks, properties set")