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.

I want to include some Python code into LaTex document, so I "imported" the listings package with

\usepackage{listings}

and

\lstdefinelanguage{Python}{
 keywords={typeof, null, catch, switch, in, int, str, float, self},
 keywordstyle=\color{ForestGreen}\bfseries,
 ndkeywords={boolean, throw, import},
 ndkeywords={return, class, if ,elif, endif, while, do, else, True, False , catch, def},
 ndkeywordstyle=\color{BrickRed}\bfseries,
 identifierstyle=\color{black},
 sensitive=false,
 comment=[l]{#},
 morecomment=[s]{/*}{*/},
 commentstyle=\color{purple}\ttfamily,
 stringstyle=\color{red}\ttfamily,
}

when compiling, I get:

 Illegal parameter number in definition oof \lstlang@python$ }

I googled, but I didn't understood how to work the problem out. it speaks about a command or something similar.

share|improve this question
    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Jun 12 '12 at 14:05
    
add comment

migrated from stackoverflow.com Jun 12 '12 at 13:48

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 10 down vote accepted

In the LaTeX source you posted, you have an error at:

comment=[l]{#},

Change this to:

comment=[l]{\#},

and it compiles for me.

share|improve this answer
1  
Yes, it works to me too. Last question, I indicated keywords. How to get them colored? I just see black line of code, without no color –  FrankBr Jun 11 '12 at 15:18
add comment

I found the following in the Reference Guide of the listings package documentation:

4.1 How to read the reference

...

Regarding the parameters, please keep in mind the following:

...

5.If you want to enter one of the special characters {}#%\, this character must be escaped with a backslash. This means that you must write } for the single character ‘right brace’—but of course not for the closing paramater character.

and also in the following section there is a note

4.18 Language definitions

...

... Note: If you want to enter \, {, }, %, # or & as (part of ) an argument to the keywords below, you must do it with a preceding backslash!

share|improve this answer
add comment

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.