I am writing a pair of Pandoc template and LaTeX package(s) for my authoring workflow (write in Markdown, produce PDF through Pandoc->LaTeX). In the Markdown document the type of document can be selected, and consequently different document classes can be loaded (book, report, article, presentation, or letter classes).

Unfortunately I can't make Pandoc dynamically adjust the mapping of heading levels to LaTeX commands. So the intermediate LaTeX file will always have \section{} as first-level headings, \subsection{} as second level etc., as it is appropriate for an article class.

What I can do in a Pandoc template is conditionally execute LaTeX commands, so the suggestion was to remap the LaTeX sectioning commands appropriately. My question is: is it possible to "remap" all sectioning commands or do I have to "recreate" them by copying their original definition?

If I do


it seems to correctly shift chapters to become parts. However, if I do


both sections and chapters end up being parts. I can see why this happens, as \section is mapped to \chapter which is already a \part (the order of the two commands doesn't seem to make a difference, which is what I hoped for).

What is the best (only?) way of shifting all heading levels by a fixed number of levels?

  • 1
    \let\originalchapter\chapter \renewcommand\chapter{\part} \let\originalsection\section \renewcommand\section{\originalchapter} But that's not the way of doing this, probably.
    – Manuel
    Jan 12, 2018 at 9:21

2 Answers 2


Start from the lowest sectioning level you plan to use:


With \let one essentially copies the current definition.

  • Thank you, that works as desired. Does \renewcommand simply reference instead?
    – uli_1973
    Jan 12, 2018 at 11:36
  • @uli_1973 Yes, \renewcommand{\section}{\chapter} will only use the meaning of \chapter current at the time \section is used, not at the time the redefinition is made.
    – egreg
    Jan 12, 2018 at 11:58

You can tell pandoc to use part as the top level with the option --top-level-division=part

From pandoc's user guide:


Treat top-level headers as the given division type in LaTeX, ConTeXt, DocBook, and TEI output. The hierarchy order is part, chapter, then section; all headers are shifted such that the top-level header becomes the specified type. The default behavior is to determine the best division type via heuristics: unless other conditions apply, section is chosen. When the LaTeX document class is set to report, book, or memoir (unless the article option is specified), chapter is implied as the setting for this option. If beamer is the output format, specifying either chapter or part will cause top-level headers to become \part{..}, while second-level headers remain as their default type.

  • Thank you, but that's beside the point. Basically I asked about dynamically changing the top-level-division from inside the template.
    – uli_1973
    Jan 14, 2018 at 22:00
  • If the point of "dynamically adjust[ing] the mapping of heading levels to LaTeX commands" was to do so at arbitrary places "inside the template", then this is, indeed, beside it.
    – DG'
    Jan 15, 2018 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .