Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How I can insert Persian text in verbatim environment when using XePersin package ( v11.138, 2012/05/03). Following code dose not work:

\begin{verbatim}

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<book>
  <bookinfo>
    <title> عنوان کتاب </title>
    <author>
    </author>
  </bookinfo>
 محتوای کتاب
</book>

\end{verbatim}
share|improve this question
1  
The verbatim environment uses only one font, so you need a monospaced font that contains Latin and Persian glyphs. –  egreg Sep 21 '12 at 8:04

2 Answers 2

up vote 2 down vote accepted

Try the following code by Vafa Khalighi:

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{xepersian}
\settextfont{XB Niloofar}
\DefineVerbatimEnvironment{myverbatim}{Verbatim}{commandchars=+\[\]}
\begin{document}
%\begin{latin}
\begin{myverbatim}

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<book>
  <bookinfo>
    <title> +rl[عنوان کتاب] </title>
    <author>
    </author>
  </bookinfo>
+rl[ محتوای کتاب]
</book>

              +rl[دکتر] 

\end{myverbatim}
%\end{latin}
\end{document}
share|improve this answer
    
@Reza: Additionally, for more examples and information, you are very welcome to visit the ParsiLatex website. –  Vahid Damanafshan Dec 2 '12 at 10:57
    
Thanks. This do not work as expected. Even wore than egreg's answer –  PHPst Dec 2 '12 at 11:03
    
@Reza: See my update. For more information, you can see this topic. –  Vahid Damanafshan Dec 2 '12 at 11:14
    
@Reza: Yes, it is. By the way, if everything is OK with my code above, you should accept it as your answer, according to the site's rule. –  Vahid Damanafshan Dec 2 '12 at 13:15
    
Is [ ] wrappers really needed, in your linked page Khalighi presented a not working code that dose not have any wrapper inside verbatim environment, can you also fix that solution too? –  PHPst Dec 25 '12 at 9:53

The verbatim environment uses only one font, so you need a monospaced font that contains both Latin and Persian glyphs. Here's an example (but I don't know Persian, so it might be not perfect):

\documentclass{article}
\usepackage{fontspec}
\setmonofont{FreeMono}

\begin{document}
\begin{verbatim}

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<book>
  <bookinfo>
    <title> عنوان کتاب </title>
    <author>
    </author>
  </bookinfo>
 محتوای کتاب
</book>

\end{verbatim}

\end{document}

enter image description here

share|improve this answer
    
Thanks, Persian is a RTL languages. The issue is 'عنوان کتاب' in text is rendered as 'کتاب عنوان' in PDF, usually Persian files use XePersian package in general, but even when I use it verbatim environment have the issue yet, Perhaps there is a config that I forget to set. –  PHPst Dec 2 '12 at 4:49
    
@Reza I'm afraid that this is an inherent limitation of the verbatim environment, where it's quite difficult, as it is now, to change the writing direction. :( –  egreg Dec 2 '12 at 10:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.