This is a question about getting colors with tex4ht. The issue was discussed e.g. here, where a suggestion was made, which however I can't get to work. I asked a comment there and it was suggested to make a new question, so here it goes:

Can you give a working example of a config file with a working syntax for \Configure{HColor}{colorname}{csscode}, I can't get it to translate \textcolor{red}{blah} properly.

More precisely, if I have:








and I compile with tex4ht I get

    <?xml version="1.0" encoding="iso-8859-1" ?>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->   <html xmlns="http://www.w3.org/1999/xhtml"   >  <head>    <title></title>  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  <meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />  <meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />  <!-- html,xhtml,-css,NoFonts -->  <meta name="src" content="post2.tex" />  <meta name="date" content="2017-09-07 08:56:00" />  </head>
<body  > <p style="text-align:justify"><span class="paragraphHead"><a   id="x1-1000"></a><span id="textcolor1">WARNING</span></span>    </p>    </body></html>                                                                                

which does not look red on a browser. Note the command

<span id="textcolor1">WARNING</span></span>

My htlatex options are xhtml,-css,NoFonts

  • You disable generation of the css file with the -css option.
    – michal.h21
    Sep 7 '17 at 13:08
  • How can I have colors with the -css option?
    – Manu
    Sep 7 '17 at 13:48
  • Why don't you want to use the CSS file? It wouldn't be possible in an straight-forward way.
    – michal.h21
    Sep 7 '17 at 14:33
  • Because free wordpress does not support it. Is it really so hard to tell tex4ht how to interpret the textcolor command?
    – Manu
    Sep 7 '17 at 15:07
  • I found a way hot to do it, see the updated answer
    – michal.h21
    Sep 7 '17 at 20:05

If you use xcolor package, you shouldn't need to configure anything, colors should work out of the box:


Helo world \textcolor{red}{blah}. And I can use \textcolor{mycolor}{my color}.

enter image description here

If you really want to redefine it in the .cfg file, you need to use valid CSS color declaration, like #0012FF. You must escape the # character:


enter image description here


tex4ht saves the colors in the CSS file. Because you don't want to use the CSS file, we must use a trick to save the colors directly in the style attribute of element around the colored text. Try this .cfg file:

\Configure{textcolor}{\HCode{<span style="color:\#\tsf@color;">}}{\HCode{</span>}}

% redefine \textcolor command

  % we need to convert the current color to hexadecimal form usable in the style attribute
  % the \tsf@color macro is used in the \Configure{textcolor} configuration to insert the
  % CSS color
  % call the original command

It produces the following HTML:

<p class="noindent" >Helo world <span style="color:FF0000;">blah</span>. And I can use <span style="color:FF3333;">my color</span>. </p> 
  • It still doesn't work for me. I added a MWE that shows my output. I tried both with xcolor and without. Maybe there's something in my options that's wrong?
    – Manu
    Sep 7 '17 at 13:01
  • Beatiful, thanks, it works! For some reason it doesn't work if I apply it to section headers, but I haven't debugged.
    – Manu
    Sep 7 '17 at 21:02

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.