# Arabic font for Listing

Currently, I am using Listings package in order to insert my XML text in the document.

For example the code:

\begin{lstlisting}
<Product Title="نوکیا" Type="گوشی">
\end{lstlisting}


The problem in here is that Listings does not support Arabic font. As a result 'نوکیا' and 'گوشی' can not be shown. Is there any solution to make Arabic font be supported by the Listings package?

• Which TeX format do you use: pdfLaTeX, XeLaTeX, LuaLaTex, or something else? Please advise. – Mico Jun 3 '14 at 21:19
• @Mico I use XeLaTex – Pedram Jun 4 '14 at 1:25

One of solution is this. first define your listingstyle like this before \begin{document}

If your main Language is persian then:

\documentclass[11pt]{book}
\usepackage{listings}
\usepackage{xepersian}

\lstdefinestyle{MyXML}{
language=XML,
escapeinside={\%*}{*)},
morekeywords={encoding,
xs:schema,xs:element,xs:complexType,xs:sequence,xs:attribute}
}


then in your listing code use this code

مقاله من فارسی می‌باشد
\begin{latin}
\begin{lstlisting}[style=MyXML]
<Product Title="%*\rl{نوکیا}*)" Type="%*\rl{گوشی}*)">
\end{lstlisting}
\end{latin}
انتهای مقاله


here is my output

If your main language is English then:

\documentclass[11pt]{article}
\usepackage{setspace}
\usepackage{listings}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage{english}
\setotherlanguage{farsi}

\lstdefinestyle{MyXML}{
language=XML,
escapeinside={\%*}{*)},
morekeywords={encoding,
xs:schema,xs:element,xs:complexType,xs:sequence,xs:attribute}
}


My Article is In English Language

\begin{lstlisting}[style=MyXML]
<Product Title="%*\textfarsi{نوکیا}*)" Type="%*\textfarsi{گوشی}*)">
\end{lstlisting}

End of Article


and the output

• I get this error while I am trying to compile: Environment latin undefined. what is the problem? – Pedram Jun 4 '14 at 1:24
• @Pedram your article is in Persian ? or English ? if your main language is English just don't use \begin{latin} and \end{latin} – Karo Jun 4 '14 at 6:26
• Thanks for your help. My article in is English. There are only a few cases that I use Persian as the value of an attribute in my XML. I did exactly what you said. But I did not get the answer. Take a look at this picture: 4shared.com/photo/KOVxBes-ce/1__1_.html – Pedram Jun 4 '14 at 10:04
• @Pedram is this working now ? – Karo Jun 4 '14 at 11:23

I think it's easy to create the document with arabtex package. Arabic word/sentence is typed between \< and >. So, we need to define escapeinside character for listings package.

\documentclass{article}
\usepackage{arabtex}
\usepackage{utf8}
\usepackage{listings}

\lstset{escapeinside=}

\begin{document}
\setcode{utf8}

\begin{lstlisting}
<Product Title="\<نوکیا>" Type="\<گوشی>">
\end{lstlisting}

\end{document}