latexpandoc

How do I use Pandoc to convert Latex to HTML such that the source code snippets inside Latex keep syntax highlighting in HTML?


I need to convert some Latex material into HTML using Pandoc. The issue I am facing is that the (C) source code snippets are not being highlighted in the HTML.

If I use the following as example:

\documentclass[a4paper]{report}
\usepackage{minted}
\begin{document}
    \begin{minted}[linenos, bgcolor=yellow, autogobble, tabsize=4]{c}
        void main()
        {
            printf("I need help!\n");
        }
    \end{minted}
\end{document}

Doing the conversion using pandoc -N -f latex -t html example.tex -o example.html yields an HTML file that looks as follows:

The converted code.

The following link Pandoc latex to html: cannot keep code formatting suggests using minted but I see no syntax highlighting.

Any ideas?


Solution

  • This should work without any additional filters. The problem appears to be that the necessary highlighting styles are not part of the generated HTML. Use --standalone/-s to use the default template, or generate a custom template to include the relevant snippets.

    See also this question.