quartifyr_styling (the Python engine bundled at
inst/python/) is code-first generation of the docx
reference-doc used when rendering a quartifyr shell with
Quarto, the abbreviations YAML → abbreviations.tex bridge
consumed by quarto-plus, and headless Word
field/cross-reference post-processing via LibreOffice. Called from R via
a pyro bridge (the styling_*() functions
below), or standalone via the quartifyr-styling CLI:
uv venv .venv --python 3.12 # from a checkout of the repo
source .venv/bin/activate
uv pip install -e '.[dev]'What a style YAML can do
Every option below is a YAML diff from the default preset – fonts,
color, all-caps headings, shaded/padded code blocks, banded tables, all
changed together here to show the range in one comparison. Both are the
same examples/demo-report/report.qmd content,
rendered through the same pipeline, differing only in which
reference-doc was built from which style YAML:

default.yaml, untouched

a ~15-line override
fonts:
body: "Calibri"
heading: "Calibri"
monospace: "Consolas"
colors:
heading: "#0054AD"
title: "#0054AD"
table_header_fill: "#CFE2FF"
rule: "#0054AD"
heading:
all_caps: true
code:
background_color: "#FFF3CD"
padding_pt: 4
table:
banding: true
quartifyr::styling_build_reference_docx(
style = "inst/python/styles/default.yaml",
override = "acme-branding.yaml",
out = "acme-reference.docx"
)See “Style YAML reference” below for every option this can touch, and “Pulling and editing a project’s own style YAML” for a lower-friction way to build an override like the one above than hand-writing it from scratch.
Style YAML reference
Every top-level section below is a dataclass in
inst/python/quartifyr_styling/schema.py, validated against
inst/python/styles/schema.json (point an editor at it via
# yaml-language-server: $schema=... for autocomplete).
override YAMLs (build‘s
--override, most styling_*() functions’
override argument) only need the keys that differ –
deep-merged onto style at load time, not a second full
copy.
fonts
| Key | Controls | Default |
|---|---|---|
body |
Body text font family | "Times New Roman" |
heading |
Title/subtitle/heading font family | "Times New Roman" |
monospace |
Code block/inline code font family | "Courier New" |
sizes.body |
Body text size (pt) | 11 |
sizes.title |
Title page title size (pt) | 26 |
sizes.subtitle |
Title page subtitle size (pt) | 16 |
sizes.heading.1-6
|
Per-level heading size (pt) – a level deeper than any key here falls back to the smallest defined | 16, 14, 12, 11, 11, 11 |
sizes.caption |
Figure/table caption size (pt) | 10 |
sizes.footnote |
Footer/footnote text size (pt) | 9 |
sizes.toc |
Table of contents entry size (pt) | 11 |
colors
Every value is a "#RRGGBB" hex color.
| Key | Controls | Default |
|---|---|---|
text |
Body text | #000000 |
heading |
Heading text | #000000 |
title |
Title/subtitle text | #000000 |
caption |
Figure/table caption text | #000000 |
table_header_fill |
Table header row background | #D9D9D9 |
table_border |
Table border lines | #000000 |
rule |
Rule under the title (if shown) | #000000 |
page
| Key | Controls | Default |
|---|---|---|
size |
"letter" or "a4"
|
"letter" |
margins_in.top/bottom/left/right
|
Page margins (inches) |
1 each |
paragraph
| Key | Controls | Default |
|---|---|---|
line_spacing |
Body text line spacing multiplier | 1.15 |
space_after_pt |
Space after a body paragraph (pt) | 8 |
alignment |
"left"/"justify"/"center"/"right"
|
"left" |
heading
| Key | Controls | Default |
|---|---|---|
bold |
Bold heading text | true |
space_before_pt/space_after_pt
|
Spacing around a heading (pt) |
12/6
|
keep_with_next |
Keep a heading on the same page as the paragraph after it | true |
all_caps |
All-caps visual transform (OOXML w:caps) – the
underlying text is untouched |
false |
table
| Key | Controls | Default |
|---|---|---|
style |
Word table style name | "Table Grid" |
header_bold |
Bold the header row | true |
banding |
Alternating row shading | false |
synopsis
Governs the synopsis section’s definition-list look (bold label line,
indented value beneath it) – see synopsis-style: in the Quarto extension article for the three
layouts this applies to.
| Key | Controls | Default |
|---|---|---|
label_space_before_pt/label_space_after_pt
|
Spacing around a label line (pt) |
12/2
|
value_space_after_pt |
Space after a value line (pt) | 2 |
value_indent_in |
Value line indent (inches) | 0.25 |
alignment |
Overrides paragraph.alignment for values only; omit to
inherit it |
unset |
title_page
| Key | Controls | Default |
|---|---|---|
show_rule_under_title |
Rule under the title (color from colors.rule) |
true |
fields |
Which title-page fields appear, in order (a list, not a map – pandoc’s Lua metadata tables don’t preserve map key order) | report_type, title, subtitle, date, lead_scientist, version, confidentiality |
footer
| Key | Controls | Default |
|---|---|---|
show_page_number |
Show the page-number field | true |
text |
Optional static footer text | "" |
code
Styles fenced code blocks/inline code (pandoc’s own
Source Code/ Verbatim Char docx styles), and
every per-token syntax-highlight character style pandoc’s docx writer
can emit inside a fenced code block (KeywordTok,
StringTok, CommentTok, …) –
background_color applies to both, so a keyword or string
inside a code block shares the same background as the block around it
rather than keeping pandoc’s own hardcoded shading regardless of this
setting. Defaults match pandoc’s own built-in fallback, so leaving this
section untouched doesn’t change existing rendered output.
| Key | Controls | Default |
|---|---|---|
font_size |
Code text size (pt) – family comes from fonts.monospace
above |
10 |
background_color |
Shaded background, block and per-token alike | #F1F3F5 |
padding_pt |
Space before/after the shaded block (vertical only – OOXML paragraph shading has no horizontal-padding concept) | 0 |
equation
| Key | Controls | Default |
|---|---|---|
font |
Docx-wide default math font (applied post-render by
apply-layout, not build – pandoc’s docx writer
doesn’t carry this setting through from the reference-doc template).
Font family only; an unstyled equation inherits its size from the
surrounding paragraph |
"Cambria Math" |
build: style YAML → reference-doc
quartifyr::styling_build_reference_docx(
style = "inst/python/styles/default.yaml",
out = "org-reference.docx"
)
Add override/--override with just the keys
that differ from the default preset (fonts, colors, page setup, …) to
brand a new organization; see
inst/python/styles/default.yaml for the full schema and
inst/python/quartifyr_styling/schema.py for validation
rules (hex colors, positive sizes, valid page sizes, …).
style/override/out are plain
file paths, not fixed locations. An org can keep its style YAML
anywhere, and most project authors never need to run build
at all: reuse an already-built .docx, distributed however
your org already shares binary artifacts.
The generated reference-doc also sets
<w:updateFields w:val="true"/> in
word/settings.xml, so real Word automatically recalculates
every field (ToC, SEQ, REF, PAGE,
…) the moment a delivered document is opened; no manual “select all,
F9”, no LibreOffice involved for that case.
abbrevs: footnotes YAML → abbreviations bridge
quartifyr::styling_build_abbreviations_tex(
footnotes = "report/standard_footnotes.yaml",
out = "report/shell/abbreviations.tex"
)Converts a project’s standard_footnotes.yaml
(reportifyr’s own format) into the
abbreviations.tex that quarto-plus reads to
render a “only abbreviations actually used via \gls{}”
list.
apply-layout: header/footer + page-number split
quartifyr::styling_apply_layout(
docx = "report/shell/report.docx",
qmd = "report.qmd",
status = "draft"
)Run on the shell docx right after the Quarto render, before
reportifyr’s pass-2 fill. Reads the .qmd’s
frontmatter for header-format: and applies it to a two-zone
page header (template flush left, draft/final status flush right). Also
reads confidentiality: for the footer’s left zone, and, if
the .qmd uses {{< body-start >}}, splits
the rendered docx into title-page/front-matter/body OOXML sections so
the whole front matter numbers in lowercase roman (starting at “i”) and
the body restarts at arabic “1”. A .qmd with neither
header-format: nor {{< body-start >}} is
left untouched; both are opt-in.
It also turns
{{< landscape >}}/{{< portrait >}}
markers placed after {{< body-start >}} into
landscape and portrait section breaks, with the header, footer and page
numbering carried across.
Also reads crossref-hyperlinks: (default
true); false strips the \h
hyperlink switch from every figure/table/appendix cross-reference’s
REF field, document-wide. "same-page" can’t be
resolved here (no real pagination exists yet on the pass-1 shell); it
just marks each crossref for the next command.
fit-tables: wide tables on the page
quartifyr::styling_fit_tables("report/draft/report-draft.docx")Run on the filled draft/final docx. reportifyr
leaves the column widths of the tables it inserts to the word processor,
which gives a table with a dozen or more columns very narrow columns and
header words that break mid-word. This gives each of those tables a
fixed layout: the width of the page section it is in (so a table between
{{< landscape >}} and
{{< portrait >}} uses the landscape width), no column
narrower than its longest word, and, only when the words alone don’t
fit, a font size reduced in 1 pt steps to a 7 pt minimum. Tables
quartifyr generates itself (title page, signatures,
synopsis) are left alone. On by default in render_report()
(fit_tables = FALSE, or --no-fit-tables, to
skip it).
resolve-same-page-crossrefs: post-fill crossref
resolution
quartifyr::styling_resolve_same_page_crossrefs("report/draft/report-draft.docx")Resolves the markers apply-layout’s
crossref-hyperlinks: "same-page" left behind, now that
reportifyr’s pass 2 has filled in real content and
pagination means something; run on the filled draft/final docx,
not the shell. A no-op (skips LibreOffice entirely) if the document has
no same-page markers. Read-only with respect to LibreOffice: it drives a
headless-LibreOffice macro only to read page numbers, never to re-save
the docx.
Experimental. Inherits the headless-LibreOffice
caveats documented for recalculate-fields below. Off by
default in render_report().
recalculate-fields: headless ToC/field
recalculation
quartifyr::styling_recalculate_fields("path/to/report-final.docx")Drives headless LibreOffice to recalculate a docx’s Word ToC (page
numbers, entries) in place; for non-interactive pipelines that never
open the file in an application at all. Real Word already recalculates
fields automatically on open (via the reference-doc’s own
updateFields setting above), so this is only needed for
headless consumers.
Experimental. Earlier real-world runs against the
same document produced three different outcomes: a hang, a clean exit
that did nothing, or success. On macOS with LibreOffice 26.2 the hang
had a cause: a fresh profile that already contains the seeded macro
never runs it. The profile is now initialised first and the macro added
afterwards, which took 100 of 100 sequential and four-way concurrent
runs on macOS 26.6 to success in under three seconds each. A macro that
still never starts is abandoned after half the timeout (at least 30
seconds, or QUARTIFYR_SOFFICE_START_TIMEOUT) and reported
as unavailable instead of waiting out the timeout. Windows and Linux
were not re-tested. Off by default
(render_report(..., recalculate_fields = FALSE)). When it
does fail, it only produces a warning, not a render failure; the
document is still fully usable, just needs a manual “select all, F9” in
Word.
Pulling and editing a project’s own style YAML
# Copy the bundled default template/style into a project
quartifyr::styling_example_template(dir = "templates")
style <- quartifyr::styling_example_style(dir = ".")
# Edit in place ...
style$heading$all_caps <- TRUE
style$colors$heading <- "#0054AD"
# ... and save back out as just the diff from the default
quartifyr::styling_save_overrides(style, file = "overrides.yaml")That override YAML is what style/override
(or --style/--override) take everywhere else
in this article – styling_build_reference_docx()
deep-merges it onto the base at load time, so it’s a diff to keep in a
project, not a second full style YAML to maintain by hand.
For a narrower, one-off edit to an existing style YAML (not
necessarily one just pulled via
styling_example_style()):
quartifyr::styling_update_style(
list(code = list(background_color = "#FFF3CD")),
file = "overrides.yaml",
yes = TRUE
)Deep-merges the update onto file’s content, in place – a
modifyList()-style edit without hand-copying the rest of
the file. yes = TRUE is required: this rewrites the whole
file, so any comments it had are lost.
