{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
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 ...
5
votes
2answers
1k 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. ...
5
votes
2answers
3k 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 ...
4
votes
1answer
881 views

\newenvironment fails with special listings environment

I want to use the showexpl, but define a new environment with predefined settings. But all I get is an emergency stop. \documentclass{scrbook} \RequirePackage{showexpl} ...
3
votes
1answer
1k views

Change caption style of listings package without “caption” package

Is there a way to change style of a caption in listings without the caption package (make it smaller and non-bold)? I am using \lstnewenvironment to create my own customized environment and then use ...
10
votes
2answers
339 views

Can the listings package highlight by regexp?

I'm trying to typeset SuperCollider code using the listings package. Any "freestanding" identifiers that begin with a capital letter are class names, and should be highlighted; by "freestanding", I ...
10
votes
3answers
485 views

Masking \end{lstlisting}

I am not sure if I am using the right wording in title. Basically what I need is to add the following source using the listing package. In preamble: \usepackage{listings} then and is here when I ...
9
votes
1answer
411 views

Background images for code listings

I've been searching around but I can't find any info for adding an image background for my code listing using the listings package. Is there a way to do this?
8
votes
1answer
544 views

Listings line numbers that match the linerange specification

This is a follow-up question to First line number in lstinputlisting environment. Consider the MWE: \documentclass{article} %\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox ...
7
votes
2answers
370 views

How can I define a custom listing environment?

I am trying to define an enviroment for a specific programming language, F#. Here's my code: \definecolor{bluekeywords}{rgb}{0.13,0.13,1} \definecolor{greencomments}{rgb}{0,0.5,0} ...
7
votes
2answers
3k 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 ...
6
votes
1answer
175 views

Listings: text highlighting based on prefix

How can I apply different styles to keywords depending on their prefix? Here is some sample code: (-2,0,0) (2,1,1) op-registerbox !box1 ;box1 /Blue op-setproperties I'd like to typeset words ...
5
votes
1answer
467 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 ...
4
votes
2answers
185 views

Indent content of verbatim / lstlisting environment relative to containing environment

I want the content of \verbatim to be indented relative to the actual indent of \verbatim, not the exact number of spaces. For example, I like to indent at sections to make the LaTeX source more ...
4
votes
1answer
373 views

How can I define multiple identifier classes and styles in listings?

I'm trying to add different styles (color, etc.) to different groups of words in the listings package. Note that my question is different from How can I use multiple declarations (\textbf, \emph) in ...
4
votes
2answers
681 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, ...
3
votes
1answer
85 views

Listings package split frame when the page ends

When I use the listings package with frame in my code the frame "breaks" when the page ends and it is open in the end of the page. I want the frame to be complete with four sides and continue in the ...
3
votes
1answer
716 views

How to tweak the LOF and LOT without using any packages?

The list of figures/tables in default book class looks like: Default looking: List of Figures 1.1 Snapshots .................. 2 1.2 Snapshots .................. 4 1.3 Snapshots ...
34
votes
1answer
504 views

listings: Copy to clipboard feature?

I was just wonder if it would be possible to have a "Copy to Clipboard Button" next to each listing which would just copy the verbatim content of the lstlistings environment to the clipboard. An ...
20
votes
2answers
10k views

How to highlight Python syntax in LaTeX Listings \lstinputlistings command

I am using package listings to import my Python source code into my LaTeX document. I use the command \lstinputlistings. I have a Python source like class MyClass(Yourclass): def __init__(self, ...
14
votes
1answer
11k 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 ...
10
votes
5answers
7k 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, ...
18
votes
3answers
13k views

Shrinking monospace style for listings package

I am working on a thesis and putting together a "pretty" listing. I'm looking at setting up a small font style for a code view. What I have here is: \usepackage{listings} \lstset{language=C, ...
18
votes
1answer
25k views

Listings caption [duplicate]

I'm using the listings package with this \begin command: \begin{lstlisting}[caption=blabla, label=amb] This yields a nice code listing with a caption like "Listing 1.1 blabla". Is there a way to ...
16
votes
1answer
181 views

How to strip a listing of all (line and block) comments without leaving white space?

I'm looking for an easy and robust way to strip all the comments from a listing. My approach (passing \@gobble to the commentstyle key) correctly removes all the one-line comments and block comments. ...
16
votes
1answer
458 views

How to remove the leading unnecessary white spaces when using linerange option?

To be honest, I am looking for people who already read the listings documentation completely. If those people also cannot solve it, then the documentation does not mention anything about it. Sorry for ...
11
votes
2answers
734 views

tcolorbox - list of listings?

In a book with figures, tables and listings, I figured out that all listings and some tables and figures look better when presented in a tcolorbox. The book has the usual tables of contents: ...
10
votes
3answers
2k 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#> ...
22
votes
2answers
2k views

Ensure verbatim code block is copy/paste-able

After rendering a document containing this code block \begin{verbatim} if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist. if [ ! -f README.md ]; ...
13
votes
1answer
3k views

Double-column listing package

Not too well up on LaTeX, but I want to use the listings package for listings spanning a two-column format. Unfortunately, asterisks cannot save me (like for figures/tables); this doesn't work: ...
11
votes
2answers
4k views

How to insert code with accents with listings?

I'm trying to insert source code in LaTeX with using listings, but my code has accents and pdflatex gives me this error: Unicode char \u8:�\expandafter not set up for use with LaTeX. This is a code ...
8
votes
2answers
614 views

Combining `tikzpicture` and `lstlisting`

I'm working on a custom lstlisting environment, in which I use TikZ to add a frame and a title. Because of the widespread curly braces of node I cannot use newenvironment, so I have to resort to ...
8
votes
3answers
1k views

Problems with copy and paste from PDF using lstlisting

I'm using lstlisting to create course notes from which I am hoping that code can be copy&paste'd I've already implemented the suggestions in Phantom spaces in listings (pdf) to make sure that ...
8
votes
2answers
652 views

Attach listing to PDF

I would like to add listings source as attachment to a PDF (created by pdflatex). For \lstinputlisting this is pretty easy: \RequirePackage{listings} \RequirePackage{embedfile} ...
5
votes
2answers
631 views

Position tikz pictures at left margin of a listing code block

I'm trying to finish my attempt at having good looking unlimited line annotations for the listing environments, using tikz. The original problem was that indentation caused shifts in the positioning, ...
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)... ...
10
votes
1answer
780 views

How to extend the \lstinputlisting command

With the answer from autogobble for lstinputlistings I've managed to create a command that gobbles \lstinputlisting and makes firstnumber to start by firstline. I would like to rewrite it as a ...
10
votes
3answers
11k 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 ...
9
votes
2answers
539 views

Two code blocks working syncronously

I need two code blocks in my beamer frame. One will be the code and other will be the output for each line of code. I want to uncover each code line and corresponding output line. So, first it will ...
9
votes
2answers
285 views

How to add listings environment to DTX files

I am working on my first DTX file and want to add a code example, which shall be printed with listings. This works so far, but since the documentation is commented the listings code is using a full ...
8
votes
3answers
815 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 ...
7
votes
1answer
5k views

lstlisting line wrapping

How is it possible to let lstlisting wrap lines? I've troubles with following block: \begin{lstlisting}[language=java] public class MeasureStationControllerV0Test { MeasureStationControllerV0 ...
7
votes
2answers
1k views

Grouping the list of listings by chapter

I am using the listings package. I want to print out a list of listings, which I can do. The thing is that in the other listings the typesetter "groups" figures/tables by chapter. Is it possible to ...
5
votes
1answer
169 views

How can I preclude copying & pasting of listings?

When I include code snippets in my documents, my lazier readers, i.e. students :), are often tempted to just copy and paste those snippets instead of typing them themselves. However, there are risks ...
4
votes
1answer
327 views

Placing listing and figure side by side in memoir

I am writing a document using the memoir class where I want to place listings (with the listings package) and figures side by side. My first approach was to save the listing in a box and use subbottom ...
4
votes
2answers
3k 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 ...
3
votes
1answer
6k views

Styling a lstlisting caption using caption package

I'd like to style a caption in a specific way, but I can't seem to figure out the proper settings to do so. First off, I'd like to change the label from "Listing" to "Algorithm" when I use ...
3
votes
1answer
771 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 ...
10
votes
1answer
149 views

Strange interaction between listings and sections

Consider this example: \documentclass[a4paper]{article} \usepackage{listings} \lstnewenvironment{shell}{}{} %\usepackage{verbatim} %\let\shell\verbatim %\let\endshell\endverbatim \begin{document} ...
9
votes
1answer
530 views

Scaling inline code to the current font size

Edit: Don't even bother reading the question. Just jump straight to Heiko Oberdiek's answer :) With the listings package, typesetting listings in some absolute font size is very easy; all you have to ...