5

I use Pandoc to generate an output from a Markdown file to many outputs: html, word (.docx), latex, pdf, etc.

I tried using the "fenced div" feature to style differently some parts of the text. For example:


blablabla.

:::: special

Some special text, with markdown formatting.

::::


To style that block with Html, it's fairly straight forward. I have a template.css file that includes a .special {background-color: #aaaaaa;} line and it's done (it's referenced in my command line arguments).

I also have a template.latex file, but I'm less fluent in all things Latex. I've tried in many ways and couldn't find how to tweak it to apply a style to pandoc fenced divs. In the raw Latex file that it outputs, there's not even a command indicating that there was something there. It's just ignored.

I've searched a long time for this answer, and I can't find any clue. Thanks in advance.

2
  • 1
    Welcome to TeX.se! I don't think this is a supported feature yet (if it ever will be). See github.com/jgm/pandoc/issues/5880 for some discussion. The recommended approach seems to be to use Lua filters.
    – Alan Munn
    Jan 27 '20 at 22:46
  • 1
    AFAIK you must use ::: {.special data-latex=""} and of course the "special" environment should have been already defined in the template preamble, the document class or some package, that I suspect that is not usable to export to another formats.
    – Fran
    Jan 28 '20 at 6:38
5

You need a lua filter to process the fenced div:

function Div(el)
  if el.classes[1] == "special" then
    -- insert element in front
    table.insert(
      el.content, 1,
      pandoc.RawBlock("latex", "\\begin{Special}"))
    -- insert element at the back
    table.insert(
      el.content,
      pandoc.RawBlock("latex", "\\end{Special}"))
  end
  return el
end

This will transform the div to a latex environment:

blablabla.

\begin{Special}

Some special text, \emph{with markdown formatting.}

\end{Special}

You mustn't forget do define the environment in your template:

\usepackage{mdframed}
\newenvironment{Special}%
  {\begin{mdframed}[backgroundcolor=lightgray]}%
  {\end{mdframed}}

enter image description here

1
  • 1
    Thanks! If you didn't already know: You can output the AST with --to native to figure out how pandoc represents the elements internally
    – DG'
    Jan 28 '20 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.