{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

15
votes
2answers
2k views

Colored background in inline listings

I would like to make inline code more distinguishable from the text surrounding it, and I thought that using a background might work (like it is done on the stackexchange pages.) Since I use the ...
4
votes
2answers
2k views

How to prevent a \lstinputlisting being split across pages?

This question shows how to prevent a long listing from being split across several pages when the code is written directly into the tex file. I want to achieve the same effect when including code in ...
5
votes
2answers
1k views

Background overflows when using rounded corners for listings (package: `listings`)

I'm using listings to list code in my document, and I want the code to be displayed in a frame with rounded corners and a grey background color. But the background overflows the frame, as if the frame ...
16
votes
5answers
11k views

Using bold/italic text inside listings?

How can I use bold text inside a code listing? I wanted to make some parts of the code bold.
7
votes
2answers
295 views

How to emphasize within a listing two successive identifiers separated by a space?

I have this pgfplots code that I want to put in a lstlisting environment: \pgfplotsset{ every axis x label/.append style = { font = \small }, every axis y label/.append style = { ...
4
votes
3answers
2k views

Customizing the list of listings generated by \lstlistoflistings?

I'm using listings in my document, and its command \lstlistoflistings to generate the list of listings. The problem is that I've customized all the other lists (TOC, LOF and LOT). More precisely, I've ...
1
vote
1answer
368 views

Why does pdfLaTeX fail when I try to use `begin{lstlisting}` inside a user-defined environment?

I'm having trouble with the listings package. I can't compile the following minimal example through pdfLaTeX: \documentclass[a4paper, 11pt, twoside, openright, english]{memoir} \usepackage{listings} ...
5
votes
1answer
340 views

Listing index uses wrong dashes

When generating an index of all my Listings, the library seems to use the wrong dashes to connect words: Expected Unported-2.0-Graphic Actual Unported—2.0—Graphic In the title of the listings, ...
3
votes
3answers
415 views

How to emphasize with in a listing an identifier containing a digit?

I have this LaTeX code that I want to typeset using listings: \documentclass[paper=a4,fontsize=12pt,version=last]{scrlttr2} I want to emphasize "scrlttr2" with a different format. How can it be ...
6
votes
3answers
995 views

Smaller frame with listings

I am using listings to put java code in my beamer slides. Sometimes, I want to frame the code but I do not want the frame to occupy the whole width of the page. I want the frame to occupy only the ...
9
votes
1answer
7k views

How to create beamer slides with source code that can be copied?

We are converting our course slides from Powerpoint to LaTeX, to be able to offer all code in a more open format and to let students easily copy code from the slides. However, the latter does not seem ...
6
votes
1answer
892 views

Problems with column alignment in the `lstlisting` environment

I'm having some problems with the column alignment in the lstlisting environment provided by listings.sty. In fixed-width column alignment mode, whatever the typeface being used, listings are ...
2
votes
1answer
336 views

Why compilation with a lot of \lstinputlisting is so slow?

I'm using a lot of \lstinputlisting in my document and the compilation of it is really slow. Why it takes so long? How could I make things better?
13
votes
1answer
4k views

How can I use LaTeX-commands inside of a listing?

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the ...
7
votes
2answers
2k views

Disable keyword highlighting in lstset

I have the following lstset defined for my listings \lstset{ numbers=left, numberstyle=\scriptsize, tabsize=4, rulecolor=, language=java, ...
5
votes
2answers
3k views

How do I prevent LaTeX from showing a whitespace following a quote when in an lstlistings environment? [closed]

When I am inside the lstlistings environment, it seems that using a quote such as (') or (") will toggle on the showing of whitespace indicators (small little half rectangles). Am I doing something ...
2
votes
1answer
2k views

How to highlight own keywords in HTML lstlistings?

I would like to highlight some words in a lstlisting. The language is HTML. However, \emph seems not to be working with HTML. Any suggestions how I could work around this problem? Right now I have: ...
3
votes
1answer
2k views

Listings in table of contents

I'm struggeling a little bit with the display of table of contents. I had previously a problem using natbib , and now the same issue with listings. Maybe I'm mixing something up with documentclass ...
1
vote
2answers
581 views

Latex escape interrupts frame of listing

I am (ab)using a framed listings environment include an enumeration environment (by escaping to latex). This compiles fine but in the resulting pdf the frame around the listing is interrupted. ...
3
votes
1answer
442 views

Error when using equations and mathescape in source codes using the listings package

I want to write equations within source code that i formatted with the listings package. Therefore I use mathescape=true. The strange thing is, that it only works when I change the language of my ...
2
votes
1answer
1k views

Emphasizing words within a string using the listings package in LaTeX

I'm using the listings-package for LaTeX to format source-codes within my document. I can emphasize keywords using the emph-option of the listings package: \lstset{ emph={nerv}, ...
8
votes
3answers
10k views

How to use different lstset settings for listings?

I would like to specify two different lstset settings in one latex file: one for java code, one for html. Is this somehow possible? The solution of ...
11
votes
2answers
2k views

The 'listings' package and UTF-8

Please, do you know if there's any possibility how to use the listings package together with XeLaTeX? I have to use XelaTeX and therefore I have UTF-8 encoded files. This is not compatible with ...
3
votes
2answers
2k views

How to use a comma in lstlisting keywords?

I am creating a language for the doxygen tool. I need to create a set of new keywords. When I try to use the comma in one of them, it does not highlighting. I protect comma with a backslash, but it ...
4
votes
2answers
2k views

How to get autoref working with different counters for different listing environments?

In my document I want several different custom listing environments. The solution from fraktalek works like a charm, except for one thing: \autoref doesn't work for me. I have tried the following: ...
1
vote
1answer
306 views

lstinline error “ended by EOL” in dtsyntax

I'm using the package dtsyntax to highlight code text based on listings. For in-line annotation they make a new command \modelica{ } based on lstinline as follows : ...
22
votes
4answers
7k views

Having problems with listings and UTF-8. Can it be fixed?

I'm having some problems with listings and UTF-8 in my document. Maybe someone can help me? Some characters work, like é and ó, but á and others appear at the beginning of words... ...
3
votes
1answer
749 views

multicols, lstlisting and float

Using the following structure, how can I get the listing to stay on the same page, be it at the top or the bottom? \documentclass{scrartcl} \usepackage[ngerman]{babel} \usepackage{multicol} ...
3
votes
1answer
833 views

Help with deletekeywords in Listings package

Using the listings package, I can use deletekeywords to remove keywords, and so the keyword is not rendered in bold. For example, the for from the following is not in bold font: ...
4
votes
1answer
460 views

Listings, literate, and space at the start of the line.

I am trying to use the literate option to replace the prompt (>>>) and continuations (...) in python input with symbols that "hang" in the margin. I can almost do this with something like ...
5
votes
1answer
447 views

Listing, zebra effect and broken lines

In Creating a zebra effect using listings, I've found one solution to produce a zebra effect for listing. Unfortunately, this only works if the lines are not broken. Is there a way to fix this? Here ...
2
votes
1answer
168 views

Bug with framed, listings and xcolor are together

When using a combination of the packages framed, listings, and xcolor, that causes a strange bug, that I cannot manage to fix. The problem is that, when a box (made with the framed package, and ...
10
votes
1answer
1k views

How can I change the color of digits when using the listings package?

I'm using the listings package and was already able to modify the color of the keywords and almost all elements I was interested in. The only thing that remains is the color of the digits. I'd like to ...
1
vote
1answer
399 views

Enlarge list of listings

I'm using \cleardoublepage \renewcommand{\lstlistlistingname}{Quellcodeverzeichnis} \enlargethispage{\baselineskip} %EITHER \lstlistoflistings \enlargethispage{\baselineskip} %OR THIS ...
1
vote
2answers
934 views

Biblatex and listings incompatibility…

Does someone know why biblatex and listings are incompatible and if there is a way to fix it? I have a Lyx document and whenever I insert program listings I get errors like: al trabajo de ...
5
votes
2answers
267 views

A version of shortvrb for listings?

So, shortvrb is a neat little package that allows you to do \MakeShortVerb{\|} which then has |foo| behave like \verb|foo|. Now, I like listings. Is there a \MakeShortListings that makes |bar| act ...
5
votes
2answers
1k views

Multicolumn listing for comparison in LaTeX

I have some C code that I want to insert in a LaTeX document using a listing. I also want to display its translation to assembly code. I don't know how to display those two kind of codes in a ...
0
votes
1answer
356 views

Problems with error message when using listings-package and inputenc.

I want to include the code of some script in my LaTeX document. In a "minimal" example, it works perfectly well - but only if I leave out the line \usepackage[latin1]{inputenc}: ...
5
votes
1answer
937 views

Code listing in subfigure

I am trying to use the subfigure package of LaTeX to display a code listing. Here was my first attempt: \begin{figure} \subfigure[Standard approach]{ {\footnotesize \begin{verbatim} var caps = new ...
2
votes
1answer
2k views

Lstlistings: Getting pretty equations in display mode

I am currently trying to print my algorithms using the listings package. For clarity I always try to display the more complex mathematical expressions as formula instead of plain code. This results in ...
4
votes
1answer
303 views

Add word Listing in front of number in list of listings

I have to add the word Listing or Lst. in front of the number of a listings in the list-of-listings. I use the listings package. I know how to achieve this with tables: ...
4
votes
1answer
802 views

Framing two-column listings with a tikz node : “missing \item” error ?

I'm trying to use this answer to put my lstlistings environments inside a tikz node. So I want to define a new listings environment, with \lstnewenvironment. My final goal, to be precise, is to ...
3
votes
2answers
1k views

Emphasizing a string in code example using showexpl

I am writing documentation for a package using the showexpl package which in turn uses the listings package. When using listing I can highlight a portion of the code like this: ...
6
votes
1answer
10k views

LaTeX - lstinline

I want to include a short code snippet using the listings package. I have already chosen the parameters for \lstset and my C++ code looks nice with these setttings. For an inline code snippet I try ...
4
votes
1answer
2k views

Line Numbers in Listing Outside of Paragraph

I use the listings package for code listings and I turned the line numbers on. But they appear left of the paragraph. I want them inside the paragraph. In the documentation it looks just right. Here ...
7
votes
2answers
1k views

Hide all images, listings and equations?

is there any way to hide all images, equations and all listings (embedded by using lstlisting package) manually by setting a certain command in the preamble? It would just be interesting to see how ...
7
votes
1answer
2k views

Listing with line numbers inside a table

I typeset a lot of listings (using the listings package) inside (array-based) tabular environments. This works like a charm, however, breaks when I pass the numbers= option to the listing: ...
1
vote
2answers
294 views

Using listings' escapebegin/escapeend with short commands

I'm building beamer slides with code set using listings and I want to draw arrows to parts of the code. To achieve that I have a zero width command that defines a named PGF coordinate (given as the ...
3
votes
1answer
5k views

Size of lstlisting in subfig

For a paper, I have to present two code snippets that do the same thing to compare them. I started having them in two different figures, but now, I'm trying to have them side by side, and that's ...
6
votes
3answers
793 views

How to present source code RDF/Notation 3 in LaTeX?

I give a second try to present RDF in Notation 3 serialization in LaTeX. I tried with the listings package but its not so nice the restuls for the eye-there is much spacing between the letters, the ...