LaTeX template: \thesubtitle undefined — subtitled PDFs fail to compile #13

Closed
opened 2026-07-09 15:43:46 -04:00 by jared · 1 comment
Owner

Summary

inst/quarto/latex/civilytics-title.tex references \thesubtitle, but nothing ever defines it, so any PDF document that sets a subtitle fails to compile.

Reproduction

A .qmd with a subtitle, using the civilytics LaTeX template:

---
title: "My Title"
subtitle: "A subtitle"
format:
  pdf:
    pdf-engine: xelatex
    include-in-header:  latex/civilytics.tex
    include-before-body: latex/civilytics-title.tex
---

Fails with:

! Undefined control sequence.
l.318 ...selectfont\color{ink2}\thesubtitle

Root cause

Quarto/pandoc emits the subtitle like this (verified in the generated .tex):

\title{My Title}
\providecommand{\subtitle}[1]{\apptocmd{\@title}{\par {\large #1 \par}}{}{}}
\subtitle{A subtitle}

It defines \subtitle (which appends to \@title) — it never defines \thesubtitle. The titling package provides \thetitle/\theauthor/\thedate but has no subtitle equivalent.

Suggested fix

include-in-header (civilytics.tex) is emitted before pandoc's \subtitle provider (verified: line 133 vs 280), and pandoc uses \providecommand, so a definition in civilytics.tex wins. Add to civilytics.tex:

% Capture the pandoc subtitle into \thesubtitle for the title page
\makeatletter
\newcommand{\thesubtitle}{}
\newcommand{\subtitle}[1]{\renewcommand{\thesubtitle}{#1}}
\makeatother

Also suppress pandoc's default \maketitle in civilytics-title.tex (it runs after the custom title page and would otherwise print a second, unstyled title), and add a \providecommand{\thesubtitle}{} guard in the title partial so it degrades gracefully if used without the preamble.

Found while rendering a branded PDF (COG finance API spec).

## Summary `inst/quarto/latex/civilytics-title.tex` references `\thesubtitle`, but nothing ever defines it, so **any PDF document that sets a `subtitle` fails to compile**. ## Reproduction A `.qmd` with a subtitle, using the civilytics LaTeX template: ```yaml --- title: "My Title" subtitle: "A subtitle" format: pdf: pdf-engine: xelatex include-in-header: latex/civilytics.tex include-before-body: latex/civilytics-title.tex --- ``` Fails with: ``` ! Undefined control sequence. l.318 ...selectfont\color{ink2}\thesubtitle ``` ## Root cause Quarto/pandoc emits the subtitle like this (verified in the generated `.tex`): ``` \title{My Title} \providecommand{\subtitle}[1]{\apptocmd{\@title}{\par {\large #1 \par}}{}{}} \subtitle{A subtitle} ``` It defines **`\subtitle`** (which appends to `\@title`) — it never defines **`\thesubtitle`**. The `titling` package provides `\thetitle`/`\theauthor`/`\thedate` but has no subtitle equivalent. ## Suggested fix `include-in-header` (civilytics.tex) is emitted *before* pandoc's `\subtitle` provider (verified: line 133 vs 280), and pandoc uses `\providecommand`, so a definition in civilytics.tex wins. Add to `civilytics.tex`: ```latex % Capture the pandoc subtitle into \thesubtitle for the title page \makeatletter \newcommand{\thesubtitle}{} \newcommand{\subtitle}[1]{\renewcommand{\thesubtitle}{#1}} \makeatother ``` Also suppress pandoc's default `\maketitle` in `civilytics-title.tex` (it runs *after* the custom title page and would otherwise print a second, unstyled title), and add a `\providecommand{\thesubtitle}{}` guard in the title partial so it degrades gracefully if used without the preamble. Found while rendering a branded PDF (COG finance API spec).
Author
Owner

Fixed in PR #15 (merged to master).

Fixed in PR #15 (merged to master).
jared closed this issue 2026-07-09 16:19:17 -04:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Civilytics/civilyticsR#13