SPB Git

spb/wp27_uqo

Public
2.1 KB · 42 lines python
1import sys, re, datetime2from docx import Document3from docx.shared import Pt4from docx.enum.text import WD_ALIGN_PARAGRAPH5path = sys.argv[1]; doc = Document(path)6paras = doc.paragraphs7norm = lambda p: re.sub(r"\s+", " ", p.text.replace(" ", " ")).strip()8title = "Does the Language of Artificial Intelligence Move Markets?"9# --- title page: everything before the Abstract block is centred10i_abs = next(i for i, p in enumerate(paras) if norm(p) == "Abstract")11for p in paras[:i_abs - 1]:12    p.alignment = WD_ALIGN_PARAGRAPH.CENTER13    if norm(p) == title:14        for r in p.runs: r.font.size = Pt(18); r.font.bold = True15    elif norm(p).startswith("A Semantic Analysis"):16        for r in p.runs: r.font.size = Pt(13)17# --- move References (pandoc appends it at the end) before the appendix, as in the PDF18h1 = [p for p in paras if p.style.name == "Heading 1"]19refs = next(p for p in h1 if norm(p) == "References")20appA = next(p for p in h1 if re.match(r"^A [A-Z]", norm(p)))21body = doc.element.body; kids = list(body)22i_refs, i_app = kids.index(refs._p), kids.index(appA._p)23moved = [k for k in kids[i_refs:] if k.tag.endswith("}sectPr") is False]24for k in moved: appA._p.addprevious(k)25# --- page breaks where the LaTeX source has \newpage26breaks = 027paras[i_abs - 1].paragraph_format.page_break_before = True; breaks += 128for p in h1:29    t = norm(p)30    if t.startswith("1 Introduction") or t == "References" or p is appA:31        p.paragraph_format.page_break_before = True; breaks += 132# --- document properties33cp = doc.core_properties34cp.title = title35cp.subject = "A Semantic Analysis of S&P 500 SEC Filings and the Cross-Section of Stock Returns, 2010–2026"36cp.author = "Manel Kammoun; Djerrycharli Tandjambianda; Simon-Pierre Boucher"37cp.keywords = "textual analysis, sentence embeddings, artificial intelligence, disclosure, cross-section of returns"38cp.comments = "UQO Working Paper No. 17, Version 1.1, October 26, 2026"39cp.created = cp.modified = datetime.datetime(2026, 10, 26, 12, 0)40doc.save(path)41print(f"post-processed: {i_abs-1} title-page paragraphs centred, {len(moved)} reference paragraphs moved before appendix, {breaks} page breaks, properties set")42
Files · d87f8d8bd9679faee8ccd55c141f50c64de63705
Menu

Theme