YAML Front Matter


YAML Front Matter

RexxPub can read configuration options from the YAML front matter block of a Markdown document, in addition to (or instead of) command-line options, URL parameters, or program defaults.

Every key, the values it takes and which of the md2 programs reads it are in a table of their own: The Front Matter at a Glance.

This feature is available in every RexxPub program: the CGI (Serve and Print), md2html (Build), md2pdf (Render), md2epub (EPUB generation), md2latex and md2slides.

Syntax

A YAML front matter block is a block of text delimited by --- lines at the very beginning of a Markdown file:

---
title: My Document
author: Josep Maria Blasco
bibliography: references.bib
rexxpub:
  section-numbers: 3
  size: 12
---

The opening --- must be the first line of the file. The closing delimiter may be --- or .... What lies between the delimiters is YAML 1.2, read by yaml.cls, the YAML class that comes with ooRexx (version 5.2.0 and later): block and flow mappings and sequences ({ a: 1, b: 2 }, [x, y]), nesting to any depth, single- and double-quoted strings (with escapes in double quotes), literal (|) and folded (>) block scalars, anchors and aliases, and comments (# at the start of a line, or after a blank). This is the same YAML that Pandoc reads from the same block.

A few consequences are worth knowing:

  • Booleans. true, yes and on (in lower case, capitalized or all capitals) are the boolean true, and false, no and off the boolean false. RexxPub sees them as true and false. A text that happens to be one of those words must be quoted: answer: "yes".
  • Empty values. A key with no value (key:), or with ~ or null, counts as not given at all.
  • Colons. A colon followed by a blank inside an unquoted value is not allowed: write title: "Rexx: The Language". A colon with no blank after it (time: 12:30, https://...) is fine.
  • Numbers. Integers are read as numbers: 012 is 12. Quote a value that must keep its exact spelling.
  • Indentation. Only blanks, never tabs.

Invalid YAML stops the conversion, with the line it was found in:

paper.md:5: invalid YAML front matter: Mapping value is not allowed in this context: A: B

Pandoc would reject the same block anyway; RexxPub says so first.

Valid YAML can still give an option the wrong shape: a list or a block where one value goes (style: {.x}, docclass: [a, b]). Such an option is ignored, with a warning:

Warning: YAML 'rexxpub: style:' is a block, not a value; ignored.

Pandoc metadata vs. RexxPub options

The YAML front matter block serves a dual purpose. Pandoc reads it to extract standard metadata fields such as title, author, date, bibliography, and csl. RexxPub reads it to extract its own options, which live under the rexxpub: key to avoid any conflict with Pandoc's metadata.

Both Pandoc and RexxPub process the same front matter block — there is no need to duplicate it:

---
bibliography: references.bib
csl: ../../../../csl/rexxpub.csl
rexxpub:
  style: dark
  section-numbers: 3
  number-figures: true
  size: 12
---

In this example, Pandoc will use bibliography and csl for citation processing, and RexxPub will use the fields under rexxpub: to configure the output.

RexxPub options

All RexxPub options are placed under the rexxpub: key. The currently supported options are:

Key Values Default Pipelines Description
style A style name, or a file dark All Default Rexx highlighting style
size Number (pt), 6–36 Per class md2pdf, CGI, md2latex Base font size
section-numbers 0--4 Per class All but md2slides Section numbering depth
number-figures 0, 1, true, or false true All but md2latex Automatic figure/listing numbering
docclass article, book, letter, slides Per filename md2pdf, CGI, md2latex Document class
outline 0--6 3 md2pdf only PDF outline depth (H1..Hn)
margin 1 to 4 lengths, as in CSS Per class md2pdf only Page margins
css A sheet, several, or a list (none) md2pdf only The document's own stylesheets

The number-figures option accepts 0, 1, or a boolean (true, false, yes, no, on, off).

The default for size is 12 for article, book, default, and letter, and 20 for slides.

The sizes 10, 11, 13 and 14 have a stylesheet of their own for each class, made after LaTeX (article-10pt.css...), and 12 is the base. In md2pdf any other size, from 6 to 36 points (size: 9, size: 10.5, size: 9pt), is computed: the page comes from the nearest stylesheet, and the sizes of footnotes, their marks and code are worked out from the number, in the same proportions.

margin sets the margins of every page, as the CSS margin property does: one length for all four (margin: 1.5cm), two for top and bottom and for the sides (margin: 2cm 1.5cm), three, or four (top, right, bottom, left). The units are cm, mm, in, pt, pc, px and q. It wins over the margins of the class and the size. In a book, right and left are the outside and the inside of a right-hand page, and the other way round on a left-hand one. A value that is not a margin is reported and left out.

css names the document's own stylesheets: one (css: test.css), several (css: a.css b.css, or with commas), or a YAML list (css: [a.css, "my sheets/b.css"], for a name with blanks). They are found relative to the document, and loaded after the stylesheets of RexxPub, in the order given, and before file.md.css, the sheet that belongs to one file only. A sheet that is not there is reported and left out.

The default for section-numbers depends on the document class: 3 for article (and default), 2 for book, and 0 for letter and slides. A file with no document class (in the CGI and md2html, any file not called article.md, book.md, letter.md or slides.md, unless its docclass: says otherwise) is shown as written, with no section numbers: ask for them with section-numbers:. md2epub numbers no sections unless section-numbers asks for it.

The docclass option overrides the filename-based inference (in md2pdf and the CGI); in md2latex, --class wins over it. For example, a file named readme.md with docclass: article in its YAML front matter will be rendered using the article document class. In the CGI, this also selects the corresponding CSS (print/article.css) and determines the default section-numbering depth. Invalid class names are silently ignored (with a warning in md2pdf).

An unknown style is ignored the same way, with a warning, in md2pdf, md2html and md2epub, and the default style applies instead. (With --style, the YAML value is not consulted at all.) Style names are case-insensitive, as they are on the command line.

style can also be a stylesheet of the author's own: a file next to the document, or anywhere else (style: my-style.css, style: ./styles/rexx-mine.css). A value with a / or a \, or ending in .css, is a file, relative to the document. The style's name is the one its rules carry: the first .highlight-rexx-NAME class in the file. So a copy of a shipped sheet (css/rexx-vim-light-zellner.css, say) can be edited and used as it is, without renaming anything: from then on, vim-light-zellner is the author's. md2latex, md2html, md2pdf, md2epub and md2slides take it, and so does --style (relative to the current directory). md2html links the sheet where it is, as the page sees it; md2pdf and md2epub flatten its nesting, which their readers do not understand; md2slides embeds it in the deck. A file that is not there, or has no .highlight-rexx-NAME rules, is reported, and the default style applies.

The outline option controls how many heading levels are included in the PDF document outline (bookmarks). It is only used by md2pdf, which passes --outline-tags h1,...,hn to pagedjs-cli. outline: 0 leaves the PDF with no outline (before 20261102 it was the same as 1).

Citation Style Language (csl)

The csl option is not a RexxPub option. It is a standard Pandoc metadata field and should be placed at the top level of the YAML front matter, not under rexxpub::

---
bibliography: references.bib
csl: ../../../../csl/rexxpub.csl
rexxpub:
  section-numbers: 3
---

Pandoc reads csl directly from the YAML front matter and uses it for citation processing with --citeproc. RexxPub does not need to duplicate this field.

Note: md2pdf, md2epub and md2latex also accept a --csl command-line option, which passes the style to Pandoc explicitly. The argument can be a plain name (looked up in the csl/ directory of the distribution) or a full path to a .csl file. When a csl field is present in the YAML front matter, it wins: the --csl option is not passed. md2html and the CGI follow csl too (md2html uses rexxpub when there is none).

Document language (lang)

The lang field is a standard Pandoc metadata field and should be placed at the top level of the YAML front matter, not under rexxpub::

---
lang: es
rexxpub:
  style: dark
---

This sets the lang attribute on the <html> element (or the equivalent in EPUB and PDF), which affects hyphenation, spell-checking, and accessibility in the browser or PDF viewer. The value should be a BCP 47 language code (e.g. en, en-GB, es). When omitted, the default is en.

Syntax highlighting style (highlight-style)

The highlight-style field is a standard Pandoc metadata field and should be placed at the top level of the YAML front matter, not under rexxpub::

---
highlight-style: kate
rexxpub:
  style: dark
---

This option selects the CSS theme used for syntax highlighting of non-Rexx fenced code blocks (Python, Java, SQL, etc.). These blocks are highlighted by Pandoc's built-in skylighting engine; RexxPub loads the corresponding CSS from the css/pandoc/ directory. The available styles are: pygments (the default), kate, tango, espresso, zenburn, monochrome, breezeDark, and haddock.

This option does not affect Rexx code blocks, which use the Rexx Highlighter and the style option under rexxpub:.

Note: md2pdf also accepts a --pandoc-highlighting-style command-line option.

Listing options (listings:)

The listings: nested group controls the appearance of code listing captions. These captions are generated by the numberFigures.js script from the data-caption attribute on fenced code blocks (set via the caption="..." option in the fenced code block header).

md2slides reads listings:, figures: and number-figures too, and builds the same captions itself; in a deck, number-figures defaults to false.

---
rexxpub:
  listings:
    caption-position: below
    caption-style: italic
    label-style: bold-italic
    label: Example
    frame: tb
---
Key Values Default Description
caption-position above, below above Caption placement relative to code
caption-style normal, italic normal Font style of the caption text
label-style bold, italic, bold-italic, normal bold Font style of the "Listing N:" label
label Any text Per language Custom label (overrides localization)
frame none, tb, single, leftbar none Border style for Pandoc code blocks

The caption-position option changes both the DOM order (semantic) and the visual position of the <figcaption> element. When set to below, the script places the caption after the code block instead of before it, and the CSS break rules are adjusted so that the caption stays attached to the code.

The label option overrides the localized label ("Listing" in English, "Listado" in Spanish, etc.) for all listings in the document. This is useful for tutorials that prefer "Example" or documents mixing code and pseudocode that want "Code".

The frame option controls the border style of Pandoc-highlighted code blocks (non-Rexx fenced code blocks). The values follow the LaTeX listings package conventions: none (no border, the default), tb (top and bottom rules), single (full box), and leftbar (a vertical rule on the left side). Rexx fenced code blocks are not affected, as they have their own styling.

Listing options only affect code listings. Image figure captions are controlled separately by the figures: group described below.

Figure options (figures:)

The figures: nested group controls the appearance of image figure captions. These are the <figcaption> elements that Pandoc generates inside <figure> elements for images with alt text.

---
rexxpub:
  figures:
    caption-position: above
    caption-style: italic
    label-style: bold
    label: Illustration
---
Key Values Default Description
caption-position above, below below Caption placement relative to image
caption-style normal, italic normal Font style of the caption text
label-style bold, italic, bold-italic, normal bold Font style of the "Figure N:" label
label Any text Per language Custom label (overrides localization)

Note that the default for caption-position is below (the standard HTML/Pandoc convention), whereas for listings it is above (the LaTeX convention).

The caption-position option changes both the DOM order and the visual position of the <figcaption> element. When set to above, the script moves the caption before the <img> element, and the CSS break rules are adjusted so that the caption stays attached to the image.

The label option overrides the localized label ("Figure" in English, "Figura" in Spanish, etc.) for all figures in the document.

Figure options only affect image figures. Code listing captions are controlled separately by the listings: group described above.

Table options (tables:)

The tables: nested group sets how the tables of the document look, in every pipeline (md2html, the CGI, md2pdf, md2epub and md2latex). A table is balanced by default: its columns are as wide as what they hold asks, not as the dashes under its header say.

---
rexxpub:
  tables:
    grid: yes
    stripes: "#F2F2F2"
---
Key Values Default Description
grid yes, no no A line around every cell
stripes yes, no, or a colour no Every second row of the body on a colour (yes: a light grey)

A single table says otherwise on the ::: that holds it, and wins over the YAML: .grid and .nogrid, .stripes and .nostripes, stripes=#E8F0FF (the colour, in hex), and cols=1:4 for the relative widths of its columns (a column it does not name counts as 1). md2latex also takes rules=solid, dashed or dotted there, a line under each row.

Block options (blocks:)

The blocks: nested group gives the code blocks of the document a ground and a frame, in every pipeline (md2html, the CGI, md2pdf, md2epub, md2latex and, since v359, md2slides, where it may also be written in a defaults: file). What is said at the top of the group is for every block; under code:, only for code (Rexx listings and code in other languages); under output:, only for program output (```{.output}).

---
rexxpub:
  blocks:
    border: solid
    border-width: 0.5pt
    code:
      background: "#F2F6FA"
    output:
      border: dashed
---
Key Values Default Description
background A colour, or none The style's The ground of the block
border solid, dashed, dotted, none (none) A frame around the block
border-width A length: 0.5pt, 1px, 0.2mm... 1px How thick the frame is
border-color A colour gray The colour of the frame

A colour is #RRGGBB, #RGB, or one of the 148 names of CSS (gray, navy, cornflowerblue, rebeccapurple...), as in JDOR. A block says otherwise on its fence, and wins: background=, border=, border-width= and border-color= work on any fence, a Rexx one too (see the fenced code documentation). A border-width= or a border-color= without a border= means a solid one. A value that is not one of these is reported and left out.

Since v366, the group can also say what is for the code of one language, under a key that names it, and for all the code that is not Rexx, under other:. Shell commands on a light blue ground, say, with the Rexx listings left as they are:

---
rexxpub:
  blocks:
    border: dotted
    bash:
      background: "#EEF5FC"
---

The language of a block is the first class of its fence (```bash and ```{.bash} are bash), in any case; a Rexx listing's is rexx, so rexx: is for the Rexx listings alone. Any key of the group with values under it, but code:, output: and other:, names a language. The fence wins over its language, the language over other:, other: over code:, and that over the group as a whole. Output (```{.output}) has no language: only output: and the group speak for it.

Mention options (mentions:)

A Rexx mention in the text (`Say "Hi"`{.rexx}, and [USE]{.kw}, which is `USE`{.rexx keyword}) is set on the ground of code. With

---
rexxpub:
  mentions:
    background: none
---

the mentions keep the colours of the style, on no ground (md2html, the CGI, md2pdf, md2epub, md2latex and md2slides; no and false are the same as none).

Other nested groups

The rexxpub: key may contain additional nested groups. Some are read by a single pipeline, and are documented with that pipeline rather than here; any that no pipeline claims are still parsed and stored as sub-tables, but are not acted upon.

The anim: group is of the first kind. It sets the default page and element animations of a slide deck, and is read by md2slides alone — the other pipelines produce no slides and ignore it. It is documented, together with the deck-only title: and footer: keys, in the md2slides documentation.

Precedence

When the same option is specified in multiple places, the following precedence rules apply:

style (highlighting style)

URL parameter > YAML > default.

The style option follows a reader-wins policy. The URL parameter (or the style chooser dropdown in the CGI) always takes precedence over the YAML value, which in turn takes precedence over the built-in default (dark).

This is because the highlighting style is a presentation choice that depends on context: a document may look best with dark on screen, but the author (or someone else) will need print when producing a PDF for conference proceedings. The style chooser and the ?style= parameter must continue to work even when the YAML specifies a default.

All other options

YAML > default.

All structural options follow an author-wins policy. They are set in the YAML front matter, and there is no URL parameter for them, nor a command-line option in md2pdf or md2html. (In md2epub, --cover and --chapter-level give a value that the YAML has not given; in md2latex, --class wins over docclass.)

This is because structural options reflect the author's intent about how the document should be rendered. If the author writes section-numbers: 2, it is because the document is designed for exactly two levels of numbering. A URL parameter should not silently override that decision — and, looking ahead, if the document contains cross-references such as "as explained in Section 3.1 on page 12", changing the numbering depth from the URL could render those references meaningless.

When the YAML does not specify a value, the built-in default applies.

Summary table

Option 1st (wins) 2nd 3rd (default)
style URL/CLI YAML dark
size YAML Per class
section-numbers YAML Per class
number-figures YAML true
docclass YAML filename default
outline YAML 3
margin YAML Per class
css YAML (none)

Example

A typical article with RexxPub options in the YAML front matter:

---
bibliography: references.bib
csl: ../../../../csl/rexxpub.csl
lang: en
rexxpub:
  docclass: article
  section-numbers: 3
  number-figures: true
  outline: 4
---

::::: title-page

My Article <small>A Subtitle</small>
=====================================

::: author
Author Name
:::

:::::

Introduction
============

...

The CGI will render this with 3 levels of section numbering and automatic figure numbering, using the article document class (regardless of the filename). The highlighting style will default to dark, but the reader can override it with ?style=light or the style chooser dropdown. The section numbering, figure numbering, and document class cannot be overridden from the URL — they are fixed by the author.

When rendered with md2pdf, the PDF will include an outline (bookmarks) for headings H1 through H4, and the <html lang> attribute will be set to en.