{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

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
351 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
20k 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
950 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
3k 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
398 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
554 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
941 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
30k 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
674 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,,...
5
votes
2answers
886 views

How can I set columns=fixed for lstinline globally?

I typeset my listings using listings with a proportional font. This looks good for the lstlisting environment. However, when I use \lstinline|code|, the spacing reverts to variable-width. I would like ...
8
votes
1answer
2k views

Listings code snippet has white horizontal lines across it

I'm using the listings package to typeset my code examples. I've set the background color to slightly off white color and I'm noticing strange white horizontal lines across the snippet. They seem to ...
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: \lstset{language=[Sharp]C,,...
0
votes
1answer
618 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
664 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 option....
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
10k 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
269 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. ...
15
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?
13
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 ...