3

I try to put together guidelines for linguists. One part concernes typesetting right to left text with the bidi package. I want to use verbatim for the code, but the Persian characters are not printed correctly in the verbatim environment. But the following code does not work. I also had a look at a solution for a similar question, but this did not work either.

\documentclass{article}

\usepackage{fontspec}
\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}
\usepackage{bidi}
\newcommand{\PRL}[1]{\RL{\Parsifont #1}}

\begin{document}

\PRL{او مرد را دوست نخواهد داشت.}

\begin{verbatim}
\usepackage{fontspec}\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}
\usepackage{bidi}
\newcommand{\PRL}[1]{\RL{\Parsifont #1}}

\PRL{او مرد را دوست نخواهد داشت.}
\end{verbatim}


\end{document}

This was the second attempt according to the other suggested solution:

\documentclass{article}

\usepackage{fontspec}
\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}

\usepackage{fancyvrb}
\usepackage{xepersian}

\usepackage{bidi}
\newcommand{\PRL}[1]{\RL{\Parsifont #1}}


\DefineVerbatimEnvironment{rtlverbatim}{Verbatim}{commandchars=+\[\]}

\begin{document}

\PRL{او مرد را دوست نخواهد داشت.}

\begin{latin}
\begin{verbatim}
\usepackage{fontspec}\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}
\usepackage{bidi}
\newcommand{\PRL}[1]{\RL{\Parsifont #1}}

\PRL{او مرد را دوست نخواهد داشت.}
\end{verbatim}
\end{latin}


\end{document}
2

You did not understand the concept of the solution correctly

  1. You should use the new defined verbatim environment rtlverbatim;
  2. Persian text should be surrounded by +PRL[...] to be displayed correctly in verbatim environment.

You may also like to define a separate Persian font for you verbatim Persian text. See XePersian documentation to see the effect.

Your example should be modified like this:

\documentclass{article}

\usepackage{fontspec}
\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}

\usepackage{fancyvrb}
\usepackage{xepersian}

\newcommand{\PRL}[1]{\RL{\Parsifont #1}}


\DefineVerbatimEnvironment{rtlverbatim}{Verbatim}{commandchars=+\[\]}

\begin{document}

\PRL{او مرد را دوست نخواهد داشت.}

\begin{latin}
\begin{rtlverbatim}
\usepackage{fontspec}\newfontfamily\Parsifont[Script=Arabic]{XB Niloofar}
\usepackage{bidi}
\newcommand{\PRL}[1]{\RL{\Parsifont #1}}

\PRL{+PRL[او مرد را دوست نخواهد داشت.]}
\end{rtlverbatim}
\end{latin}


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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