1

I know including raw HTML is possible in Markdown documents with Pandoc, so I was wondering if there was a way to allow it in LaTeX documents.

Pandoc converts lower than and greater than characters to HTML entities when included in a LaTeX document (even when inside a verbatim). it makes perfect sens but it's not what I want.

  • 1
    escape the characters – var firstName Jan 11 at 20:12
  • 1
    It doesn't work. You can try it out online here : the characters are deleted altogether. – geoffrey Jan 12 at 15:19
  • I was hoping someone would have worked out how to support \begin{rawhtml}...\end{rawhtml} with pandoc. – peterjc Jul 18 at 8:09
0

The best way is to use a specially-marked verbatim environment, which can then be transformed into the desired target format via a Lua filter. E.g., add a %%%html tag as the first line of a verbatim environment, then insert the HTML which you'd like to preserve:

\begin{verbatim}
%%%html
<aside>Embedding raw HTML can be helpful</aside>
\end{verbatim}

Pandoc will read this as a normal code block, but we want a raw HTML block. We use a filter a filter to convert it:

function CodeBlock(cb)
  local rawHtml = cb.text:match('^%s*%%%%%%html\n(.*)')
  if rawHtml then
    return pandoc.RawBlock('html', rawHtml)
  end
end

Save the above into a file and use it as the argument of pandoc's --lua-filter option.

  • 1
    This is awesome! I noticed that verbatim behaves like a block and has the tendency to close paragraphs, which is not great when I want to insert inline elements within a paragraph, but now that I know where to look I should be able to sort this out by myself. I suppose I can aso modify the behavior of \texttt. – geoffrey Jan 13 at 15:57

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.