Conversation
Pandoc emits \citep / \citet when citation_package: natbib is set, but tufte-latex only redirects \cite, so citations rendered inline instead of as margin sidenotes. Patch tufte-common.def to redefine both commands via \RenewDocumentCommand: \citep routes through \cite (margin entry), \citet adds the "Author (Year)" textual form inline plus the margin entry. \citeyearpar ([-@key]) is intentionally untouched; optional prefix/locator arguments are dropped.
cderv
added a commit
that referenced
this pull request
May 21, 2026
The xparse signature `{o o m}` used by the #48 patch reads the next token
as the mandatory argument when no optional argument is present. For
raw-LaTeX `\citep*{key}` that token is `*`, so the citation key `{key}`
gets dropped on the floor and the star becomes the cite argument, with
broken output and undefined-citation warnings.
Pandoc never emits the starred forms itself, so the bug only reaches
users who type natbib commands directly in their .Rmd. Add `s` to the
signature on both `\citep` and `\citet` so the star is consumed, then
route the unstarred margin path either way. The keep-generator-in-sync
copy in tools/update-tufte-common-def.R is updated to match.
Follow-up to roborev review on #48 (PR #135).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
tufte::tufte_handout()(ortufte_book()) is used withcitation_package: natbib, citations render inline as plain author-year text with a bibliography only at the bottom, instead of appearing as margin sidenotes liketufte-latexdoes for hand-written\cite{}calls.Root Cause
Pandoc with
citation_package: natbibemits\citep{key}for[@key]and\citet{key}for@key, never the bare\cite{}form. Thetufte-latexclasses only redefine\citeto route through the margin sidenote machinery (inst/rmarkdown/templates/tufte_handout/patches/tufte-common.def, line 970); natbib's own\citepand\citetare left untouched, so they render inline like in any non-tufte document.Fix
Patch
tufte-common.defto redefine\citepand\citetvia\RenewDocumentCommand, guarded by the existing@tufte@loadnatbibboolean:\citepnow produces a margin sidenote (superscript marker in body, full reference in the margin).\citetkeeps natbib's textual "Author (Year)" form inline AND adds the full reference to the margin — the proper Tufte book style, preserving prose for textual citations. The redefinitions delegate to\citerather than\@tufte@normal@citedirectly so they pick up tufte's in-sidenote swap when nested inside\sidenote{}.\RenewDocumentCommandis available in the LaTeX kernel since 2020-10, so no extra\usepackage{xparse}is needed.The patch is also registered in
tools/update-tufte-common-def.Rso future upstream refreshes re-apply it automatically.Known limitations
\citep[prefix][locator]{key}arguments are dropped.[@key, p. 5]places the entry in the margin but does not echo "p. 5".\citeyearpar(emitted for[-@key]suppress-author) is intentionally left at natbib's default inline rendering.Test plan
tufte::tufte_handout()withcitation_package: natbiband[@key]— superscript in body, full entry in margin@key— body shows "Author (Year)" + superscript, margin shows full entry[@a; @b]— single superscript, margin shows both entries joined with "and"[-@key]— renders inline as(YEAR), no margin entry (by design)tufte::tufte_book(),tufte_handout2(),tufte_book2()behave the same^[footnote]does not errordevtools::test()passesFixes #48