Files
DolanandClaude Opus 5.5 5f626c02ba fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does (#3918)
* fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does

estimatePageNumbers stopped at three things report templates have (#3912):

- A row whose w:tblPrEx repeats the table's own w:tblW, w:tblLayout or
  w:tblInd. Properties that are the same as the table's change nothing,
  so only those that differ still stop the layout.
- A cell's line at multiple spacing at the foot of a row that breaks
  across pages, where it fits only without the space below its text.
  word-split-rows-and-boxes.docx shows Word moves it to the next page,
  unlike in the body: 69 probes, with and without borders and above a
  cell's bottom margin, all now on Word's pages.
- An inline VML text box of its own height whose text is taller than
  it. Word cuts the text off and keeps the box's height (OB1 in the same
  probe), so the box is laid out at its own height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(layout): compare a row's table properties with the table's whatever order their attributes are in

XML gives attributes no order, so a row's w:tblPrEx written with
w:type before w:w is the same as the table's w:tblW written the other
way round. The comparison now sorts each element's attributes first,
as a text frame's are compared, rather than stopping the layout there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(layout): put the probe's text box shape type before whichever box ONLY leaves first

The shape type was added to OB1a's box, so a run with ONLY=OB1b wrote a
box referring to a shape type the document didn't declare. It now goes
before the first box in the document, whichever that is. A full run
writes the same document as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 04:14:34 +00:00

85 KiB

Layout probes

Documents made to find out how Word lays out pages, where its rules aren't written down. docx/layout follows what they showed. Each line of text names its probe, such as Q3a fill 12, so it can be found in a PDF of the document, and each probe starts on a page of its own or is marked off by lines above and below it.

Each probe has the .docx Word opened and the PDF Word saved from it, beside the script that makes it. They were saved from Word 16 for Mac from 2026-09-30 to 2026-10-05 (Save As, PDF, Best for printing). docx writes some of them differently now, so the committed .docx is the one each PDF is of: word-rules and word-tables were made before docx wrote a table style and each cell's width.

Probe What it settles Reader
word-rules P0 to P10: the space before the first paragraph and at the top of a page, the space between paragraphs and contextual spacing, widow and orphan control, the height of headers and footers and of table rows, the line pitch of each font and size, footnotes that don't fit on the page, table rows broken across pages, columns, and paragraphs of only spaces word-rules.py
word-rules2 Q1 to Q7: contextual spacing with each paragraph's share, the space before a section's first paragraph on a new page, keepLines and widow control inside table rows, header rows in columns, sections that start in the next column, footnotes in columns, and columns of different widths word-rules2.py
word-balance W1 to W9: how the columns before a continuous section break are evened out, with column breaks, space after, paragraphs kept together or with the next, tables, lines of two sizes, columns that go on to the next page or start low on it, and a page of exactly 51 lines before a new section word-balance.py
word-balance2 S1 to S7 and C1 to C2: the space after columns and before the next section, which the empty paragraph that ends a section keeps, and column breaks in columns that are evened out word-balance.py
word-keep-together K1 to K5: a paragraph kept together that is taller than a column, which Word lays out down only the first column of each page, from a new page unless it is at the top of one, and what follows it word-balance.py
word-next-column N1 to N6: where a section that starts in the next column starts after columns of other numbers and widths, the space before its first paragraph there, three in a row, and in columns below text, followed by a continuous section break word-next-column.py
word-column-widths R1 to R6: widow control in a paragraph that goes on into a column of another width, where its lines are broken again, and the widths of a table sized to its text that goes on into a wider column word-column-widths.py
word-column-stops CS1 to CS9: where word-watertight-stops' SP10, SP12 and SP13 left it open. A section that starts in the next column of columns of other widths, which Word lays out in the page's columns, goes on in its own on the next page, and its footnotes are in its own columns; a paragraph kept together that is taller than some of the columns of different widths but not others goes in the first it fits in; and two paragraphs kept with the next, or one at the top of a page or of the second column, before one taller than a column go to a new page as one did word-column-stops.py
word-contextual X1 and Y1: contextual spacing next to the empty paragraph that ends a section, whose space after is never on the page itself, and with doNotUseHTMLParagraphAutoSpacing. word-contextual-adding is the second document it writes, with that setting word-contextual.py
word-tables T1 to T13: the widths Word gives table columns from columnWidths, cell widths and table widths, and a word longer than its column (T7) pagelines.py
word-autofit A1 to D1: the widths Word gives the columns of tables whose cells have no widths, which it sizes to their text word-autofit.py
word-long-words L1 to L8: how Word widens a column for a word longer than its cells give it, in tables whose cells all have widths, and what it takes from the other columns. word-long-words-layout.ts prints docx/layout's widths for them word-autofit.py
word-probes U1 to U8: the widths of tables given no widths with merged cells or tables in cells, footnotes continued, footnotes in table rows and in columns, rows with merged cells, a table in a cell or a set height across pages, rows taller than a page, the space before a continuous section's first paragraph with a page break before it, and lines of only spaces before a break word-probes.py
word-nested-tables N1 to N8: a table in a table cell across pages, where word-probes' U4c and U4d left it open: the border below the last of it on the page, which border that is, and the border above the rest on the next, a row of it breaking with borders, its cells' margins above and below, rows that can't break or of a set height, a table in a cell of a table in a cell, and a row whose cells' widow control holds it back word-nested-tables.py
word-header-columns H1 to H8: a table's header rows repeated at the top of each column, in columns evened out before a continuous section break and on a second page, the columns of a table that goes on from the page before evened out, and the line of the empty paragraph that ends a section after a table word-header-columns.py
word-footnotes-in-columns N1 to N12: footnotes in columns, which Word lays out in the columns too, one after the other from the first and evened out, whichever column they are referred to from, with every column ending above them. Below columns that start below text across the page, or are evened out above it, a footnote that wraps in a column, one too long for the room below its reference, and footnotes referred to from text across the page and from columns below it word-footnotes-in-columns.py
word-line-heights H and T1 to T4: the height of lines in each font, size and line spacing, measured over a page, and how a table row breaks across pages: with room for the table's bottom border below it and for the space after a cell's paragraph, rows of an at-least height with less room than their height, and a page that ends between rows word-line-heights.py
word-page-number-formats P: page numbers and page references in each number format at 4, 1234 and 0, L: lists in each format from 1 to 60 and at larger numbers, and C1 to C11: chapter numbers, with each separator, from headings of each level and numbering, before and after a heading on the same page word-page-number-formats.py
word-page-number-formats2 P: page numbers in each format where its letters run out and at 0, and C12 to C15: chapter numbers after a heading that isn't numbered, from one numbered on its own too, from a level with no number in its text, and from a style based on heading 1 word-page-number-formats.py
word-unicode K, E, L, H, N, W, A, P, KR, T, R and G: which characters Word keeps from starting or ending a line of Chinese and Japanese, with no language and in each language, hanging punctuation, kinsoku and wordWrap off, Latin words and numbers after ideographs, breaks after dashes, slashes and zero-width spaces, the space between ideographs and Latin text, punctuation compression, Korean and Thai, right-to-left paragraphs and runs, and the height of lines of East Asian, Thai and Hebrew fonts word-unicode.read.ts
word-unicode2 S, E, H, A, W, T, F and G: every character of Word's lists in Japanese, Chinese, Korean and English, hanging punctuation and the space around Latin text in Japanese, wordWrap off, zero-width spaces, Thai without marks above or below its letters, the font and size of Hebrew and Latin in runs that are right to left and runs that aren't, and the height of lines of 21 East Asian fonts. word-unicode2-layout.ts compares where docx/layout breaks the lines of S and E with where Word does word-unicode2.read.ts
word-no-prompt NP1 to NP4: a document whose page numbers docx/layout writes, without updateFields: whether Word opens it without asking to update the fields, and whether the numbers of its table of contents, its page references in the text and the header, and its numbers of pages in the footers are the pages Word has. Word opened it without asking, and all 43 numbers were Word's word-no-prompt.py
word-seq Q1 to Q14: how Word numbers SEQ fields: \r, \c, \h and \s, the formats of \*, identifiers in other capitals or quotes, bookmarks, hidden text, simple fields, headings and their entries in the table of contents, and SEQ fields in a footnote, the header and footer, and a text box. word-seq-clean is the same document written clean with page numbers, which Word opened without asking to update the fields word-seq.py
word-watertight-text TX1 to TX21: how Word measures text and lines where docx/layout read nothing or guessed: superscript, raised text, italics, small capitals, paragraph borders, automatic spacing, lengths in characters and lines, pictures in the line, two fonts on a line, soft hyphens, tabs past the margin, ligatures, emphasis marks, run borders, letters the width tables didn't have (TX17), fonts that aren't installed, the spaces other than U+0020 (TX19), justified lines and list numbers aligned right. One of the round of probes for the watertight inventory word-watertight.py
word-watertight-tables TB1 to TB11: how Word lays out table formatting docx/layout read nothing of: a table style's spacing and size against Normal's, borders only a table style has, cell borders, space between cells, rows kept with the next, vertical text in a cell, hideMark, a table style's first row, a table sized to its text and indented, hidden rows, and a floating table, the text after which Word puts beside it (TB11), where docx/layout stops. One of the round of probes for the watertight inventory word-watertight.py
word-watertight-pages PG1 to PG8: how Word lays out sections and pages where docx/layout read nothing or guessed: a continuous section with other margins, numbered from 7 or I (PG2), or on landscape pages, a picture floating in the header, line numbers, page borders, the fields Word writes itself, and endnotes that go on to the next page, below the continuation separator (PG8). One of the round of probes for the watertight inventory word-watertight.py
word-watertight-fields FD1 to FD4: what Word writes for page references and numbers of pages docx/layout left blank: a page reference to a bookmark across two pages, with \p ("below", "above", "on page 4"), in formats of their own (\* roman, \* ALPHABETIC, \* Ordinal, \# "00"), numbers of pages in a format of their own, and a page reference to a bookmark in a footnote. Saved after its fields were updated (select all, then F9), so its PDF has Word's results. One of the round of probes for the watertight inventory word-watertight.py
word-page-fields PF1 to PF8: what Word writes for the page references and page numbers word-watertight-fields and word-watertight-pages didn't show: \p across columns and table cells, to pages in roman numerals or with chapter numbers, with capitals and number formats; formats, capitals and pictures of page references, numbers of pages and page numbers; PAGE and SECTION in a footnote, a footnote continued on the next page and an endnote, which Word gives the page and section of the note's reference; and page references to bookmarks in them, which Word gives the reference's page too. Saved after its fields were updated (Yes to updating them when Word opened it, then select all and F9) word-page-fields.py
word-watertight-settings ST1 to ST3: whether a page reference written dirty makes Word ask to update the fields, a table style's spacing with Word's overrideTableStyleFontSizeAndJustification, and a gutter at the top (w:gutterAtTop), which Word takes from the page's height (ST3). One of the round of probes for the watertight inventory word-watertight.py
word-watertight-sections SC1 to SC5: the number of the page after a section numbered afresh that starts in the next column (SC1), or continuously, below text or at the top of a page, and two on one page (SC2); a gutter at the top with a header that goes below the margin (SC3); which separator is above endnotes on the pages after the first (SC4); and where the separator goes when no line of an endnote fits below it (SC5), which is word-watertight-sections2, as a document's endnotes are at its end word-watertight.py
word-watertight-endnotes EN1 to EN3: how many lines of endnotes Word puts below the continuation separator on a page after the first, where SC4 of word-watertight-sections had one more than the page has room for. Word puts as many as fit on the page without the separator, so the last goes past the margin by up to its height, and makes the separator a line tall though it is written 1100 tall (EN2). word-continued-endnotes showed which of two readings of it is Word's. It writes word-watertight-endnotes1 to 3, as a document's endnotes are at its end word-watertight.py
word-continued-endnotes CE1 to CE5: where word-watertight-endnotes left it open. Word leaves the continuation separator's room out of what fits below it, rather than putting a line on while its top is above the margin: a last line taller than the rest goes to the next page (CE1), and lines shorter than the separator fill the page to 259.55 past the margin (CE2). Both separators are a line of the document's text tall, whatever their own formatting: in 20 points (CE3), with space before (CE4), and written exactly 1100 tall or double spaced (CE5). It writes word-continued-endnotes1 to 5 word-continued-endnotes.py
word-watertight-markup MK1 to MK6: whether tracked changes and comments move Word's lines: deleted text, which Word shows in balloons beside the page and breaks the lines without, inserted text, a deleted paragraph mark, which joins its paragraph to the next, a comment, a change of formatting, and a deleted table row, which takes no room. Saved with markup in balloons, beside which Word scales the page down. One of the round of probes for the watertight inventory word-watertight.py
word-tracked-changes MK7 to MK13: what word-watertight-markup didn't show: which formatting a paragraph joined to the next by a deleted mark takes, a deleted mark before a table or at the end of a cell or section, numbered paragraphs, deleted pictures, breaks, tabs and footnote references, moved text, deleted rows and cells, and deleted rows and text in tables sized to their text. It writes word-tracked-view-insdel and word-tracked-view-markup too, which ask Word to hide insertions and deletions, or markup word-tracked-changes.py
word-tracked-tables MK14a to MK14l: what word-tracked-changes left open about deleted rows: their borders, the table's or their own, as the first or last row, and with space between cells, beside the same tables without them, and which rows of a table style's first row, last row and bands the rows around a deleted row are. Saved with markup in balloons, beside which Word scales the page down word-tracked-tables.py
word-character-widths W, S, B and H: how wide Word draws each of the 1,995 characters of the width tables' ranges in Calibri, Cambria, Arial, Times New Roman and Courier New, plain and bold, and which font it draws those its fonts lack in; how wide each space is; whether lines break after each space; and whether a word before one at the end of a line stays on the line. Its .json has each paragraph's characters, for the reader. scripts/generate-font-widths.ts checks the width tables against what the reader reads word-character-widths.py
word-italic-widths W and S in italic and bold italic: how wide Word draws each character of the width tables' ranges in the italics of the five fonts, and which font it draws those their italics lack in, and how wide each space is. word-character-widths.ts writes it with italic, and word-character-widths.json's italic twin, word-italic-widths.json, is beside it. scripts/generate-font-widths.ts checks the italic width tables against what the reader reads word-character-widths.py
word-fonts F1 to F7: when Word kerns text in Aptos, from what size and across runs, whether with the pairs only its GPOS table has, and how far apart its lines are, for measuring fonts from their files word-fonts.py
word-kerning I, K, L, LK, A, P, R and SP: how Word kerns every pair of the characters of Windows-1252 in Calibri, Cambria, Arial and Times New Roman, plain, bold, italic and bold italic, and of printable ASCII in Courier New; which letters it joins with each ligature setting of its Font dialog, how wide they are, and the kerning beside them; Aptos's ligatures and prose with Word's Normal settings; and kerning and ligatures across runs, with character spacing, scaling and small capitals. Each paragraph is a line of a page 22 inches square, and its .json has their text. scripts/generate-font-kerning.ts makes the width tables' kerning from what the reader reads word-kerning.py
word-units U1 to U8: lengths written with units, as docx writes a length given as a string, such as "1in" or "12pt": whether Word reads them in a page's size and margins, a run's size, indents, character spacing, a table's widths and row height and the space between columns, and how it rounds a margin of a fraction of a twip and a size of a fraction of a half-point word-units.py
word-units2 V1 to V6: how Word reads a length with a unit that isn't a whole number of twips or half-points, measured across the page: indents and a margin in each unit, negative ones, sizes, character spacing, a table's column and a row's height word-units.py
word-paragraph-formats B1 to B10, A0 to A8, C1 to C16 and L1 to L3: what TX5 to TX7 of word-watertight-text left open: where the space before and after goes against a border, whether a border below a paragraph's last line needs room at the foot of a page, which paragraphs with the same borders are one box, the room each style of border takes, borders in a cell and with contextual spacing; automatic spacing at the start of a document, in lists, beside tables, in footnotes and headers; indents in characters beside those in twips, and space in lines word-paragraph-formats.py
word-positions H1 to H3, X1 to X9 and Y1: the header and footer of the blank page Word adds before a section on an odd or even page, which page it adds it before a section numbered from its own first number, and where each line is across and down the page with indents, alignment, a list, a right tab, a table, columns and a footnote, against layoutDocument word-positions.py
word-watertight-stops SP1 to SP19: what Word does where docx/layout stops. Of footnotes (SP1 to SP9): in columns, a reference moves to the next column or page with all of its footnote; before a new-page section, the rest of one has pages of its own; a first paragraph kept together or with the next goes with its reference; a row widow control keeps whole moves on, and header rows aren't repeated; one whose least is taller than a page starts on the next. SP18 showed how far Word squeezes justified lines, and SP14, SP15 and SP17 how it sizes a table whose rows give a column different widths, and long words in tables whose cells have widths and in cells merged across columns word-watertight.py
word-watertight-notes FN1 to FN15: footnotes word-watertight-stops left open. Word: a page is left as it was when its reference moves on (FN1); footnotes continue in columns from the top of a page's or a section's column (FN2, FN3); rests have pages of their own before any section (FN4, FN5); text and footnotes go after one that starts on the next page (FN6 to FN8); footnotes break before kept paragraphs and tables (FN9, FN10, FN12), rows as the text's (FN11); go below a table's first row (FN13) and in the first footnote's columns (FN14, FN15) word-watertight.py
word-notes-across-pages NP1 to NP3, NF1, NF2: footnotes word-watertight-notes left open. Word: a table row in a footnote breaks again on each page it goes on to, 38, 50 and 32 lines of 120 (NP1); a line at the top of a later column whose footnote of 55 lines kept together can't go with it goes on the next page, and the footnote on the next two (NP2); a footnote's row moves to the next page whole where a cell would have none of its lines (NP3); the paragraph after a table that ends a note whose paragraphs are Normal is in Normal (NF1, NF2) word-notes-across-pages.py
word-table-widths TW1 to TW23: what word-watertight-stops left open of table widths: rows that give a column different widths in a table with no width of its own, one wider than the widest each row gives each column, and one laid out fixed; a table whose own width is narrower or wider than its cells; a word longer than the page in a table of 100%, given no widths, or given only a table width, and one longer than the table's own width; a long word across columns given different widths, and across columns given no widths that the table is narrowed around, as U1m of word-probes. word-table-widths.py reads where Word drew each row's borders word-table-widths.py
word-table-formats BS, BC, CS, BB, KR, VT, HM, CF and TI: the room each style of border takes, borders that disagree, left and right borders beside text, space between cells with borders and in tables sized to their text, cells' borders where a table breaks across pages, rows kept with the next, text that runs up a cell, hideMark, every part of a table style for some cells with w:tblLook on, off, not given and as w:val, and indented tables word-table-formats.py
word-table-formats2 MG, BS, BC, VT, CF, KR and CS: what word-table-formats left open: cells of a row with different margins, borders at half a point and 3 points, left and right borders beside text, text running up a cell in other sizes, the corners and bands of rows of a table style, a row kept by its second cell, and space between cells of different widths, beside borders and across pages word-table-formats.py
word-merged-cell-margins A, B and C: how the margins of a cell merged down rows size the rows below its first, made with rowSpan, by hand with verticalMerge, and by hand with no margins in the second row. Saved from Word 16 for Mac on 2026-10-15, in docx's default document rather than the probes' Calibri 11 on A4 Read by eye from the page
word-split-rows-and-boxes SR1 to SR3: a table row across pages whose cell's line at 1.15 lines fits at the foot of the page only without the space its multiple spacing adds below its text, which Word moves on to the next page, unlike in the body, with or without borders and above a cell's margin below; OB1: a text box in the line of its own height with more text than fits in it, whose text Word cuts off, the box as tall as it says. Opened in Word 16 for Mac on 2026-11-19 and read with the AppleScript beside it, rather than saved as a PDF Read through AppleScript
word-justify J00 to J18: when Word squeezes a justified line to fit one more word on it: lines of 19, 6 and 2 spaces ending with short, medium and long words, in other fonts, last lines, lines before a line break, distributed and the other justifications, tabs, no-break spaces, spaces at the start of a line, and ideographs word-justify.py
word-justify2 K00 to K12: when Word squeezes a distributed line, and Latin text justified for Thai or with a low kashida, as J01 to J07 and J04 for justified ones, and justified and distributed lines with one space word-justify.py
word-mixed-heights MH1 to MH7: how tall Word makes a line of two fonts, or with a picture, where word-watertight-text's TX8 and TX9 left it open: multiple and at-least spacing over two fonts, the line gap above the text, a picture alone or beside text at 0.8 to 1.5 lines, the font of a picture's run, the descent of each East Asian font, and a picture shorter than its line word-mixed-heights.py
word-run-formatting RF1 to RF8: run formatting, where word-watertight-text's TX1, TX2, TX4, TX15 and TX16 left it open: the size of superscript, subscript and small capitals in each font and at the sizes where Word rounds them, which size's line they take up, raised and lowered text smaller than its line, in another font, with line spacing and written with units, emphasis marks at each size, in each font and of each kind, run borders of each size, space and style, on runs next to each other and across a line, and empty paragraphs whose marks have each word-run-formatting.py
word-run-formatting2 RF9 to RF14: where word-run-formatting left it open: emphasis marks at each line spacing and on lines taller than their fonts' own, whether a line has room for a border's end after its last word, the room borders of 21 other styles take, and borders round raised text, superscript and small capitals. It imports docx/layout's widths, to end RF11's lines where it means to, so run it from a checkout word-run-formatting.py
word-breaks-and-tabs HM1 to HM7, SH1 to SH4, DT and TP: where word-watertight-text's TX10 to TX12 left it open: two paragraphs joined by a hidden mark that are formatted differently, a hidden mark before a table, at the end of a table cell (HM2, which Word leaves as it is) and in a list, hidden paragraphs, specVanish; soft hyphens in justified lines, where the hyphen doesn't fit (SH2), in a table sized to its text and in a word longer than a line; text at a decimal tab stop that isn't a plain number; and tab stops past the margin that are centred or decimal, at the start of a line or with indents. It imports docx/layout's widths, to end SH1's and SH2's lines where it means to, so run it from a checkout word-breaks-and-tabs.py
word-hidden-paragraphs HP1 to HP8: paragraphs whose text and mark are all hidden, where word-breaks-and-tabs' HM3 left it open: whether the next paragraph takes such a paragraph's indent, alignment, line spacing, borders or page break before; one before a table and in table cells; a bookmark in one at the end of a full page, and page references to it; a page break, a picture and a footnote reference in hidden text; one in a list; the space before and after the paragraphs around one, and their contextual spacing; a hidden heading, and text hidden by its character style; and one at the end of the document after a full page word-hidden-paragraphs.py
word-compat CS1 to CS4: whether the compatibility settings Word writes in every document it makes change its lines in compatibility mode 15: Normal's size and alignment against a table style's (overrideTableStyleFontSizeAndJustification), a table style's parts in a header of several rows (differentiateMultirowTableHeaders), kerning, ligatures and figures spaced proportionally (enableOpenTypeFeatures), and a hyphen at the foot of a page (useWord2013TrackBottomHyphenation). Word laid out word-compat-on, with them, and word-compat-off, without, alike, and made all of a header of several rows the first row (CS2) word-compat.py
word-hyphenation HY1 to HY13: automatic hyphenation in compatibility mode 15, written four times: with Word's defaults, with a hyphenation zone of an inch (-zone), with one line in a row ending with a hyphen at most and capitals left whole (-limit), and with those but no hyphenation (-manual): the least room Word hyphenates in, the shortest words and parts it breaks, numbers, text not checked for spelling, justified lines, capitals, soft and hard hyphens, and a table sized to its text. Word kept no zone, hyphenated wherever a part of two letters fit, left words of four letters whole, and sized the table's column to the parts it hyphenated its long word into word-hyphenation.py
word-compat-settings CP1 to CP20: which of the schema's 64 compatibility settings (w:compat) change Word's lines in compatibility mode 15: the same probes without them, with each of eight groups of them on, then with each setting of the two groups that changed lines on alone (word-compat-settings2), and with all but the two that did on together (-together). Only suppressTopSpacing, which shortens the first line of a page at exact or at-least spacing, and useFELayout, which spaces Latin letters apart from Japanese, changed lines. Others moved only the text inside lines of exact height, or left a justified line before a line break not stretched word-compat-settings.py
word-lists LJ1 to LJ11, LO1 to LO9, LR1 to LR4 and LF1 to LF6: list numbers where word-watertight-text's TX21 left them open: where the text after a right-aligned or centred number goes when the number is wider than its indent, in the margin, in a table cell and in a right-to-left paragraph; how Word counts lists made from one definition, and starts them again (w:lvlOverride); levels that start again after a level of their own (w:lvlRestart), legal numbering, and a level used before the one above it; and which formatting a number takes, its paragraph mark's or its text's, and how tall it makes its line word-lists.py
word-floats F1 to F40: pictures and shapes that text wraps around, and floating tables: which lines are beside a drawing and how much room they have, with its distances from the text, for square, tight, through and top and bottom wrapping, on each side; the least room Word puts a word in; drawings placed against the paragraph, the line, the page and its margins, in each alignment and as percentages, turned and with effects; a drawing above its paragraph, or past the bottom of the page; columns, indents, a table below a drawing, and tables that text wraps around. Each drawing is a picture of a size of its own, which the reader finds with pdftocairo -svg word-floats.py
word-grid G1 to G14 and CA to CD: a document grid (w:docGrid). Of lines: how many of its lines a line of each font from 6 to 40 points takes, and where its text is in them, line spacing, space before and after and in lines, w:snapToGrid off, table cells, headers, footers and footnotes, other pitches, pictures, borders, emphasis marks, a continuous section, no pitch, and how many lines go on a page. Of lines and characters, and snapping to characters: ideographs, Latin, kana and half-width katakana, runs and paragraphs off the grid, indents in characters, justified lines and w:adjustRightInd. word-grid2 is the second document it writes, with Normal larger than the default word-grid.py
word-grid3 H1 to H11 and VH1: what word-grid left open: a grid of lines with w:charSpace, a footnote that goes on to the next page and endnotes on a grid, a grid of characters in a header, a footnote, a table cell, columns and text spaced out by its run, space in lines with w:snapToGrid off and in a cell, and a header on pages of text that runs down the page word-grid.py
word-vertical V1 to V13: text that runs down the page (w:textDirection on a section): how many characters go in a line down the page and how many lines across it, without a grid and on grids of lines and of characters, Latin text, a header, a footer and a footnote, indents and space before and after, landscape pages, the other directions, and a continuous section break into it word-vertical.py
word-imported-documents AC1 to AC16 and AS1 to AS9: what Word does with a document a document imports (w:altChunk), in six documents: where an imported .docx's paragraphs go, in the body, a table cell, a header, a note and another imported document, whose styles, defaults, theme, settings, sections, headers, lists and footnotes they take, which of two bookmarks of a name Word keeps, how a style only the imported document has keeps its look, what "keep source formatting" (w:matchSrc) keeps, and plain text. word-imported-bookmarks asks Word to update its fields, to show which bookmarks it kept word-imported-documents.py
word-floats2 G1 to G29: where word-floats left drawings open: drawings that overlap or may not, distances above a drawing that reach the lines before it, an offset with an effect extent, a paragraph's top after another's space after, headings kept with the next beside and before drawings, narrow tables beside drawings, drawings past the bottom in columns and at a page's top, anchored on a later page, in columns evened out, and floating tables placed by each setting word-floats.py
word-floats3 H1 to H15: tables that text flows around, where word-floats2 left them open: the room one keeps the text out of with borders of each width and without, with its cells' margins and an indent, at the left and the right; where one goes after a paragraph's space after and before one with space before, placed against the margins and the page, centred down the margins and across the page; one taller than the paragraph after it, two that may not overlap, and one in columns word-floats.py
word-frames FM1 to FM19: text frames and drop caps: where a frame is against the page, the margins, the column and the paragraph after it, lined up or at a distance, its height with each height rule and none, its width with none, each wrapping, its distances from the text, two paragraphs in one frame, borders round one, drop caps as Word writes them and as docx's options do, frames in the header, one past the bottom of the page, and the text before one going round it word-frames.py
word-vml VM1 to VM15: VML drawings: docx's text boxes in the line, with one and three lines, a height of their own and hidden, and placed on the page with no wrapping; a rectangle and a picture in the line; rectangles with square, top and bottom, tight and one-sided wrapping, and VML's distances from the text; a text box in the header's line, and a rectangle there that text wraps around word-frames.py
word-stops-floats In stops2. FT1 to FT8, FR1 to FR6: tables that text flows around before a table, a section's end or the document's end, with a border on one side, a footnote, kept with the next, past the bottom of the page, in a cell, header or footnote, without an anchor, inline, and two that may not overlap; and text frames before a table or a section's end, with borders, in a cell or footnote, from a style and a paragraph, with notes, and without an anchor or inline stops2/word-stops.py
word-stops-drawings In stops2. DR1 to DR16: pictures text flows around in a cell, footnote or text box, that may not overlap, placed against their character, sized by and placed against the inside and outside margins and lined up inside and outside, beside footnotes, pushed on by the text before them, above footnotes, beside tables, kept with the next, beside an earlier section's text, by their simple position, and beside a narrow room stops2/word-stops.py
word-equations EQ1 to EQ5: equations (m:oMath): how wide Word makes one of letters, digits and operators in a line of text, in each alphabet, and with spaces, brackets, a function and plain and normal text; how tall its line is, and one alone in its paragraph or in m:oMathPara; a superscript, a subscript, a fraction, a root, a sum and brackets round a fraction, in the line and alone; and an equation that goes past the end of its line word-equations.py
word-equations2 EQ6 to EQ9: what word-equations left open: each italic letter, Latin and Greek, small and capital, before an operator, for its width and italic correction; plain letters, digits, binary operators, relations, brackets and punctuation; an italic letter before a digit or a plain letter, unary minus signs, normal text and a plain function's name; and how tall a line with an equation is in Arial, Times New Roman, Courier New and 16 points, alone in its paragraph, with space around it, and two in one m:oMathPara word-equations2.py
word-stops-equations EQ10 to EQ28, EQS1 and EQS2, in stops2/ with word-stops-equation-settings and word-stops-equation-font: equations Word builds up, each in a line of text and displayed: fractions, nested and without a rule, scripts, roots, sums and integrals with their limits, brackets that grow, matrices and cases, accents, bars, functions and limits, braces and a box; normal text and the alphabets; operators next to each other, full stops, italic signs and runs of other sizes and formatting; displayed equations beside text, two in a row and after a list's number; equations too long for their line; Cambria Math's other characters; and the document's maths settings and font word-stops-equations.py
fsplit How a footnote that doesn't fit below its reference goes on to the next page. Laid out in LibreOffice only, so it has no PDF from Word: Word's split of an 8-line footnote is word-rules P7b pagelines.py
stops2/ The stops batch of 2026-10-04 (lay-stops2): one probe document for each stop that needed Word, saved from Word in one session. Those a change has followed are committed, with what Word showed, in stops2/README.md stops2/word-stops.py
word-stops-font-widths In stops2, from lay-stops2's batch: W, S, B and H, as word-character-widths, in Office's 16 other fonts that Word for Mac installs, from Calibri Light to Impact, plain and bold, and word-stops-font-italic-widths in italic and bold italic, with the bold and italic Word makes itself for a font without them. Word draws each character a font has as wide as its own file has it, and the rest in Calibri, Cambria, Arial, Times New Roman, Cambria Math, Segoe UI Symbol or an East Asian font, by the font and character. scripts/generate-font-widths.ts makes their width tables from Word's files, checked against what the reader reads word-character-widths.py
word-stops-font-heights In stops2: FH1 to FH16, how tall a line of each of the 16 fonts is at 11 and 20 points, which is as their files' hhea tables make it, Corbel's and Book Antiqua's shorter than their ascent and descent for Windows make it. word-stops-kerning.ts writes it word-font-heights.py
word-stops-font-kerning In stops2: I, K, L and P, as word-kerning, in Calibri Light, Aptos, Aptos Narrow, Georgia, Trebuchet MS and Verdana, and word-stops-font-kerning2 in the other ten: Word kerns each as its own file does, and text with Normal's ligatures only where the file's GPOS table kerns Latin text. scripts/generate-font-kerning.ts makes their kerning from what the reader reads word-kerning.py
word-stops-office-fonts In stops2: MB, FB, KL and DS, what lay2-fonts left stopping, for the next round of Word's PDFs: the bold Word makes itself at other sizes, kerned, and of an embedded font; whether the font Word draws a character a font lacks in depends on the run's language or East Asian font, and how tall its line is; kerning with other ligature settings in fonts kerned only by their kern table; and Corbel's and Consolas's descents word-stops-office-fonts.py
word-toc-numbers TN1 to TN6, and TN4 in word-toc-numbers-font: how Word starts the entry of a numbered heading in a table of contents with its number, and where it puts the tab stop after the number. By its Normal template, not the document: past the number in Aptos 12 pt by 240 twips, and 240 more a level, on multiples of 240 up to 1920, or on multiples of 200 up to 1600 after the entries at levels 7 to 9. Read from the .docx files Word saved once it had updated their tables, not .word.docx as they aren't laid out to compare list-numbers.spec.ts

Make a probe's .docx

From the root of the repository:

npm run run-ts -- scripts/layout-probes/word-rules2.ts

It writes build/word-probes/word-rules2.docx. fsplit, word-no-prompt and word-seq import docx/layout, so build the package first (npm run build). word-watertight-stops and word-justify measure their lines with docx/layout's width tables, which they import from src. The others import only docx, as the demos do. word-watertight-text, word-watertight-stops, word-tracked-changes, word-hidden-paragraphs, word-grid and word-grid3 replace markers in the XML with what docx can't write, as their INJECTIONS and FIRST_ROW_STYLE say, and word-imported-documents replaces each with w:altChunk and adds the part it imports to the package (importInto). word-fonts also imports the measuring of text from src/text-layout, to print the widths docx/layout measures its probes at when it is given a folder with Aptos's and Calibri's files, such as Word's own:

npm run run-ts -- scripts/layout-probes/word-fonts.ts build/word-probes/word-fonts.docx "/Applications/Microsoft Word.app/Contents/Resources/DFonts"

Lay it out in LibreOffice

To compare with Word, convert the .docx to a PDF in the Docker image CI lays out the layout demos in, which has a pinned LibreOffice and its fonts. Build it from scripts/shape-demos/Dockerfile, then:

docker run --rm --platform linux/amd64 --user "$(id -u):$(id -g)" -v "$PWD/build/word-probes:/work" -w /work \
    <image> soffice -env:UserInstallation=file:///tmp/profile --headless --convert-to pdf word-rules2.docx

LibreOffice keeps its settings in a profile, which has to be somewhere the user running it can write, hence -env:UserInstallation.

LibreOffice's PDF takes the .docx's name, so it replaces a PDF from Word of the same name in that folder. Keep Word's PDFs somewhere else, or rename LibreOffice's.

Read a PDF

Each reader reads where each line is from pdftotext -bbox-layout, from Poppler, which is in the image above and in Homebrew (brew install poppler). For Word's PDF of word-rules2:

pdftotext -bbox-layout scripts/layout-probes/word-rules2.pdf build/word-probes/word-rules2.html
python3 scripts/layout-probes/word-rules2.py build/word-probes/word-rules2.html

word-floats.py reads where Word drew each drawing from pdftocairo -svg, also from Poppler, as well as each line:

pdftotext -bbox-layout scripts/layout-probes/word-floats.pdf build/word-probes/word-floats.html
pdftocairo -svg scripts/layout-probes/word-floats.pdf build/word-probes/word-floats.svg
python3 scripts/layout-probes/word-floats.py build/word-probes/word-floats

word-frames.py reads word-frames and word-vml the same way, with a frame's grey shading and a text box's outline. Word draws a VML shape a little smaller than it is and about 8 twips lower, so a text box's height is read from its outline's path, which is in EMUs, and where it puts the text from the lines around it:

pdftotext -bbox-layout scripts/layout-probes/word-vml.pdf build/word-probes/word-vml.html
pdftocairo -svg scripts/layout-probes/word-vml.pdf build/word-probes/word-vml.svg
python3 scripts/layout-probes/word-frames.py build/word-probes/word-vml

word-equations2.py reads where Word drew each character of an equation from the PDF's own content, where Word draws each at a place of its own, more exactly than pdftotext gives it, and how far each is from the next. Their widths are Cambria Math's own: scripts/generate-cambria-math.ts writes what Word's maths layout needs of the font, from Word's own copy of it, into src/layout/cambria-math.ts. stops2/word-stops-equations.py reads word-stops-equations' PDF the same way: each equation's width in its line of text, and how far its line goes above and below its baseline, pinned by the lines of Calibri around it, and with --json, these by probe, in points:

python3 scripts/layout-probes/word-equations2.py scripts/layout-probes/word-equations2.pdf
python3 scripts/layout-probes/stops2/word-stops-equations.py scripts/layout-probes/stops2/word-stops-equations.pdf
npm run run-ts -- scripts/generate-cambria-math.ts "/Applications/Microsoft Word.app/Contents/Resources/DFonts/Cambria.ttc"

word-positions.py compares the PDF with the layout word-positions.ts writes beside its .docx, from layoutDocument:

npm run run-ts -- scripts/layout-probes/word-positions.ts
pdftotext -bbox-layout scripts/layout-probes/word-positions.pdf build/word-probes/word-positions.html
python3 scripts/layout-probes/word-positions.py build/word-probes/word-positions.html build/word-probes/word-positions.layout.json

word-unicode.read.ts and word-unicode2.read.ts are TypeScript, for Intl.Segmenter, which they check Thai's line breaks with:

pdftotext -bbox-layout scripts/layout-probes/word-unicode2.pdf build/word-probes/word-unicode2.html
npm run run-ts -- scripts/layout-probes/word-unicode2.read.ts build/word-probes/word-unicode2.html

word-kerning.py reads where Word draws each glyph, from pdftocairo's SVG of the PDF, as pdftotext boxes only words, and the small probes from pdftotext -bbox-layout:

pdftocairo -svg scripts/layout-probes/word-kerning.pdf build/word-probes/word-kerning.svg
pdftotext -bbox-layout scripts/layout-probes/word-kerning.pdf build/word-probes/word-kerning.html
python3 scripts/layout-probes/word-kerning.py build/word-probes/word-kerning

word-seq.py reads Word's PDF of word-seq, and the .docx of word-seq-clean docx writes, to check the numbers written in it against Word's. Word updates the fields of word-seq-clean when it saves it as a PDF, so its PDF has Word's numbers, not the ones written. The committed word-seq-clean.docx is the one Word opened; make it again to check docx as it is now:

pdftotext -layout -enc UTF-8 scripts/layout-probes/word-seq.pdf build/word-probes/word-seq.txt
python3 scripts/layout-probes/word-seq.py build/word-probes/word-seq.txt build/word-probes/word-seq-clean.docx

word-page-number-formats.py reads both page number probes, from the text of pdftotext -layout rather than where each line is:

pdftotext -layout -enc UTF-8 scripts/layout-probes/word-page-number-formats.pdf build/word-probes/word-page-number-formats.txt
python3 scripts/layout-probes/word-page-number-formats.py build/word-probes/word-page-number-formats.txt

word-balance.py reads word-balance, word-balance2 and word-keep-together, and word-contextual.py reads both documents word-contextual.ts writes, word-contextual and word-contextual-adding. word-autofit.py reads the borders of the tables of word-autofit and word-long-words too, from each page as SVG:

pdftotext -bbox-layout scripts/layout-probes/word-autofit.pdf build/word-probes/word-autofit.html
pdftocairo -svg -f 1 -l 1 scripts/layout-probes/word-autofit.pdf build/word-probes/word-autofit-1.svg
pdftocairo -svg -f 2 -l 2 scripts/layout-probes/word-autofit.pdf build/word-probes/word-autofit-2.svg
python3 scripts/layout-probes/word-autofit.py build/word-probes/word-autofit

word-watertight.py, word-table-formats.py, word-character-widths.py and word-lists.py take the name of the PDF without its extension, and read its HTML and the text and fonts of pdftohtml -xml:

pdftotext -bbox-layout scripts/layout-probes/word-character-widths.pdf build/word-probes/word-character-widths.html
pdftohtml -xml -i -q -zoom 1 scripts/layout-probes/word-character-widths.pdf build/word-probes/word-character-widths
python3 scripts/layout-probes/word-character-widths.py build/word-probes/word-character-widths

It reads word-italic-widths the same way. With --json, word-character-widths.py prints the widths it read, which scripts/generate-font-widths.ts takes, and where the lines of W break, which word-character-widths-layout.ts compares with where docx/layout breaks them:

python3 scripts/layout-probes/word-character-widths.py build/word-probes/word-italic-widths --json > build/word-probes/word-italic-widths.word.json
npm run run-ts -- scripts/layout-probes/word-character-widths-layout.ts word-italic-widths build/word-probes/word-italic-widths.word.json

word-mixed-heights.py takes the HTML, and prints the height of each probe's lines beside the heights each way Word might work them out gives:

pdftotext -bbox-layout scripts/layout-probes/word-mixed-heights.pdf build/word-probes/word-mixed-heights.html
python3 scripts/layout-probes/word-mixed-heights.py build/word-probes/word-mixed-heights.html

word-run-formatting.py reads both run formatting probes, from the HTML beside the name of the PDF without its extension:

pdftotext -bbox-layout scripts/layout-probes/word-run-formatting.pdf build/word-probes/word-run-formatting.html
python3 scripts/layout-probes/word-run-formatting.py build/word-probes/word-run-formatting

word-page-fields.py prints what each field of word-page-fields shows, and the page of the PDF it is on, from the HTML of pdftotext -bbox-layout:

pdftotext -bbox-layout scripts/layout-probes/word-page-fields.pdf build/word-probes/word-page-fields.html
python3 scripts/layout-probes/word-page-fields.py build/word-probes/word-page-fields.html

word-probes.py takes the name of the PDF without its extension, and reads its HTML and, for U1's tables, its first five pages as SVG:

pdftotext -bbox-layout scripts/layout-probes/word-probes.pdf build/word-probes/word-probes.html
for n in 1 2 3 4 5; do pdftocairo -svg -f $n -l $n scripts/layout-probes/word-probes.pdf build/word-probes/word-probes-$n.svg; done
python3 scripts/layout-probes/word-probes.py build/word-probes/word-probes

word-table-widths.py reads the same, for both pages, and prints the edges of each row of each table as where Word's columns are, from where it drew their borders:

pdftotext -bbox-layout scripts/layout-probes/word-table-widths.pdf build/word-probes/word-table-widths.html
for n in 1 2; do pdftocairo -svg -f $n -l $n scripts/layout-probes/word-table-widths.pdf build/word-probes/word-table-widths-$n.svg; done
python3 scripts/layout-probes/word-table-widths.py build/word-probes/word-table-widths

For word-watertight-text and word-watertight-stops, word-watertight.py reads the pictures on each page from pdfimages -list too, which some of their probes need:

pdftotext -bbox-layout scripts/layout-probes/word-watertight-text.pdf build/word-probes/word-watertight-text.html
pdfimages -list scripts/layout-probes/word-watertight-text.pdf > build/word-probes/word-watertight-text.images.txt
pdftohtml -xml -i -q -zoom 1 scripts/layout-probes/word-watertight-text.pdf build/word-probes/word-watertight-text
python3 scripts/layout-probes/word-watertight.py build/word-probes/word-watertight-text

word-continued-endnotes.py takes the HTML of each of the five PDFs, and prints how many endnote lines are on each page, and where the first and last are:

for n in 1 2 3 4 5; do
    pdftotext -bbox-layout scripts/layout-probes/word-continued-endnotes$n.pdf build/word-probes/word-continued-endnotes$n.html
done
python3 scripts/layout-probes/word-continued-endnotes.py build/word-probes/word-continued-endnotes{1,2,3,4,5}.html

word-justify.py takes the name of the PDF without its extension too, and reads only its HTML:

pdftotext -bbox-layout scripts/layout-probes/word-justify.pdf build/word-probes/word-justify.html
python3 scripts/layout-probes/word-justify.py build/word-probes/word-justify

word-justify.ts also writes word-justify2.docx, the K probes of distributed lines, and the reader reads its PDF the same way, by its name:

pdftotext -bbox-layout scripts/layout-probes/word-justify2.pdf build/word-probes/word-justify2.html
python3 scripts/layout-probes/word-justify.py build/word-probes/word-justify2

word-line-heights.py also measures the height of lines in other PDFs, such as word-rules' P3 and Word's PDFs of the layout demos, and the lines of the rows of tables-across-pages that break across pages: see the top of it.

pagelines.py prints the lines of one page with their top, height, the gap from the line above in twips, and left edge, which shows where each column of a table starts:

python3 scripts/layout-probes/pagelines.py build/word-probes/word-tables.html 1

Word puts text on a grid of 1/300 inch (4.8 twips), so a gap between two lines is only good to about 5 twips. Measure heights over many lines.

A new probe

When Word's rule for something isn't known, write a probe in the shape of word-rules2.ts, with a reader for its PDF, and have it saved from Word as a PDF with the same name as its .docx. Commit the .docx, the PDF and the reader beside the script, and leave out LibreOffice's PDFs, pdftotext's HTML, SVG pages and Word's ~$ lock files.

word-tracked-changes.py reads the three documents word-tracked-changes.ts writes, each from where its text is, and gives each length unscaled, as Word scales the page down beside the balloons of the changes:

for name in word-tracked-changes word-tracked-view-insdel word-tracked-view-markup; do
    pdftotext -bbox-layout scripts/layout-probes/$name.pdf build/word-probes/$name.html
done
python3 scripts/layout-probes/word-tracked-changes.py build/word-probes/word-tracked-{changes,view-insdel,view-markup}.html

word-tracked-tables.py reads where each line of word-tracked-tables is, and the borders between them, from each page as SVG, which Word draws as filled rectangles. It finds how much Word scaled the pages from MK14a's table, whose borders left and right are 9026 twips apart, which is more exact than from where the text starts, as word-tracked-changes.py finds it, as Word moves the page as well as scaling it:

pdftotext -bbox-layout scripts/layout-probes/word-tracked-tables.pdf build/word-probes/word-tracked-tables.html
for n in $(seq 1 12); do
    pdftocairo -svg -f $n -l $n scripts/layout-probes/word-tracked-tables.pdf build/word-probes/word-tracked-tables-$n.svg
done
python3 scripts/layout-probes/word-tracked-tables.py build/word-probes/word-tracked-tables

word-compat.py reads the two documents word-compat.ts writes, and prints what each probe shows in both, side by side:

for name in word-compat-on word-compat-off; do
    pdftotext -bbox-layout scripts/layout-probes/$name.pdf build/word-probes/$name.html
done
python3 scripts/layout-probes/word-compat.py build/word-probes/word-compat-on.html build/word-probes/word-compat-off.html

word-hyphenation.py reads the four documents word-hyphenation.ts writes, and prints how each probe's lines end in each, side by side:

for name in word-hyphenation word-hyphenation-zone word-hyphenation-limit word-hyphenation-manual; do
    pdftotext -bbox-layout scripts/layout-probes/$name.pdf build/word-probes/$name.html
done
cd build/word-probes
python3 ../../scripts/layout-probes/word-hyphenation.py word-hyphenation word-hyphenation-zone word-hyphenation-limit word-hyphenation-manual

word-compat-settings.py reads the documents word-compat-settings.ts writes, and prints, for each document with settings, the probes it lays out unlike the document without them, the first round's against word-compat-settings and the second's against word-compat-settings2:

for pdf in scripts/layout-probes/word-compat-settings*.pdf; do
    pdftotext -bbox-layout $pdf build/word-probes/$(basename $pdf .pdf).html
done
cd build/word-probes
python3 ../../scripts/layout-probes/word-compat-settings.py word-compat-settings $(ls word-compat-settings-*.html | sed 's/.html$//')
python3 ../../scripts/layout-probes/word-compat-settings.py word-compat-settings2 $(ls word-compat-settings2-*.html | sed 's/.html$//')

word-imported-documents.py reads the six documents word-imported-documents.ts writes, and prints each line with its page, where it is and how wide its ten m's are, which says which font and size it is in, and then each probe's lines down from its line above:

for name in documents text ends parts bookmarks styles; do
    pdftotext -bbox-layout scripts/layout-probes/word-imported-$name.pdf build/word-probes/word-imported-$name.html
done
python3 scripts/layout-probes/word-imported-documents.py build/word-probes/word-imported-*.html

Documents saved from Word

Each <demo>.word.docx is a layout demo, as scripts/compare-layout.sh writes it, opened in Word 16 for Mac in Print Layout, with No to updating the fields, and saved as a Word Document once Word had laid out all its pages (2026-10-01, text-and-spacing again on 2026-10-02, once its headings were in Calibri rather than Calibri Light, and table-formatting on 2026-10-02). Word writes a w:lastRenderedPageBreak where each page began, and the number of pages in docProps/app.xml.

scripts/compare-layout.sh copies them into its output directory, and scripts/compare-layout.ts lays each out through the .docx adapter, as patchDocument lays out a template, and compares the page of each heading in its table of contents with the page Word marked it on. Word's PDFs of the same documents showed where Word writes the marks, and where it doesn't (see wordPagesOf in scripts/compare-layout.ts).

columns and long-table-of-contents aren't here: Word writes no mark where a column break starts a page, nor in a table of contents, so their marks don't have all of Word's pages. Word's PDFs of them put all their headings on the pages docx/layout puts them on.

Check every line of a demo

scripts/compare-layout.sh checks the page of each heading. demo-lines.ts checks every line of a demo, and every row of its tables: it lays out the demo's .docx through the .docx adapter, finds each line and row among the lines of Word's PDF of it, and fails when one is on another page from Word's. table-formatting.word.pdf is Word's PDF of table-formatting, saved from Word 16 for Mac on 2026-10-02 from the .docx that table-formatting.word.docx was saved from:

pdftotext -bbox-layout scripts/layout-probes/table-formatting.word.pdf build/word-probes/table-formatting.word.html
npm run run-ts -- scripts/layout-probes/demo-lines.ts scripts/layout-probes/table-formatting.word.docx build/word-probes/table-formatting.word.html

Each line it prints has the gap between where docx/layout puts the top of the line or row and where the top of Word's text is. For table-formatting, all 195 lines and rows are on Word's page, the lines within 0.3 points of Word's, and the rows' gaps are 0.4 to 0.7 points below rows of thin borders and 2.9 to 3.2 below those of thick ones.

On 2026-10-02 it put every line on Word's page in keeping-text-together, sections-headers-and-footers, table-of-contents-page-numbers, tables-lists-and-pictures and text-and-spacing, read from their .word.docx and Word's PDFs of them. In tables-across-pages, docx/layout leaves the header row of survey 9's table alone at the bottom of page 14, as the table's first row, set to a height taller than the room left, goes on to page 15, and Word moves the header row to page 15 with it.

kerning.word.pdf is Word's PDF of kerning, saved from Word 16 for Mac on 2026-10-02 from the .docx the demo writes, with No to updating the fields. Word saved no .docx of it, so the demo's own is laid out:

scripts/compare-layout.sh
pdftotext -bbox-layout scripts/layout-probes/kerning.word.pdf build/word-probes/kerning.word.html
npm run run-ts -- scripts/layout-probes/demo-lines.ts build/layout/kerning.docx build/word-probes/kerning.word.html

All 202 of its lines are on Word's page, broken where Word breaks them, and within 0.9 points of Word's. Measured without kerning, as the layout did before, 103 of the 204 lines it broke the text into were.

guess-lines.ts checks how near docx/layout's best guess comes to Word past where it would stop: it lays out a document saved from Word without a guess and with one (estimatePageNumbersWith({ guess: true })), prints what it guessed at on each page and how many pages each layout and Word's PDF have, and finds each line from the first page it guessed on among Word's lines, as demo-lines.ts does:

pdftotext -bbox-layout scripts/layout-probes/word-watertight-pages.pdf build/word-probes/word-watertight-pages.html
npm run run-ts -- scripts/layout-probes/guess-lines.ts scripts/layout-probes/word-watertight-pages.docx build/word-probes/word-watertight-pages.html

On 2026-10-02, of the documents here that stop without a guess, word-watertight-pages (a date measured as it is written) had 91 of the 91 lines found on Word's page from the guess on, word-mixed-heights (a font not in the width tables measured as Arial) 420 of 420, word-hidden-paragraphs 87 of 87, and word-paragraph-formats 460 of 460, each with as many pages as Word's PDF. Guesses at many characters whose widths aren't known, as in word-character-widths and word-italic-widths, and at page numbers in formats not yet written, as in word-page-number-formats, which Word writes as error messages, end a few pages short of Word's.