22

When htlatex converts a document, emphasis and bold-face are converted to spans of a certain style which is defined in the accompanying CSS file.

Input:

\documentclass{scrartcl}

\begin{document}
  Normal text

  \em{Emphasized text}

  \textbf{Bold-faced text}
\end{document}

Output (header and footer stripped):

<!--l. 4--><p class="noindent" >Normal text
<!--l. 6--><p class="indent" >  <span 
class="cmti-10x-x-109">Emphasized text</span>
<!--l. 8--><p class="indent" >  <span 
class="cmbxti-10x-x-109">Bold-faced text </span> 

Is it possible to generate "plain" HTML that does not use an external CSS file? Something along these lines:

<!--l. 4--><p class="noindent" >Normal text
<!--l. 6--><p class="indent" >  <em>Emphasized text</em>
<!--l. 8--><p class="indent" >  <b>Bold-faced text </b>

This is for pasting references into another website that already has a CSS.

  • You can also include the css-code inside the html file. Would that be acceptable too? – bodo Sep 4 '12 at 10:09
24

You have to do two things:

you can disable generation of css and ugly elements like

<span 
class="cmti-10x-x-109">Emphasized text</span>

with some command line options:

htlatex filename "xhtml,NoFonts,-css" 

You will then have to provide configurations for em and textit, as they are by default dealt only by css.

This should be done with custom config file, like myfonts.cfg

\Preamble{xhtml}
\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<b>}}{\HCode{</b>}}
\begin{document}
\EndPreamble

Now your htlatex call will be

htlatex filename "myfonts,-css,NoFonts"

Resulting html

<body 
>
<!--l. 4--><p class="noindent" >Normal text
</p><!--l. 6--><p class="indent" >  <em>Emphasized text</em>
</p><!--l. 8--><p class="indent" >  <b>Bold-faced text</b> </p> 
</body></html> 

All command line options of tex4ht are described in this article. There are also other interesting articles about configuring of this system.

For getting rid of <p class="indent">, you can put following to the config file:

\Configure{HtmlPar}
{\EndP\Tg<p>}
{\EndP\Tg<p>}
{\HCode{</p>\Hnewline}}
{\HCode{</p>\Hnewline}}
  • Works for me. But I have two questions: 1. Where did you find the documentation on the -css option? 2. Is there a way to get rid of the class="indent"? – krlmlr Sep 4 '12 at 12:37
  • @user946850 see edit – michal.h21 Sep 4 '12 at 12:59
  • The described code works for me too. But how to get rid off class="likesectionHead" and <a id="x1-1000"></a> from the < h3> tag (similarly from the < h4> tag), of the resulting html: <h3 class="likesectionHead"><a id="x1-1000"></a>2013</h3> <p> </p> <h4 class="likesubsectionHead"><a id="x1-2000"></a>Journal papers</h4> <p> </p> – rasha Jan 1 '13 at 20:08
  • 1
    On my system (WinXP + MixTex), I must give options without spaces in between, as "myfonts,-css,NoFonts" instead of "myfonts, -css, NoFonts". Since I just wasted a lot of time to find this out I thought it might be useful to have this here. – Manu Oct 14 '16 at 13:45
  • @EmanueleViola it works with spaces on Linux, but it is obviously better to not include them. Thanks for pointing that out – michal.h21 Oct 14 '16 at 16:13
1

You can use

htlatex myfile.tex "html,css-in"

This will embed css into the html file.

Note that, you may need to execute the command two times because the "css-in" option uses the .css file generated in the previous call.

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.