Docx writer: display-math continuations take a first-line indent

#11900 · closed · 1 comments

View on GitHub ↗

sghng

**Explain the problem.** The shared preprocessing `fixDisplayMath` (`src/Text/Pandoc/Writers/Shared.hs`) chops a paragraph at its display equations so each centers alone, turning the text after an equation into a new paragraph. With a reference doc whose body style indents paragraph first lines (most manuscript templates do), that new paragraph is indented, even though it continues the sentence running into the equation: mid-sentence text after a display formula gets a first-line indent. **Reproduce** (stock pandoc, with the default reference doc doctored to indent body first lines): ```sh cd $(mktemp -d) pandoc -o ref.docx --print-default-data-file reference.docx mkdir x && cd x && unzip -q ../ref.docx python3 - <<'PY' p = 'word/styles.xml' s = open(p).read() s = s.replace('<w:spacing w:before="180" w:after="180" />', '<w:spacing w:before="0" w:after="0" /><w:ind w:firstLine="720" />') open(p, 'w').write(s) PY zip -q -r ../ref2.docx . && cd .. cat > t.md <<'EOF' Text leading into the display equation $$x = 1$$ and this line continues the same sentence after it. EOF pandoc t.md --reference-doc=ref2.docx -o t.docx unzip -p t.docx word/document.xml | grep -o '<w:ind[^/]*/>' ``` **Received:** no `w:ind` on the continuation paragraph; the style's `firstLine` applies to it (open `t.docx`: the "and this line continues" text is indented like a new paragraph). ![stock: the continuation of the sentence is indented like a new paragraph](https://raw.githubusercontent.com/sghng/pandoc/issue-assets/img/10-indented-v2.png) **Expected:** a run-in continuation of a chopped display-math paragraph suppresses the first-line indent (direct `w:ind w:firstLine="0"`), the way it renders in LaTeX. Text before the first equation and genuinely new paragraphs keep the indent. ![with the fix: the continuation sits flush, as it does in LaTeX](https://raw.githubusercontent.com/sghng/pandoc/issue-assets/img/10-flush-v2.png) **Root cause:** `fixDisplayMath` knows which pieces are continuations, but it discards that knowledge: the pieces come out as plain `Para` blocks, indistinguishable from fresh paragraphs, so the writer applies the normal body style to all of them. **Fix:** `fixDisplayMath` wraps each post-equation text piece in a `math-continuation` div; the docx writer renders those divs transparently and suppresses the indent with a direct zero `w:ind`. (Related inconsistency on stock: display math inside a `mark` span escapes the chop entirely, since the equation is nested past the top-level inline list, so highlighted display math keeps one paragraph with the equation embedded.) > [!NOTE] > > This is 10/13 of issues identified in an attempt to create an APA styled Word target from a Typst source. The issues are ordered logically so that fundamental fixes are applied first. I have fixed all of them locally and will split and upstream the fixes one by one.

Comments

jgm

I'll just add FirstParagraph style in this case (as we already do after block quotes.