[Tex/LaTex] How to highlight arabic texts with allowing line breaks

arabichighlightingline-breaking

I would like to highlight some texts. For Latin texts the \hl command of the soul package works well, but not for Arabic texts.

(\hl{SOME ARABIC TEXT} has only a small line as output in the pdf file.)

I could use \colorbox{yellow}{ARABIC TEXT} but it doesn't allow line breaks.

(The command \uline of the ulem package works for Arabic text too, so maybe it is not so difficult to get an "Arabic" \hl?)

(Perhaps the code of Leo Liu could be helpful: It makes some yellow boxes which cover the Arabic texts.)

I'm using xelatex (TeX Live 2012). Here is a minimal example:

\documentclass{article}
\usepackage{xcolor} 
\usepackage{ulem,soul}
%\usepackage{fontspec,color,xcolor,hyperref,xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{arabic}
\setotherlanguages{german}
\newfontfamily\arabicfont[Script=Arabic]{Times New Roman}

\begin{document}

\begin{german}
Highlighting works for \hl{latin texts}.
\end{german}

\hl{عربي} % you will just see a vertical small yellow line

\end{document}

EDIT: With this code:

\documentclass{article}
\usepackage{xcolor} 
\usepackage[normalem]{ulem}
%\usepackage{fontspec,color,xcolor,hyperref,xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage{arabic}
\setotherlanguages{german}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Times New Roman}
\newcommand\hl{\bgroup\markoverwith % 
  {\textcolor{yellow}{\rule[-.5ex]{2pt}{2.5ex}}}\ULon}


\begin{document}
\begin{german}
Test \hl{for highlighting} text. %correct
\end{german}
\hl{عربي} % correct

\hl{عربي} % result: yellow box covers the word
\end{document}

I get the result:

arabicTest

So, in the first line the highlighting of the arabic text is correct – does someone know how to modify the code to make the hightlighting correct in the second line too?

Best Answer

As mentioned in comments:

It is very unlikely that you can do this due to \special bug/problems of TeX--XeT in RTL mode.

The way that specials are handled by the TeX--XeT model (currently) used by XeTeX means this can't really be done.