Vertically align a run's glyphs below the baseline at a reduced size.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/subscript-text |
|---|---|
| Format | docx |
| Category | text-formatting |
| Spec | ecma-376-5-part-1 § 17.3.2.42 w:vertAlign |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
subscript-element-presentword/document.xml | existThe run carrying the subscript text must have a <w:vertAlign> child inside <w:rPr>. | //w:r[w:t[normalize-space()='Subscript text']]/w:rPr/w:vertAlign | — | — |
subscript-val-is-subscriptword/document.xml | equal = subscriptw:val must equal 'subscript'. | //w:r[w:t[normalize-space()='Subscript text']]/w:rPr/w:vertAlign/@w:val | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
subscript-text-rendered | css_selector/ match-text = Subscript textA DOM node marked subscript (via <sub> or vertical-align: sub) must contain the fixture text. | .docx-wrapper sub, .docx-wrapper [style*='vertical-align: sub'], .docx-wrapper [style*='vertical-align:sub'] | — | pass |
subscript-text-visible | computed_style = ^sub(?:$|\b) style=vertical-alignThe computed vertical-align on the subscript run must be sub (or a sub-offset length). | .docx-wrapper :is(sub, span):not(:has(*)) | — | pass |
scripts/gen_subscript_text.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/subscript-text.docx``.
A minimal document exercising ``w:vertAlign w:val="subscript"``. One
paragraph containing one subscript run.
Satisfies the assertions in ``features/docx/subscript-text.json``.
"""
from __future__ import annotations
from pathlib import Path
from docx import Document
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "subscript-text.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph()
run = paragraph.add_run("Subscript text")
run.font.subscript = True
_OUT.parent.mkdir(parents=True, exist_ok=True)
doc.save(_OUT, reproducible=True)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"$schema": "../manifest.schema.json",
"id": "docx/subscript-text",
"title": "Subscript text",
"format": "docx",
"category": "text-formatting",
"summary": "Vertically align a run's glyphs below the baseline at a reduced size.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.2.42",
"element": "w:vertAlign",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "<w:vertAlign w:val=\"subscript\"/> lowers the run below the baseline and reduces its size. Valid w:val values are 'baseline' (default), 'superscript', 'subscript'. Unlike the toggle properties (w:b, w:i), w:val is required."
},
"fixtures": {
"machine": "docx/subscript-text",
"office": "docx/subscript-text"
},
"generator": {
"python": "scripts/gen_subscript_text.py"
},
"assertions": [
{
"id": "subscript-element-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Subscript text']]/w:rPr/w:vertAlign",
"must": "exist",
"description": "The run carrying the subscript text must have a <w:vertAlign> child inside <w:rPr>."
},
{
"id": "subscript-val-is-subscript",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Subscript text']]/w:rPr/w:vertAlign/@w:val",
"must": "equal",
"value": "subscript",
"description": "w:val must equal 'subscript'."
}
],
"render_assertions": [
{
"id": "subscript-text-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper sub, .docx-wrapper [style*='vertical-align: sub'], .docx-wrapper [style*='vertical-align:sub']",
"must": "match-text",
"value": "Subscript text",
"description": "A DOM node marked subscript (via <sub> or vertical-align: sub) must contain the fixture text."
},
{
"id": "subscript-text-visible",
"kind": "computed_style",
"selector": ".docx-wrapper :is(sub, span):not(:has(*))",
"style_property": "vertical-align",
"value": "^sub(?:$|\\b)",
"description": "The computed vertical-align on the subscript run must be sub (or a sub-offset length)."
}
]
}
