{listings} is a package that extends LaTeX's {verbatim} features. A variety of syntax highlighting options are available. For general questions about {verbatim} or {highlighting} use the respective tag. For the unrelated concept of list structures, use {lists} instead.

learn more… | top users | synonyms

3
votes
3answers
2k views

add vdots to a listing without breaking the box

I have a problem when I try to add \vdots in an escaped string inside of a listing environment. The box is cut. How can I avoid the break of the box? The code is this: ...
0
votes
1answer
608 views

Align normal text inside a listing

I need a way to correctly align the escaped strings that I put inside of this listing. The problem is that they are presented right aligned. I want that this lines keep the indentation of the previous ...
3
votes
1answer
658 views

Visual separation when using linerange in listings

I have read through the listings documentation and couldn't find an answer to the following question: How do I insert some sort of visual feedback in a listings listing when using the linerange ...
7
votes
1answer
1k views

listings package - Can I include a backslash \ in language keyword (\begin) for syntax highlighting in LaTeX code?

I want to highlight a LaTeX code (including backslash \, e.g. \begin). Unfortunately, by default a LaTeX listings package does syntax highlighting only keywords WITHOUT back slash (e.g. begin).
14
votes
1answer
9k views

Automatically resize lstlisting fontsize in a beamer slide

I have frames of the following format (code followed by an itemize): \begin{frame}[fragile] \frametitle{Blah} \begin{lstlisting} Five to seven lines of code here... \end{lstlisting} ...
7
votes
1answer
2k views

Listings package: How to highlight math operators?

I am using the listings package to include GAUSS code to Latex. E.g. like this: \lstset{ emph={proc,retp,endp,local}, emphstyle=\color{blue}\textbf, emph={[2]=,.^,./,=}, emphstyle={[2]\color{red}} } ...
6
votes
1answer
264 views

Where can I find the documentation for `lstdoc`?

It appears that the listings package provides another package, called lstdoc, which in some unknown fashion provides facilities for printing TeX code samples while simultaneously TeXing them into the ...
7
votes
2answers
2k views

Fixed Width Font with LTXexample environment

Not sure why this problem has eluded me but I can't seem to get fixed width font in the code portion. I thought that this question on how to change code font would do the trick but it doesn't for me. ...
14
votes
3answers
4k views

How to insert a nice tilde in a lstlisting?

How do I insert a nice tilde that is centered in the middle in a lstlisting? I found another thread about tildes but I can't apply it because the method described there only works outside of ...
2
votes
3answers
2k views

Any ideas why this \newcommand{\n}{\lstinline|\n|} macro doesn't work?

So I created a new macro \newcommand{\n}{\lstinline|\n|} but for some reason when I use it, all I get is bold 'n' letter and not a nice \n. Any ideas?
12
votes
1answer
10k views

How to make inline listings wrap nicely?

Does anyone know how to make inline listings wrap nicely? Take a look at the screenshot that I attached below. The code example in the second line goes outside the text margin. Also, any ideas why ...
12
votes
1answer
8k views

How to change code example font in listings?

Does anyone know how to change the font for code snippets in the listings package? I'd like to have a constant width font, rather the fancy variable-width looking font that it has by default.
4
votes
1answer
682 views

How to make sure I get regular ASCII quotes in code examples when using `listings`

So I am writing a book on AWK and when using listings code highlighting module, I get the fancy quotes “ ” and ‘ ’ instead of the regular ASCII ones " " and ' '. I hate these fancy quotes because when ...
6
votes
1answer
3k views

How to increase the padding in the code snippet box when using `listings`?

So I am writing a book on Awk programming language, and I have enabled a single frame via \lstset{frame=single}. However, I would like the code within the snippet box to be further away from the frame ...
3
votes
1answer
2k views

How to change frame color in listings package?

I am using listings package for code highlighting and I want to have a different color frame around my code examples. Any ideas how to do it? There is backgroundcolor but there isn't framecolor so I ...
1
vote
1answer
312 views

Passing listing-environment as option to command [duplicate]

