# Convert to HTML with {arabtext} sections rendered as images

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:

\documentclass{article}
\usepackage{arabtex}
\usepackage{utf8}
\begin{document}

Hello world

\setcode{utf8}
\begin{arabtext}
السَلامُ عَليكم
\end{arabtext}

Goodbye World!

\end{document}


Here's the output with pdflatex:

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

Generated HTML source:

<!--l. 7--><p class="noindent" >Hello world
<span
class="xnsh-14"></span><span
class="xnsh-14">J</span><!--l. 13--><p class="indent" >
<span
class="xnsh-14"></span><span
class="xnsh-14"></span><!--l. 13--><p class="indent" >
<span
class="xnsh-14"></span><span
class="xnsh-14"></span> <!--l. 13--><p class="indent" >
<span
class="xnsh-14"></span> <span
class="xnsh-14"></span><span
class="xnsh-14">C</span> <!--l. 13--><p class="indent" >
<span
class="xnsh-14"></span> <span
class="xnsh-14"></span><span
class="xnsh-14">@</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.

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:

\Preamble{xhtml}
\ConfigureEnv{arabtext}{\HCode{<div class="arabtext">}\Picture+{}}{\EndPicture\HCode{</div>}}{}{}
\Css{.arabtext{text-align:right;}}
\begin{document}
\EndPreamble


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:

• 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? – Abdullah Jibaly Jul 3 '15 at 12:06
• @AbdullahJibaly see tex.stackexchange.com/a/43801/2891 for image resolution settings – michal.h21 Jul 3 '15 at 13:08

Another option

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE,OT1]{fontenc}
\usepackage[arabic,english]{babel} %default language is last in list
\begin{document}
Hello world

\begin{otherlanguage}{arabic}
السَلامُ عَليكم
\end{otherlanguage}

Goodbye World!
\end{document}


and compile with htlatex foo.tex and the output is

reference: Arabi package

This does not use images. Looking at the HTML:

<!--l. 11--><p class="noindent"  dir="ltr" >Hello world
<!--l. 14--><p class="indent"  dir="rtl" >   <span