2

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}
1
  • 1
    The verbatim environment uses only one font, so you need a monospaced font that contains Latin and Persian glyphs.
    – egreg
    Commented Sep 21, 2012 at 8:04

2 Answers 2

1

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}
6
  • @Reza: Additionally, for more examples and information, you are very welcome to visit the ParsiLatex website. Commented Dec 2, 2012 at 10:57
  • Thanks. This do not work as expected. Even wore than egreg's answer Commented Dec 2, 2012 at 11:03
  • @Reza: See my update. For more information, you can see this topic. Commented Dec 2, 2012 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. Commented Dec 2, 2012 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? Commented Dec 25, 2012 at 9:53
6

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

2
  • 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. Commented Dec 2, 2012 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
    Commented Dec 2, 2012 at 10:38

You must log in to answer this question.

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