Search code examples
pandocbeamer

How to make pandoc generate header using beamer structure instead of blocks


How do I change the way headers below slide level are converted in LaTeX by pandoc from {block} environment to \structure{} command?

  • Imagine such a Markdown file (foo.md)

    # Slide title
    
    ## Header
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    
  • Let us convert it to LaTeX with the following command:

    pandoc -t beamer --slide-level 1 foo.md -o foo.tex
    
  • The resulting LaTeX file is something similar to:

    \begin{frame}{Slide}
    
    \begin{block}{Header}
    
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    
    \end{block}
    
    \end{frame}
    

Is there an easy simple and elegant solution so that pandoc produce something like the following?

\begin{frame}{Slide}

\structure{Header}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

\end{frame}

Solution

  • Easy to achieve via Lua filters:

    function Header (header)
      if header.level == 2 then
        local inlines = pandoc.List:new{}
        inlines:extend {pandoc.RawInline('tex', '\\structure{')}
        inlines:extend(header.content)
        inlines:extend {pandoc.RawInline('tex', '}')}
        return pandoc.Plain(inlines)
      end
    end
    

    Safe the filter to a file and pass that file to pandoc via the --lua-filter option.