3

So I was trying to use the listings package for LyX in order to create something as following:

enter image description here

After some research (link) I saw a suggestion to do the following steps:

In settings->LaTeX Preamble I added the following code:

\usepackage{listings}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

Then I created a TeX box and added the following code:

\L {
    \lstset{
    tabsize=3,
    frame=shadowbox,
    rulesepcolor=\color{gray},
    xleftmargin=20pt,
    framexleftmargin=15pt,
    numbers=left,
    numberstyle=\tiny,
    numbersep=5pt,
    breaklines=true,
    showstringspaces=false,
    basicstyle=\footnotesize,
    emphstyle={\color{magenta}}
}
    \begin{lstlisting}
    def some_function(parameter):
        a_random_number = parameter - 10
        print "some random string" + str(a_random_number)
    # And a random comment!
    if __name__ == '__main__'
        print 'Hello Latex Listings package'
        some_function(20)
    \end{lstlisting}
}

Please notice that I use L{} because my LyX is defined RTL (to support hebrew).

I compile with pdflatex and get the following output:

enter image description here

What should I add/change in order to get the expected output? I don't really care about the highlight per language.

1 Answer 1

1

I copy pasted your code, suppressed the \L, added a documentclass and send it to pdflatex. And I got something perfect.enter image description here

I do no use Lyx, but I doubt it can be a problem. Maybe an interaction with RTL. Listings seem to require to be in a LTR environement (see lstlisting caption problem with xepersian). Try to change that.

You must log in to answer this question.

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