{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

10
votes
2answers
421 views

Any way to show LaTeX example code *and* execute it? [duplicate]

In (La)TeX documentation and tutorials, it is common to show a snippet of code next to the output it generates. It might be two minipages side by side, or a code listing followed by boxed output, or ...
10
votes
2answers
884 views

How to align comments with lstlistings?

I am using listings with these settings: \lstset{language=C++,basicstyle=\small\sffamily, numbers=none, frame=tb, columns=fullflexible, showstringspaces=false } I like the proportionally ...
14
votes
1answer
244 views

Can the listings package automatically indent source code?

The listings package automatically highlights keywords in source code and makes it look nice. Is it possible to automatically indent the program? For example, in listings, if the following code is ...
9
votes
1answer
698 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
10
votes
2answers
2k views

Splitting a float with code listings

Using the floats and listings packages, I have defined a float for code listings and a shortcut for using it as follows: \usepackage{floats} \usepackage{listings} ...
9
votes
1answer
4k views

lstlisting in two columns

I would like to have two listings, side by side. They have approximately the same length, therefore I don't care about how it's layed out if one part is longer. I tried \begin{minipage}{\textwidth} ...
5
votes
1answer
181 views

How to accept three different languages on lstlisting

How to accept three language different? \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[brazil]{babel} \usepackage{xcolor,tikz} \usepackage{showexpl} % exibe ...
13
votes
2answers
489 views

Escaping from the escaping hell

Given the following MWE, where the argument for the code function contains an underscore: \documentclass [11pt,oneside,onecolumn]{article} \usepackage{listings} \usepackage{filecontents} ...
7
votes
3answers
5k views

Rename “Algorithm” to “Listing”

Background Syntax-highlighted source code image listings are being used as Algorithm floats with the lst: prefix for captions. Problem The following LaTeX code in the preamble renames the caption ...
2
votes
1answer
165 views

How to define different spaces below float and non float listing?

I am using listings from the listings-package. I'm having a problem with spaces below the listings. I use both, float- with h and non-float listings. The problem now is, that the spaces below the ...
18
votes
2answers
407 views

Problem with literate and breaklines=true in listings package

As the title says, the option breaklines=true seems to have an undesired interaction when using literate; in the following example the closing parenthesis doesn't get colorized ...
14
votes
1answer
698 views

In the minted package, how do I enforce straight single quotes?

Basically I want \mint{python}|'banana'| to produce straight single quotes, rather than the curly ones it normally produces (in pdflatex).
11
votes
3answers
1k views

How to deal with very long lines that do not contain spaces?

I have a problem with a lstlisting environment. I want to use it for displaying several very long lines that can not be reformatted. Independently of the option breakatwhitespace=true or false my ...
9
votes
1answer
344 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
2answers
189 views

How to refer to the count value of number of lines in a lstlisting

I need to refer to to the count value of the number of lines in a listing. Is there a way to do that ? \lstinputlisting[caption={SPARQL query used...},label={lst:sqry}]{codes/sparql_query.sparql} ...
8
votes
2answers
2k views

Which package to use for writing algorithms?

I am looking for a package that will allow me to write pseudocode of algorithms. The pseudocode may include mathematical symbols, like \forall, \in and subscripts. But I would like also to "talk" ...
7
votes
1answer
728 views

listings bug: space after literate replacement lost with spaceflexible/fullflexible columns

Problem with space being lost in listings immediately after a literate replacement when using columns=spaceflexible or columns=fullflexible (appears correctly with columns=flexible). A small example ...
7
votes
1answer
966 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
3answers
653 views

Different background colors for lstinline

In the following code, I've decided to use the code from Colored background in inline listings so as to redefine \verb to have the possibility to use colors for the text and the background of the ...
5
votes
1answer
264 views

Multiple listings styles

In using the listings package, how can I have a distinct \lstlistingname value for each type of listing. Lets say my document has C++, R and Pseudo listings, and I would like the \lstlistingname ...
5
votes
1answer
2k views

Is there a good definition for highlighting PHP code in listings?

Does someone have a good definition for highlighting PHP code with the listings package?
5
votes
1answer
1k views

cleveref + listings

\documentclass{scrbook} \usepackage{listings} \usepackage{cleveref} \begin{document} Ref: \ref{test}. Cref: \cref{test}. \begin{lstlisting}[caption={Test},label={test}] test \end{lstlisting} ...
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 ...
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 ...
5
votes
2answers
2k 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
5k views

lstlisting: how to set code color and frame color

I am using lstlisting to show some code in my PDF. The problem is that when I use: basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red}, to change the code color (not only the language ...
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 ...
3
votes
1answer
761 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} ...
2
votes
1answer
7k 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 ...
10
votes
1answer
1k views

Listings package does not break

The following code does not break even though the breaklines and breakatwhitespace is set: \lstset{ language=XML, numbers=left, numberstyle=\tiny\color{gray}, stepnumber=1, ...
7
votes
2answers
274 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
2k 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
101 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
400 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 ...
3
votes
1answer
40 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
451 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 ...
2
votes
2answers
231 views

How can I highlight text before a character with listing?

All is in the title. I would like to add a color to the text before a character with listing package. For example, I would like to add a color to text between the beginning of a line and : or =, in a ...
12
votes
1answer
9k 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 ...
9
votes
5answers
5k 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, ...
15
votes
3answers
10k 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, ...
7
votes
2answers
269 views

How do I prevent conflicts between accsupp and hyperref?

This question is related to the answer to the question Is there a LaTeX trick to prevent a PDF viewer from copying the line number? Unless you turn hyperref off, the following MWE ...
9
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#> ...
8
votes
2answers
215 views

How to show a hint when lstlisting is breaking page?

I use inline lstlisting-blocks with caption. I have several listings that are running over more than one page or starting at the end of a page. Now I want to place a hint for the readers, that the ...
8
votes
2answers
494 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
521 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
611 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 ...
9
votes
2answers
459 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 ...
8
votes
1answer
393 views

How can I highlight YAML code in a pretty way with listings?

I'm trying to highlight simple YAML (the markup language, not the CSS framework) code. I know that there is a solution using pygments and minted, however, I would prefer a solution with ...
8
votes
2answers
239 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 ...