I'm just starting to investigate using latex to generate an ebook with arabic snippets embedded in it, and I'm using the following simple document:


Hello world

السَلامُ عَليكم

Goodbye World!


Here's the output with pdflatex:

pdflatex output

When I try converting to html, here is the garbled output:

htlatex output

Generated HTML source:

<!--l. 7--><p class="noindent" >Hello world
class="xnsh-14">J</span><!--l. 13--><p class="indent" >
class="xnsh-14"></span><!--l. 13--><p class="indent" >
class="xnsh-14"></span> <!--l. 13--><p class="indent" >
class="xnsh-14"></span> <span 
class="xnsh-14">C</span> <!--l. 13--><p class="indent" >
class="xnsh-14"></span> <span 
<!--l. 16--><p class="indent" >   Goodbye World!

What I want is to render the arabic as an image (that looks like the pdf-rendered version) and have that image in the html source. Something like:

<span>Hello world</span>
<img src="foo.png" />
<span>Goodbye World!</span>

What's the best way to tackle this issue? I'm completely new to latex but don't mind if the solution requires some programming for pre-processing on my end.

1 Answer 1


It is quite easy to produce images with content of any environment. Any TeX content can be converted to image with \Picture+ ... \EndPicture commands, so we only need to configure arabtext environment to use these commands. Save following code as arab.cfg:

\ConfigureEnv{arabtext}{\HCode{<div class="arabtext">}\Picture+{}}{\EndPicture\HCode{</div>}}{}{}

This code will create <div class="arabtext"> element and all content of the environment is converted to image. The image is then aligned to the right using CSS.

Compile with

htlatex filename arab

The result:

enter image description here

  • Thanks, this is super helpful. The only issue I have is the image resolution seems to be very low, how can I get a higher resolution image generated from the \Picture+ command? Commented Jul 3, 2015 at 12:06
  • 1
    @AbdullahJibaly see tex.stackexchange.com/a/43801/2891 for image resolution settings
    – michal.h21
    Commented Jul 3, 2015 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .