{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

4
votes
1answer
110 views

How can I get identifier style to apply to '%' (in a Perl listing)?

When using Perl variable names with sigils with listings, the $ and @ sigils somehow get coloured in identifierstyle, but the % sigil remains unstyled. Therefore, this code: \documentclass{article} ...
4
votes
1answer
591 views

How to color digits with the listings package

For my project, I've been using the listings package in order to color the keywords, comments, strings, and digits in the code. The thing is, I've managed to color the keywords, comments and strings, ...
4
votes
1answer
2k views

Listings package not correctly showing PHP strings

I'm trying to display some PHP code in a LaTeX document using the listings package. Other languages appear fine (HTML for instance) but PHP seems to be ignoring any strings within the code. The rest ...
2
votes
1answer
199 views

listing package: colored numbers, but not colored in variable names

How to format all numbers in a different color has been discussed in this post. However, this also colors numbers that are part of a variable name. Is there an option to avoid that? ...
2
votes
2answers
271 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 ...
31
votes
4answers
17k views

How to prevent lstlisting from splitting code between pages?

Is it possible to prevent lstlisting from splitting a code between pages if it does not fit on one page? Instead splitting I would like to have the code on the next page. I tried to put all ...
13
votes
1answer
2k views

Manual highlight of TeX code in a verbatim environment

Friends, I'm stuck with a unusual situation: I'm trying to highlight specific words of a TeX code inside a verbatim environment. I know listings can help me by defining a set of keywords, but in this ...
6
votes
1answer
3k views

Colored strings by listings package

I'm trying to type my C++ homework by LaTeX in order to prepare it as a pdf file. I want to have my keywords in blue, my numbers in violet and my strings in reddish brown. I could do the two first by ...
11
votes
2answers
966 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 ...
10
votes
2answers
450 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 ...
14
votes
1answer
271 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
751 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
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} ...
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} ...
8
votes
2answers
250 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 ...
5
votes
1answer
204 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 ...
15
votes
1answer
831 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).
13
votes
2answers
546 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} ...
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
3answers
6k 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 ...
6
votes
1answer
350 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 ...
6
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?
4
votes
2answers
1k views

How to highlight operators and brackets in a C listing?

How can I apply a certain style to C (or, well, any other programming language) operators? So that when I write \begin{lstlistings}[language=C++] int i = 0; if(i > 1) { // do ...
2
votes
1answer
169 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 ...
2
votes
1answer
8k 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 ...
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
360 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
144 views

Bottom frame of listing appears on top of the next page

As the title says. I use, among other things, the following in my lstset: framerule=1pt, frame=tblr Some places a page break happens in the middle of my \lstlisting. Fine. But sometimes the whole ...
8
votes
2answers
216 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} ...
7
votes
1answer
807 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
1k 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
708 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
170 views

How to insert a keyword with accents (extendedchars) in listings

This is what I would like to do: morekeywords={SENÃO, ENTÃO, FAÇA, ATÉ, ENQUANTO, PARA, SE, DECLARA, DECLARE, E, OU, FIM_ENQUANTO, FIM_PARA} I'm defining a new language, and I would like to use ...
5
votes
1answer
2k 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

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
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
6k 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
1answer
809 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} ...
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
924 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
1answer
2k 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, ...
8
votes
3answers
406 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 ...
7
votes
2answers
293 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
129 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
3k views

Including XML file into LaTeX

I am using LaTeX for very first time and have very basic knowledge about it. I am using the template from here to write my thesis. I am using Ubuntu 12.04. When I try to include a small XML file in ...
5
votes
1answer
424 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 ...
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. ...
4
votes
2answers
119 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
2answers
630 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, ...