Others can correct me if I'm wrong, but I don't think the filter has enough information to tell in all cases what a level 1 header corresponds to in LaTeX. If documentclass is specified in the metadata, you could deduce whether chapter or section will be selected by default. However, --top-level-headings (or the documentclass variable?) could override the metadata.
@jcr - Brilliant, works like a charm. I had to make some trivial changes; the version I’m using right now with the LaTeX article or scrartcl classes is shown below.One thing that would be nice to have, though, would be the ability to switch automatically between a 'commands' list for book-like LaTeX classes (starting with 'chapter'), and article-like classes (starting with 'section'). I'll be trying to figure that out, but useful hints would be welcome.-- Print a formatted warning to stderrfunction warnf (...)io.stderr:write(string.format(...))endfunction Header (el)-- Replace heading with raw LaTeX if pageheading is used to specify a-- shorter form of the title to use in page headers.if el.attributes.pageheading then-- local commands = {'chapter', 'section', 'subsection'}local commands = {'section', 'subsection'}if el.level > #commands thenwarnf('pageheading attribute not supported for level %d headings', el.level)return elend-- Produce LaTeX like pandoc does, but with two additional arguments-- to specify a short for of the page heading to memoir.local title = pandoc.utils.stringify(el)-- local latexStr = string.format('\\%s[%s][%s]{%s}', commands[el.level], title, el.attributes.pageheading, title)local latexStr = string.format('\\%s[%s]{%s}', commands[el.level], el.attributes.pageheading, title)local label = string.format('\\label{%s}', el.identifier)-- wrap in hypertargetlatexStr = string.format('\\hypertarget{%s}{%%\n%s%s}', el.identifier, latexStr, label)return pandoc.RawBlock('latex', latexStr)endend