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.

On Wednesday, June 30, 2021 at 2:30:07 PM UTC+2 Nick Bart wrote:
@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 stderr
function warnf (...)
  io.stderr:write(string.format(...))
end
function 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 then
      warnf('pageheading attribute not supported for level %d headings', el.level)
      return el
    end
    -- 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 hypertarget
    latexStr = string.format('\\hypertarget{%s}{%%\n%s%s}', el.identifier, latexStr, label)
    return pandoc.RawBlock('latex', latexStr)
  end
end

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/20fccf69-3cde-450a-ad6f-f7c2ae9b2531n%40googlegroups.com.