I have a simple command which takes one argument. Now I want to pass a small listing-environment to the command. Here is the code: \documentclass{article} \usepackage{listings} \begin{document} ...
4
votes
2answers
2k views

newenvironment/newcommand for existing environment in LaTeX-Beamer

I would like to have the solution of highlighting a line in listings-package as a command or environment. To bad I cannot get it working. I tried: a simple newenvironment: compile errors ...
8
votes
1answer
14k views

Problem with special characters in listings

I'm having problems with my TeX document. I'm trying to import my java file in listings to get syntax colouring and stuff. My java files contains comments in Danish, which means they contain special ...
2
votes
1answer
144 views

Increase listings spacing through the package listings or use figure instead?

This is more a conceptional question on how to use LaTeX in the right way. So far I have striven to customize only those things in LaTeX which are supposed to be without messing to much with print ...
5
votes
1answer
1k views

UTF-8 (BMP character set) support in listings.

I'm submitting a paper to a journal using LaTeX, and I need to be able to write Unicode symbols into listings. So far, I've been able to get by with the moreverb package. It's listing environment is ...
2
votes
1answer
2k views

LyX: listings over multiple pages [closed]

I am trying to use LyX to insert child document-listing-program. The program imports OK but it is too long to fit on a single page. At the bottom of the page it outputs over the margin, sometimes ...
15
votes
1answer
1k views

Source Code Margin Comments

In the paper "Beautiful Code Compelling Evidence", by J.R. Heard -- Code is formated in a particular way which includes margin comments. I am looking for a way to do this as I think it is a very clear ...
7
votes
1answer
518 views

Problems with multi-page \lstlistings and \footnotes with the liuthesis document class

Using the liuthesis document class described at http://www.control.isy.liu.se/student/exjobb/liuthesis/liuthesis.html (download link: ...
3
votes
1answer
1k views

Highlight language keywords in a paragraph?

While it is possible to highlight specific language keywords (such as public in C++) by using lstinline command from listing package as in: Highlighting a C++ keyword \lstinline|public| in a ...
5
votes
1answer
3k views

Where to find updated listing 'lstpatch.sty'?

I'm wondering where to find updated patch files, in particular lstpatch.sty verson 1.4? It seems many packages doesn't come with the file, and my updated TexShop keep asking for the latest version ...
23
votes
6answers
12k views

Highlight text in code listing while also keeping syntax highlighting

I’m using the listings package for code listings. Now I try to highlight some part of the code using \hl from the soul package. Here’s an example of a resulting query where the injected part of a SQL ...
4
votes
1answer
868 views

\fbox inside listings

