# LaTeX to HTML using htlatex - Background problem

I've been trying to highlight Python code and convert it to HTML. For highlighting I used the minted package since it provided a few styles that I was looking for and I used htlatex for HTML conversion. Unfortunately, the background is not set as intended.

When using htlatex, I get the following warning:

"Missing \Configure{\HColor}{DarkGrey}{...} (in Latex: gray 0.1)"


Here is the TeX file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{minted}
\usepackage{xcolor}
\definecolor{DarkGray}{gray}{0.1}
\usemintedstyle{monokai}
\begin{document}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
bgcolor=DarkGray
]
{python}

[random python code here...]

\end{minted}
\end{document}


htlatex is called like so:

htlatex test.tex "" "" "" -shell-escape


I am a complete newbie when it comes to latex and I'm probably missing something obvious here. Any help is much appreciated!

• Welcome to TeX.SX! – yo' Jan 30 '15 at 23:24
• @yo Thanks :) Not new to stackexchange sites in general but I should be sticking around here for a while until I am more proficient with LaTeX ! – Veritas Jan 30 '15 at 23:34
• Well, usually we include a link with the welcome message, that is intended to the newbies. I noticed that you came with 101 rep, so you're not that much new to SE ;) – yo' Jan 30 '15 at 23:38

It seems that minted uses \colorbox for colored background, which is supported by tex4ht, we only need to configure it to support DarkGray color.

Create file hello.cfg:

\Preamble{xhtml}
\Configure{HColor}{DarkGray}{\#1A1A1A}
\begin{document}
\EndPreamble


and compile with

htlatex test.tex "hello" "" "" -shell-escape


\#1A1A1A is hexadecimal value of your dark gray color. Unfortunately, this isn't all what needs to be done. minted package doesn't have it's own configuration file for tex4ht, but uses supported packages, so it more or less works. There is a problem with your example though. Generated code listing doesn't have gray background. Why? It is evident from generated html code:

<p class="noindent" >
<span
class="colorbox" id="colorbox8"></p><div class="minipage"><div class="fancyvrb" id="fancyvrb1"><a


<span class="colorbox"> which is our colorbox is immediately closed by </p> tag! To solve that, we need to configure minted environment to close previous paragraph. This is common issue, see Control the <p> tags added by tex4ht.

Modify the config file:

\Preamble{xhtml}
\Configure{HColor}{DarkGray}{\#1A1A1A}
\ConfigureEnv{minted}{\ifvmode\IgnorePar\fi\EndP}{}{}{}
\begin{document}
\EndPreamble


This closes the paragraph before minted environment, resp. doesn't create one, as in your example there are no paragraphs:

<span
class="colorbox" id="colorbox8"><div class="minipage"><div class="fancyvrb" id="fancyvrb1"><a
id="x1-4r1"></a><span


of course, it still doesn't work, probably because of some html or css rules. Fortunately, solution is easy, we just need to declare span.colorbox to have display:block css property:

\Preamble{xhtml}
\Configure{HColor}{DarkGray}{\#1A1A1A}
\ConfigureEnv{minted}{\ifvmode\IgnorePar\fi\EndP}{}{}{}
\Css{span.colorbox{display:block;}}
\begin{document}
\EndPreamble


and the result:

• Thanks for the incredible answer! I sure have a lot of things to read about. – Veritas Feb 2 '15 at 2:47