From bdea342aab137c32931c5ce90dd671e73dbd49e1 Mon Sep 17 00:00:00 2001 From: Dennis Palatov Date: Sat, 14 Nov 2026 04:43:56 -0800 Subject: [PATCH] [Publisher] PDF: long inline code breaks instead of running off the page (78 clipped words on 40 pages -> 0), split out of #14 The fix landed on #14 on 2026-10-31 (62f7610a). #14 has been held on editorial grounds since, so the deployed PDF has kept the clipped paths for 14 days. This carries only the build part, with no section content: the Lua filter, one make-pdf.sh line, and one PUBLISHER_CONTEXT check line. The three hunks are identical to #14's, so #14 merges over it cleanly. Measured on origin/main 97f638a9 (sections unchanged), CI=true make-md/make-pdf rc 0: - words past page width - 36 pt: 96 -> 1 (p6 plain-text table cell, the 10-31 baseline) - words past the page edge (612 pt, clipped): 78 on 40 pages -> 0 - pages 292 -> 292; Missing character 0; U+FFFD 0 - text layer: after removing whitespace, hyphens and page-number lines, the differences are 99 insertions (1,780 chars, restored path tails) plus 16 layout moves (page numbers caught mid-line, one TOC entry 184 -> 183, table reading order). The one character-level case ("site+4b9c681" -> "site 4b9c681") matches the source, which has no "+". - p15 rendered before and after: the path that ran off the edge now wraps at / and -. Build artifacts are not committed; CI rebuilds and deploys on merge (make-pdf.sh is under the trigger path). Seat: cbp-claude (interactive maintenance pass) Co-Authored-By: Claude Opus 5.5 --- whitepaper/PUBLISHER_CONTEXT.md | 1 + whitepaper/make-pdf.sh | 1 + whitepaper/pdf-breakable-code.lua | 41 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 whitepaper/pdf-breakable-code.lua diff --git a/whitepaper/PUBLISHER_CONTEXT.md b/whitepaper/PUBLISHER_CONTEXT.md index 0f201a83..3877ae6f 100644 --- a/whitepaper/PUBLISHER_CONTEXT.md +++ b/whitepaper/PUBLISHER_CONTEXT.md @@ -171,6 +171,7 @@ After any change: 2. Check for errors in output 3. Verify PDF generates correctly 4. Spot-check web navigation +5. Check PDF geometry, not only glyphs: `pdftotext -bbox` and count words whose xMax exceeds page width − 36 pt (baseline 1 since 2026-10-31, a plain-text table cell on page 6). Long inline code breaks via `pdf-breakable-code.lua`; a rise means a new unbreakable construct. **Never commit changes that break the build.** diff --git a/whitepaper/make-pdf.sh b/whitepaper/make-pdf.sh index 9449ada9..762c09f2 100755 --- a/whitepaper/make-pdf.sh +++ b/whitepaper/make-pdf.sh @@ -149,6 +149,7 @@ pandoc "$TEMP_MD" -o "$PDF_FILE" \ -V toccolor=black \ -V colorlinks=true \ -H pdf-glyphs.tex \ + --lua-filter=pdf-breakable-code.lua \ 2> "$PANDOC_LOG" PANDOC_RC=$? # xelatex drops glyphs its font lacks and only says so on stderr — surface them diff --git a/whitepaper/pdf-breakable-code.lua b/whitepaper/pdf-breakable-code.lua new file mode 100644 index 00000000..cc6dc24b --- /dev/null +++ b/whitepaper/pdf-breakable-code.lua @@ -0,0 +1,41 @@ +-- Long inline code in the PDF gets break points. +-- +-- pandoc sets inline code as \texttt{...}, which TeX never breaks: the mono +-- font has no hyphen character and a path has no spaces. The provenance this +-- paper cites inline (Research/proposals/.md, +-- synchronism-site/explorer/findings/, scripts) therefore ran +-- straight off the page. Measured 2026-10-31: 98 words on 55 of 293 pages +-- ended past the 1in margin, most of them clipped at the physical page edge, +-- so the reader could not see the end of the path. +-- +-- For inline code of MIN_LEN characters or more, this emits the \texttt +-- itself and puts \allowbreak after each / _ - . so a line can end there. Nothing +-- is inserted into the text, so the text layer is unchanged. Short code +-- (1/Ω_m, B_max) is left to pandoc, since a break there would split a symbol. +-- PDF only: make-pdf.sh passes this filter, and the HTML builds do not. + +local MIN_LEN = 20 + +local escapes = { + ['\\'] = '\\textbackslash{}', + ['{'] = '\\{', ['}'] = '\\}', + ['#'] = '\\#', ['$'] = '\\$', ['%'] = '\\%', ['&'] = '\\&', ['_'] = '\\_', + ['~'] = '\\textasciitilde{}', ['^'] = '\\^{}', + ['`'] = '\\textasciigrave{}', ["'"] = '\\textquotesingle{}', + [' '] = '\\ ', +} +local breakafter = { ['/'] = true, ['_'] = true, ['-'] = true, ['.'] = true } + +function Code(el) + if not FORMAT:match('latex') then return nil end + if utf8.len(el.text) == nil or utf8.len(el.text) < MIN_LEN then return nil end + local out = {} + for _, cp in utf8.codes(el.text) do + local ch = utf8.char(cp) + out[#out + 1] = escapes[ch] or ch + -- '-' gets '{}' first so a following '-' cannot form a ligature + if ch == '-' then out[#out + 1] = '{}' end + if breakafter[ch] then out[#out + 1] = '\\allowbreak{}' end + end + return pandoc.RawInline('latex', '\\texttt{' .. table.concat(out) .. '}') +end