4

I use polyglossia in arabic tex files and I want to use the verbatim environment to write the Latex commands for a user's manual. All works well, with adding the command '\let\arabicfonttt\ttfamily' if we write english characters but it doesn't recognize I think the arabic character. How I can I fix it ? I give a simple example, where we can see that arabic letters are completely omitted.

\documentclass[12pt,a4paper]{article}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}
\begin{document}

\begin{english}
\begin{verbatim}
The command \LaTeX prints the Latex logo.

أمر
\LaTeX
يعطي لوجو لاتخ
\end{verbatim}
\end{english}
\end{document}

One can see that only the word \LaTeX of

أمر

\LaTeX

يعطي لوجو لاتخ

is taken in account enter image description here

1
  • Besides \let\arabicfonttt\ttfamily you have to do \setmonofont{DejaVu Sans Mono} or any other monospaced font supporting Arabic.
    – egreg
    Oct 17, 2014 at 16:13

2 Answers 2

3

Besides \let\arabicfonttt\ttfamily you have to do \setmonofont{DejaVu Sans Mono} or any other monospaced font supporting Arabic.

\documentclass[12pt,a4paper]{article}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}
\begin{document}

\begin{english}
\begin{verbatim}
The command \LaTeX prints the Latex logo.

أمر
\LaTeX
يعطي لوجو لاتخ
\end{verbatim}
\end{english}
\end{document}

enter image description here

3
  • 1
    It seems ok on a try file what I have done but there is still a problem : The arabic words must be in Right to left environment... we can solve this problem by doing two verbatim, one for arabic and it's written in Right to Left mode and one for english between \begin{english} and \end{english}... The question is : can we write an english sentence in Left to Right mode and an arabic one in Right to Left mode in the same verbatim ? Oct 17, 2014 at 22:14
  • @FaouziBellalouna Sorry, but that's as much as I can help: my knowledge of Arabic doesn't go beyond the fact it's written right to left.
    – egreg
    Oct 17, 2014 at 22:15
  • Ok the problem which remains is minor for me. Thanks Oct 17, 2014 at 22:25
4

We can do this with listings package, putting arabic words inside symbols defined with escapeinside like this :

\documentclass[12pt,a4paper]{article}
\usepackage{listings}
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\lstset{language=[LaTeX]TeX,escapeinside={*}{*}}

\begin{document}

\begin{english}
\begin{lstlisting}
The command \LaTeX prints the Latex logo.
*\textarabic{أمر}*
\LaTeX
*\textarabic{يعطي لوجو لاتخ}*
\end{lstlisting}
\end{english}
\end{document} 

and the result:

enter image description here

1

You must log in to answer this question.

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