{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
1answer
147 views

How to keep last n lines together in listing?

I have a large listing defined with lstlisting (listins-package). Now the listing reaches over three pages. On the last page there is only one line (the last line) of the listing. I looks not very ...
2
votes
1answer
186 views

Listings package does not break with mwrep document class

I cannot get listings package to break lines with any of the methods described in previous questions: Listings package does not break, ...
2
votes
1answer
209 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 ...
8
votes
1answer
1k views

Maple package for Latex

I'm translating the book PHYSICS WITH MAPLE by Wang. It contains some codes and outputs from Maple of course. I was wondering do we have a package such as mcode or matlab-to-tikz ( MATLAB) for Maple ...
0
votes
0answers
60 views

How to escape single quote in lstlisting? [duplicate]

Possible Duplicate: Package listings: Error “Undefined control sequence.” because of single-quote-symbol? How to escape single quote ' in lstlisting? I tried \' and ''' but ...
2
votes
1answer
419 views

How to escape backslash in rangeprefix?

I want to escape backslash to be used as a rangeprefix as follows. The current MWE does not work as expected because it still imports all codes rather than the codes sandwiched by document ...
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, ...
1
vote
1answer
562 views

Using colorbox in a Listing/minipage with underscore “_”

I am having some issues with using \colorbox{}{} in combination with an underscore. The Listing will compile without issues and highlighting the text properly, but as soon as I have an underscore in ...
1
vote
0answers
62 views

How to setup the caption and listings package to insert code? [duplicate]

Possible Duplicate: Caption parbox 6.0 pt too wide I used caption and listings package in my .tex file as below: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{ ...
13
votes
2answers
792 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} ...
0
votes
1answer
416 views

Defining a listings style and available options

When defining a style for a listings environment, I can set the background color by doing: \lstdefinestyle{highlight}{ backgroundcolor=\color{orange} } Apart from backgroundcolor, which other ...
5
votes
1answer
6k views

How to change listing caption?

I have some listings that contain pseudo-code of algorithms. And I use this: \lstset{caption={Descriptive Caption Text},label=DescriptiveLabel} to add captions to them. My problem is that the ...
7
votes
1answer
1k views

Avoid line breaks after \lstinline

I'm writing a computer science paper with LaTeX and have a lot of inline code. Now, when this code is followed by a comma and is at the end of line, the line break is inserted before the comma, which ...
3
votes
1answer
320 views

mark LaTeX keywords in listings

I am using this code to define keywords for listings \lstdefinestyle{demostyle}{ columns=flexible, keepspaces=true, basicstyle=\small\ttfamily, language = [LaTeX]TeX, ...
3
votes
1answer
340 views

Background images for code listings in beamer

I asked this question originally in attempt to get background images behind my code listings. Background images for code listings What I did not mention is that I am using the beamer package for ...
5
votes
1answer
114 views

vertical extra space below lstlisting environment inside a list environment

i want several code listings to be embedded in an item of a custom list environment. To achieve this i employ the lstlisting environment of the listings package. Unfortunately extra vertical space is ...
8
votes
2answers
3k 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
905 views

LaTeX to HTML preserving code coloring from listings

I'm trying to convert some LaTeX into HTML but my code listings don't preserve their code coloring. Why is that and how do I fix it? This is what it looks like: Side note: I'm also wondering why ...
6
votes
1answer
336 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 ...
6
votes
2answers
407 views

How to make “sub-level” numbering for listings, similar to subcaption?

I think what I'm trying to do may be complicated, so if not all of it is possible then that's OK. I'm using the listings package and I've done something similar to Custom numbering of listings ...
4
votes
1answer
2k views

How to use mathematical symbols in listing?

I want to use math mode in lstlisting. How do I do that? How to put tab in this mode? \begin{document} \begin{lstlisting}[frame=single] % Start your code-block module main() ...
9
votes
1answer
444 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?
4
votes
2answers
198 views

Mangling listings source code

I would like to make it harder for students to just copy/paste code listings from the PDF. How to achieve this? I want them to actually understand the code, close the book, and write from their ...
5
votes
2answers
1k views

Listings package with caption legend in spanish

I'm using the listings package and would like to translate the caption text displayed to Spanish, so instead of Listing 1: Dummy label it will display Listado 1: Dummy label. This is my code: ...
4
votes
1answer
243 views

Headers and footers for listing environment?

What I need to be able to do is apply a header and footer when I use the listings environment. I have a few requirements: The header and footer should be outside the listing itself, i.e. they are ...
3
votes
1answer
2k views

Add listings to list of figures

I am using the listings package to display code in my document. is it possible to add the listings to the List of Figures. Instead of Listing, there should be Figure in the caption and it should share ...
3
votes
1answer
561 views

R listings operator partially in bold

I am using listings to display R code. The matrix multiplication operator shows up partially bold, something like this: "\%\textbf{*\%}". If I separate the * and the %, the second % is not in bold. I ...
11
votes
2answers
1k views

How to compose figure from text with latex?

I have an ascii image like +--------------- | xxxxxxx +--------------- | xxxxxxx +--------------- I want to show this in figure environment. So currently I try like this: \begin{figure} ...
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 ]; ...
4
votes
2answers
1k views

How to cross-reference inside of a verbatim (or listings) environment

I would like to reference other parts of my document (e.g. equations, figures) inside of some source code. Is there an escape sequence such that \ref will be parsed instead of printed as a literal ...
4
votes
1answer
337 views

listings wrong syntax highlighting in perl - format specification

Perl uses '#' as an introduction for a comment, but also as a format specification. This produces problems in the syntax highlighting in the listings-package. How can I fix it? ...
4
votes
1answer
1k views

How to center listings caption?

I would like to know how to center the listings gerenated caption in LaTeX. It always go to the left of the code. The rest of the captions (tables) are OK. \documentclass[11pt,a4paper,oneside, ...
6
votes
1answer
2k views

XML syntax highlighting does not work

How do I make comments highlighted in the form: <!-- ======= Processing Root tag ======= --> . This is not working. \documentclass[11pt]{scrartcl} \usepackage{listings, color} ...
5
votes
1answer
141 views

StrSubstitute and @ inside and outside \lstnewenvironment

While further working on code for my answer to Different approach to literate programming for LaTeX, I am encountering a problem to which I am sure there is a very simple solution, but it completely ...
1
vote
0answers
73 views

Changing font in listings-package [duplicate]

Possible Duplicate: set the font family for lstlisting I need to change the font while using the listings-package since my TeX template seems to interfere with standard listings settings ...
6
votes
1answer
1k views

Adjusting Vertical Spacing between a listing and its Caption

I am very new to LaTeX. I am inserting a listing as follows: \lstinputlisting[float=hk, caption=My Caption comes here, captionpos=b, ...
3
votes
1answer
1k views

Alternative way to print source code [duplicate]

Possible Duplicate: Syntax Coloring in LaTeX I want to add source code of my program in document but verbatim really bugs me. All that ugly fonts and stuff.
-1
votes
1answer
409 views

Smalltalk syntax highlighting for Latex [closed]

What is the easiest way to format Smalltalk syntax using the listings package?
5
votes
0answers
294 views

How to customize the font and margin for lstlistoflistings TOC entry? [closed]

In my LaTeX template, I define the chapter and section TOC entry with the titletoc package: \titlecontents{chapter}[0pt]{\vspace{.1\baselineskip}\bfseries} {\thecontentslabel\hspace{2.8mm}}{} ...
1
vote
1answer
4k views

How to customize the caption format for \lstinputlisting

I know how to customize the caption format of lstlisting environment. But how to do this if I used the \lstinputlisting command to import code? My document contain below snippet. \begin{framed} ...
6
votes
2answers
3k views

Create a \lstnewenvironment that creates named listings

I am using the \lstnewenvironment to format a set of code listings in my document. \lstnewenvironment{code} {\lstset{language=haskell, basicstyle=\small\ttfamily, numbers=left, ...
1
vote
1answer
184 views

lstlisting-environment not available within tabularx-environment

Please consider the following example. Does anyone has an idea why I cannot use the listings-environment within the tabularx-environment? \documentclass{article} \usepackage[ngerman]{babel} ...
1
vote
1answer
340 views

Looking for HAML and CoffeeScript support

I need support for HAML and CoffeeScript like other languages already got with the listings package. Do you know any solutions?
7
votes
3answers
255 views

How to define a listing example environment

I have read the listing manual document. I would like to use the lstsample environment. It looks like below: Basically, the output is on the left and the code is placed on the right. But I don't ...
7
votes
1answer
2k views

cite in caption of listings

I am trying to cite a paper in the caption of listings. I have the following code: \begin{lstlisting}[caption=Example of something (Adapted from \cite{abc})] example \end{lstlisting} But this is ...
4
votes
1answer
299 views

Can I have automatic \needspace for listings package?

I am using the listings package. The problem I have is that if the code gets in the middle of two packages, it is cut, which I don't want. To kind of solve that, I am using the package needspace and I ...
2
votes
0answers
92 views

Colors for integers in listings package [duplicate]

Possible Duplicate: How can I change the color of digits when using the listings package? Listings package: How can I format all numbers? Is it possible to have colors for integers using ...
0
votes
1answer
760 views

Problems using listings package [closed]

I'm using the listings package to include some source code files in a LaTeX document. I'm having 2 problems: characters - are not shown in the resulting file characters % are shown overlapped with ...
5
votes
1answer
378 views

listings caption is distorted

I used listing for listing the codes like: \documentclass[prodmode,acmtecs]{acmsmall} % Package to generate and customize Algorithm as per ACM style \usepackage[ruled]{algorithm2e} ...
3
votes
1answer
808 views

Latex listings R: need mono-spaced font with bold keywords and correct caret (^)

I am using the listings package to display R code. I would like a monospaced font, bold keywords, and I would like code that works when the user cuts and pastes from the pdf file into rstudio. The ...