WordprocessingML has no list element. A list is an ordinary run of paragraphs that each
name a numbering definition and a level in w:numPr. The definitions are in
word/numbering.xml, reached by the main document’s numbering
relationship.
In a paragraph
<w:p>
<w:pPr>
<w:numPr>
<w:ilvl w:val="0"/>
<w:numId w:val="1"/>
</w:numPr>
</w:pPr>
<w:r><w:t>A list item</w:t></w:r>
</w:p>
A paragraph style can carry w:numPr too, so that every paragraph in the
style is numbered; this is how numbered headings work. In that case the level comes from
the numbering definition’s level that names the style in w:pStyle.
The two layers
There are two layers. A w:abstractNum defines the appearance of up to nine
levels. A w:num is an instance of a definition that paragraphs refer to. Several
w:num can share one abstract definition.
<w:numbering xmlns:w="…">
<w:abstractNum w:abstractNumId="0">
<w:multiLevelType w:val="hybridMultilevel"/>
<w:lvl w:ilvl="0">
<w:start w:val="1"/>
<w:numFmt w:val="decimal"/>
<w:lvlText w:val="%1."/>
<w:lvlJc w:val="left"/>
<w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr>
</w:lvl>
<w:lvl w:ilvl="1">
<w:start w:val="1"/>
<w:numFmt w:val="lowerLetter"/>
<w:lvlText w:val="%2."/>
</w:lvl>
</w:abstractNum>
<w:num w:numId="1">
<w:abstractNumId w:val="0"/>
</w:num>
</w:numbering>
A level: w:lvl
| Element | Meaning |
|---|---|
w:start | The first number at this level. |
w:numFmt | The number format. Common values: decimal, decimalZero, lowerLetter, upperLetter, lowerRoman, upperRoman, bullet, none. There are many more for other numbering systems. |
w:lvlText | The label: %1 is level 0’s number, %2 level 1’s and so on, so %1.%2 gives “2.1”. For a bullet, it is the bullet character, often in a symbol font with a private-use code. |
w:lvlJc | Alignment of the label. |
w:pStyle | The paragraph style tied to this level. |
w:suff | What follows the number: tab (the default), space or nothing. |
w:lvlRestart | A one-based level: this level restarts when that level, or any earlier one, is used. Omitted: it restarts whenever the previous level or any earlier one is used. A value above the current level is ignored, and 0 means never restart (17.9.10). The viewer applies it. Word allows 0 to 7 only and ignores it inside the w:lvl of a w:lvlOverride (MS-OI29500 2.1.282); it ignores w:start there as well (2.1.292), which the viewer still reads. For w:numFmt Word ignores the format attribute unless val is custom (2.1.286 b), and a bullet shows the literal lvlText without %1 substitution (2.1.286 a), as the viewer does. |
w:lvlPicBulletId | A picture bullet, by the ID of a w:numPicBullet in the same part (17.9.9, 17.9.20). |
w:isLgl | Show all the level’s numbers as decimals, as in legal numbering. |
w:pPr, w:rPr | Indents for the level, and formatting of the label. |
How numbers are counted
Each level keeps a counter. An item at a level adds one to that level’s counter and
resets the counters of the deeper levels, so a new 1. under a following
2. restarts its sub-items. Word counts per list, which is why continuing a
list only needs the same w:numId; a
w:num sharing an abstract definition continues the same counters unless it
restarts them.
A w:num can change this with w:lvlOverride:
w:startOverride restarts a level from a new number, and a w:lvl
inside it replaces the level’s definition.
Paragraph style lists also use w:styleLink and
w:numStyleLink: an abstract definition can be named by a numbering style, and
others can point to it through that style.
The rules the standard states (ECMA-376 Part 1, 17.9):
w:numId0is never a definition; it removes numbering set at an earlier level of the style hierarchy, typically by direct formatting (17.9.18).w:suffomitted meanstab, and the tab follows the normal tab stop rules (17.9.28).w:multiLevelType(singleLevel,multilevel,hybridMultilevel) is only a hint for a user interface; it never limits which levels a list may use.w:nameis a friendly name that never changes how the list behaves (17.9.12, 17.9.13).w:nsidandw:tmplare a unique identifier and a template code of the abstract definition (17.9.14, 17.9.29).w:styleLinksays that this abstract definition holds the numbering of the named numbering style; a missing style means it does not.w:numStyleLinkmakes an abstract definition a pointer to that style (17.9.27, 17.9.21).w:startOverrideinside aw:lvlOverrideresets that level to the given number; the standard’s example numbers two paragraphs 1 and 2 with onew:numand restarts the third at 1 with a secondw:numover the same abstract definition (17.9.26).
python-docx. It models w:num as a required w:abstractNumId child, any number of
w:lvlOverride children and a required w:numId attribute; w:lvlOverride has a required
w:ilvl and at most one w:startOverride before its w:lvl
(docx/oxml/numbering.py lines 15 to 50). w:numPr is w:ilvl then w:numId
then w:numberingChange and w:ins (lines 53 to 58). In the w:numbering root the
w:num elements come before w:numIdMacAtCleanup (line 82; 17.9.19), and a new instance gets the
lowest unused numId from 1, filling gaps (lines 100 to 109).