{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

5
votes
3answers
3k 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
481 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 : \newcommand{\modelica}[1]{\...
33
votes
4answers
18k 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... \documentclass[...
3
votes
1answer
1k 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} \...
5
votes
1answer
2k views

deletekeywords in Listings package sometimes doesn't work

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: \lstset{language=[]C++...
4
votes
1answer
639 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
582 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
180 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 ...
12
votes
1answer
2k 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
490 views

Enlarge list of listings

I'm using \cleardoublepage \renewcommand{\lstlistlistingname}{Quellcodeverzeichnis} \enlargethispage{\baselineskip} %EITHER \lstlistoflistings \enlargethispage{\baselineskip} %OR THIS \...
1
vote
2answers
1k 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 \citet{...
5
votes
2answers
359 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 ...
6
votes
2answers
2k 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
447 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}: \documentclass[]{...
5
votes
1answer
1k 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
3k 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 ...
5
votes
1answer
400 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: \renewcommand{\cfttabpresnum}{...
4
votes
1answer
1k 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
2k 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: \documentclass{article}...
10
votes
1answer
20k 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 ...
7
votes
1answer
6k 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
2k 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
3k 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
355 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
6k 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
1k 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 ...
4
votes
1answer
1k views

Execute own command in listing

I create an own command like this \newcommand{\hostname}{this.is.my.hostname} Now I want to use this command in normal text (no problem) and inside of a listing Nun kann die Funktionsweise ...
5
votes
2answers
1k views

How can I tell lstlisting to use sans-serif when escaping to math mode?

Title says it all, an example follows: \lstset{ mathescape=true, basicstyle = \sffamily } \begin{lstlisting} func($x_0$) \end{lstlisting} Where and how can I set the math font used ...
5
votes
1answer
21k views

Adding C++ code in Latex

So I am adding some C++ code snippets in my document using \lstset {language=C++} \begin{lstlisting} for (int i=0; i<iterations;i++) { do something } \end{lstlisting} My issue is that the font ...
8
votes
2answers
2k views

How to make a box containing LaTeX output?

I am writing a short introductory book on LaTeX and I would like to implement nice looking code example boxes. Using this answer: Source code listing with frame around code? I made the boxes with the ...
7
votes
1answer
3k views

Get List of Listings in an Appendix [closed]

I am using LyX with the listings package. I want to have Appendix A be titled "Code Listings" and then have the List of Listings. Right now I have \lstlistoflistings in an ERT. By using \...
6
votes
2answers
8k views

How to change the font style and size for the \lstinputlisting

I am trying to insert some piece of code into my document, using the \lstinputlisting command. However the fonts displayed do not look too good. Is it possible to change the font size and style?
7
votes
1answer
3k views

lstlisting, tt fonts, and alignment.

I (mostly) love the listings package, which I have started migrated to from verbatim for code listings. I prefer to continue to use teletype for code, and so I changed my default listing configuration ...
21
votes
4answers
4k views

How to automatically skip leading white spaces in listings

This question led to a new package: lstautogobble (lstaddons bundle) For my programming lecture slides I heavily use the listings package with \lstnewenvironment to typeset source code. It's a ...
14
votes
3answers
7k views

How to make listings code indentation remain unchanged when copied from PDF?

So I am using listings package for code examples. But there is a problem. When I copy the code examples from the final PDF document, they are usually not the same - the indentation is gone, there are ...
8
votes
1answer
952 views

How do I prevent LaTeX from putting \sections at the very end of the page?

Please take a look at the screenshot below. I am having a problem where LaTeX would put the \section at the very end of the page. So far I fixed it by using \newpage but I just learned that it was ...
8
votes
1answer
4k views

How to change “Listing 1. Caption” to “Figure 1. Caption”?

I have a listing like so: \lstset{language=Python,caption={Caption}} \begin{lstlisting} some Python code goes here \end{lstlisting} In the PDF this appears as Listing 1. Caption. How can I make it ...
8
votes
1answer
400 views

How do I create a new command \listofcodes in latex?

In addition to tables and figures, I have a bunch of code pieces. Just like follows: \begin{figure} \lstinputlisting[ language=C++, breaklines=true, keywordstyle=\color{blue}, ...
3
votes
1answer
1k views

Using the “combine” document class with the listings package

I am trying to use the combine document class (manual) to combine several pre-existing documents into a single file with consistent formatting. It works great, except that there is a conflict of some ...
8
votes
1answer
556 views

How to make my keywords still get highlighted no matter the breaklines is set to true?

I got a bit of trouble with the listings package. I am trying to highlight a custom language with lstdefinelanguage but for reasons I can't understand, highlighting for my ) keyword, and only the ) ...
0
votes
5answers
946 views

How to prevent extendedchars=\true from producing a blank line?

My previous question How to suppress BOM effect in the output? has been solved by @Vaulty. Enabling extendedchars=\true, however, produces an unnecessary blank line at the first line as shown below. ...
7
votes
1answer
2k views

Displaying two XML listings side by side. [duplicate]

I have two XML outputs from a program that I would like to include in a LaTeX document. I would like them to appear side-by-side each in its own box. So that a reader can compare the two outputs while ...
31
votes
2answers
31k views

How to format an inline source code

I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options ...
12
votes
1answer
324 views

Test if a number is in a comma separated range/list of numbers

Martin Scharrer posted a very elegant answer for the question "Creating a zebra effect using listings". I want to extend that code to highlight only lines given in a comma separated list. The ...
50
votes
1answer
3k views

Creating a zebra effect using listings

This question led to a new package: lstlinebgrd (lstaddons bundle) Friends, consider the following example using the listings package: \documentclass{article} \usepackage[T1]{fontenc} \...
2
votes
1answer
677 views

Changing Listing and Figure caption system in Platex

I'm working with platex (the Japanese latex compiler) and I'm trying to change the caption system for Listings and Figures. For both I would like the numbering to be based on section so if its a ...
8
votes
3answers
1k views

Listing language for “screen session”

I am writing a set of tutorial documents on some command-line based tools. This tutorials need to show a "screen session". Something along the lines of: $ git status # on branch "master" I want to ...
10
votes
2answers
6k views

How can I ensure that a listing is not going to be split?

How can I ensure that a listing is not going to be split? If it is going to be split I want that the entire listing to move to the following page, effectively moving everything at pass. I mean any ...
7
votes
2answers
6k views

Use $ in lstlisting

I need to create some jQuery-Listings but when I try to do so \documentclass[12pt,oneside,a4paper]{scrartcl} \usepackage{textcomp} \usepackage{listings} \usepackage{color} \definecolor{lightgray}{...
10
votes
5answers
11k views

beautiful listing for CSharp

Does anyone have a nice typesetting style for the C# language using listings? I configure it in this way: \lstset{language=[Sharp]C,,basicstyle=\footnotesize, showspaces=false,showtabs=false,,...