I am trying to highlight a specific line inside a listing with listinline. The code I am currently using looks like this: \begin{lstlisting}[escapechar=!] class A { void m() { B b = ... ...
5
votes
1answer
960 views

Wrap latex environment

I'm a beginning latex user. I have some programming code in my document which I format using the lstlisting environment from the package listings. However this still allows the code segments to be ...
1
vote
1answer
958 views

How to set rulecolor in a listings frame only for the top line?

I use the following lstlisting (listings package): \documentclass{thesis} \usepackage{ucs} \usepackage[utf8]{inputenc} \usepackage{url} \usepackage{bbding} \usepackage{listings} \usepackage{tikz} ...
16
votes
2answers
16k views

Source code listing with frame around code?

I'd like to make my code listing looking more sexy. I found a good example on SO, but one problem is remaining: I would like to not only have a horizontal line at the bottom of the listing but also ...
3
votes
1answer
727 views

Listings for Tikz code?

I am trying to quote (not compile!) LaTeX code (including TikZ code) within a LaTeX document. The verbatim package works, but it doesn't wrap text and doesn't look very nice. So I am trying to use ...
12
votes
3answers
3k views

Listing: Syntax highlighting for SPARQL query?

I use the following listing to show a SPARQL query: \begin{lstlisting}[captionpos=b, caption=SPARQL query, label=lst:sparql] PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#> ...
3
votes
1answer
1k views

Custom numbering of listings

I have a number of listings in my document, numbered 1, 2, 3 and so on. I need a table with three listings (say, three different variants of the same algorithm), that will be numbered as 2a, 2b, 2c. ...
2
votes
1answer
488 views

Multipages side by side listings

Could you tell me what should I do to be able to insert multipages, side by side listings in Latex document? I have already tried with \begin{minipage}, but it doesn't work with multipages. EDIT: ...
6
votes
2answers
990 views

How to avoid that listings are interrupted by floats?

And again I have another problem I just can't figure out. I defined a listing with some XML code: \begin{lstlisting}[captionpos=b, caption=XML detection strategy for Refused Parent Bequest, ...
5
votes
1answer
1k views

Aligning function arguments in “algorithm” environment.

In the "algorithm" environment, when a function call spans multiple lines, I would like to have its arguments aligned, like so: MyFunction(long_arg_name0, long_arg_name1, ...
7
votes
1answer
1k views

Building keyval arguments using a macro.

I try to create the arguments for a package which uses keyval, with macro, but this does not work: Here is the demo code: \documentclass{minimal} \usepackage{listings} \lstset{language=Pascal} ...
12
votes
2answers
2k views

How to insert code and graphic in textbox

I want to put a graphic and a little linux bash code in a textbox, like the picture blow... with the follow in problem: all in a textbox with yellow backgroud left part is a graphic (a finger)... ...
11
votes
2answers
5k views

XML highlighting - different style for attributes

I need to highlight syntax in my LaTeX presentation, so I've found this answer: XML syntax highlighting \lstdefinelanguage{XML} { morestring=[b]", morestring=[s]{>}{<}, ...
4
votes
1answer
2k views

`backgroundcolor` in `lstset` does not work

When I use the backgroundcolor option in lstset, all I get is a colored line above the listing: \lstset{% language=Matlab, backgroundcolor=\color{blue} } and in the document: ...
10
votes
1answer
5k views

How can I escape % in a lstlisting?

I have a little lstlisting to show a snippet of code but since the code has % in it for modulo calculation the listing breaks down. How can I escape it? I have tried the backslash, verbatim and \text ...
6
votes
1answer
1k views

How do I remove keywords in package listings?

Sure enough, there is a morekeywords option, but suppose I need to remove some? A case in point is Pascal, in which Writeln is not (strictly speaking) a keyword, but rather a predefined procedure. I ...
6
votes
2answers
2k views

Listings alternative

Well like the title says I am asking if there is an alternative to the listings package. With more programming language definitions and the likes, and updated definitions for the current languages.
4
votes
1answer
990 views

lstlistoflistings font

I'd like to change my list of listings to match my list of figures, which I have changed using tocloft: \renewcommand{\cftfigfont}{\sffamily\mdseries\upshape} Is there a way to do the same with my ...
2
votes
2answers
670 views

ignorespace and unskip in verbatim/listings?

I am writing a \bashDemo macro that will (a) execute its argument in a shell, e.g., bash, script, and (b) display the argument in a listings. So, \bashDemo ls -ls > myfiles \END will both run ls ...
4
votes
1answer
2k views

Listings package not correctly showing PHP strings

I'm trying to display some PHP code in a LaTeX document using the listings package. Other languages appear fine (HTML for instance) but PHP seems to be ignoring any strings within the code. The rest ...
11
votes
2answers
3k views

How can I remove “Listing #: ” from listings caption?

I am working on a C++ reference manual for myself and I want good-looking listings. The Stack Overflow question entitled LaTeX source code listing like in professional books was very helpful but, for ...
10
votes
2answers
6k views

listings with background color and mathescape broken

I have a listings environment in my document with backgroundcolor=\color{grey} to get a nice grey background and mathescape=true for using math symbols. However when using the \vdots command inside a ...
6
votes
3answers
2k views

Using keywords including a dot in the name with the listings package

I am using the listings package which works like charm in most cases. I tried to define new languages for my needs with the help of morekeywords options in \lstset, but entering special keywords ...
16
votes
3answers
3k views

Preferred method for inline code samples

I tend to use the minted package for including code samples within my documents, which produces very nice output. However, because Pygments always produces a verbatim environment there's no way to ...