Docx writer: configurable caption layout (APA label/title shape)

#11902 · open · 0 comments

View on GitHub ↗

sghng

**Enhancement request.** **Explain the need.** APA lays captions out as two blocks above the float: the label ("Table 3" / "Figure 3") bold on its own line, the title italic on the next line (APA 7, tables 8.1 and figures 7.1 notes). A journal manuscript delivered as Word is expected to carry that shape in the file; copy editors fix it by hand otherwise. Our pipeline (Typst sources converted to Word for an APA-journal revise-and-resubmit) needs to produce it directly. **Demonstrate** (stock pandoc; shows what the reference doc cannot reach): ```sh cd $(mktemp -d) cat > t.native <<'EOF' [ Table ( "" , [] , [] ) (Caption Nothing [ Plain [ Str "Model comparison results" ] ]) [ ( AlignDefault , ColWidthDefault ) , ( AlignDefault , ColWidthDefault ) ] (TableHead ( "" , [] , [] ) [ Row ( "" , [] , [] ) [ Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "A" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "B" ] ] ] ] ) [ TableBody ( "" , [] , [] ) 0 [ Row ( "" , [] , [] ) [ Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "1" ] ] , Cell ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) [ Plain [ Str "2" ] ] ] ] ] (TableFoot ( "" , [] , [] ) [] ) ] EOF pandoc t.native -t docx+native_numbering -o t.docx unzip -p t.docx word/document.xml | grep -o 'TableCaption.\{0,240\}' ``` **Received:** one paragraph, label and title inseparable, colon hardcoded: ``` <w:p><w:pPr><w:pStyle w:val="TableCaption" /></w:pPr><w:bookmarkStart ... /> <w:r><w:t xml:space="preserve">Table </w:t></w:r> <w:fldSimple w:instr="SEQ Table \* ARABIC "><w:r><w:t>1</w:t></w:r></w:fldSimple> <w:bookmarkEnd ... /><w:r><w:t xml:space="preserve">: Model comparison results</w:t></w:r></w:p> ``` ![stock: the caption is a single line, label and title inseparable](https://raw.githubusercontent.com/sghng/pandoc/issue-assets/img/12-current-v2.png) **Desired:** an opt-in writer setting that emits the APA shape, with the same bookmark and SEQ numbering: ``` <w:p>...<w:r><w:rPr><w:b /></w:rPr><w:t>Table </w:t></w:r> <w:fldSimple ...><w:r><w:rPr><w:b /></w:rPr><w:t>1</w:t></w:r></w:fldSimple></w:p> <w:p>...<w:r><w:rPr><w:i /></w:rPr><w:t>Model comparison results</w:t></w:r></w:p> ``` ![APA shape: the label bold on its own line, the title italic on the next](https://raw.githubusercontent.com/sghng/pandoc/issue-assets/img/12-apa-v2.png) **Root cause (why nothing outside the writer can do it):** the label is generated by the writer's own numbering state (`addLabel` in `src/Text/Pandoc/Writers/Docx/Table.hs` and the figure caption path in `OpenXML.hs`); it never exists in the AST, so filters cannot restructure it, and the SEQ field run bypasses the run-property environment, so it needs its bold set directly. A paragraph style in the reference doc styles whole paragraphs and cannot split one in two. **Proposal:** a writer option or metadata setting selecting the caption shape (for example `caption-style: apa`), default unchanged. A working implementation exists for tables and figures, including the highlighted-caption interaction (a marked caption's label paragraph takes the mark span, so the pen still covers it). > [!NOTE] > > This is 12/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