2

I want to create a new environment the make my TeX works easier:

\begin{latin}
\begin{lstlisting}[language=python]
    In [1]: x = 1

    In [2]: x
    Out[2]: 1
\end{lstlisting}
\end{latin}

I know listings has some problem for making new environment so it has its own \newlstenvironment, I tried to make new environment using this methods which I find in StackOverflow and on listings documentation but I get same error.

method 1:

\newenvironment{ppp}{%
    \begin{latin} \begin{lstlisting}}{%
        \end{lstlisting} \end{latin}}

method 2:

\lstnewenvironment{ppp}
{\begin{latin}
\lstset{language=python}} { \end{latin}}

Is it possible to create a new environment? How can I do that?

4
  • 1
    What is the latin environment?
    – user31729
    Dec 18 '17 at 14:37
  • When customizing lstlisting, or any other package that typesets stuff verbatim such as fancyvrb, you should strictly adhere to the package documentation. Dec 18 '17 at 14:46
  • latin is an environment from xepersian package that let you write English( left to right direction) in a Persian (right to left direction) Document.
    – Mehdi
    Dec 18 '17 at 14:48
  • The second method is the one that I wrote using package documentation.
    – Mehdi
    Dec 18 '17 at 14:51
3

You need the “internal” form:

\documentclass{article}
\usepackage{listings}
\usepackage{xepersian}

\settextfont{Scheherazade}

\lstnewenvironment{ppp}
  {\latin\lstset{language=python}}
  {\endlatin}

\begin{document}

سلام این یک آزمون است.

\begin{ppp}
In [1]: x = 1

In [2]: x
Out[2]: 1
\end{ppp}

سلام این یک آزمون است.

\end{document}

enter image description here

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.