Skip to content

Unnumbered sections do not show up in page headers created via LaTeX #2412

@tarleb

Description

@tarleb

Bug description

Unnumbered headers, e.g., # References {-}, are translated to \chapter* by pandoc. The starred sectioning commands in LaTeX have the side-effect of not updating the marks used for the page heads, which can have unintended effects. See., e.g., jgm/pandoc#1632 and rstudio/bookdown#1382. Pandoc tries to avoid an opinionated solution, as users may not want chapters and sections show up in the page headers, which is why it hasn't been fixed there yet. It might make sense to use a Lua filter as a temporary until this is resolved in pandoc. E.g.

--- Removes notes and links
local function clean (inlines)
  return inlines:walk {
    Note = function (_) return {} end,
    Link = function (link) return link.content end,
  }
end

--- Creates an Inlines singleton containing the raw LaTeX.
local function l(text)
  return pandoc.Inlines{pandoc.RawInline('latex', text)}
end

function Header (h)
  if h.level <= 2 and h.classes:includes 'unnumbered' then
    local title = clean(h.content)
    local secmark = h.level == 1
      and l'\\markboth{' .. title .. l'}{' .. title .. l'}'
      or l'\\markright{' .. title .. l'}' -- subsection, keep left mark unchanged
    return {h, secmark}
  end
end

Additional logic could be included, allowing users to configure headers via YAML settings.

Cc @cderv

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcrossref

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions