{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

6
votes
2answers
2k views

Increase space between listings env. and surrounding text

How can I set the space between a listing (lstlisting) and text that surrounds it? Is there a parameter I can set at the beginning of my document, that controls this? I tried framesep, but it just ...
2
votes
1answer
351 views

Making figures (listings) be like tikz node/arrow transitions

I have the MWE as below: \documentclass[a4paper,11pt,twoside]{report} \usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry} \usepackage[T1]{fontenc} \usepackage{graphicx} ...
2
votes
0answers
256 views

Using \lstinline[] changes all text colour in editor after use [closed]

Ben using \lstinline today from the listings package... and every time I use it, it seems to change the colour of all text following it in texmaker to light brown... which is very annoying when trying ...
3
votes
1answer
347 views

How to combine the listings and algorithm2e packages to be used with List of Listings

I want to make a "List of Algorithms and Listings" that contains both listings made with \begin{lstlisting}... (listings package) and algorithms \begin{algorithm}... (algorithm2e package). I also ...
3
votes
2answers
1k views

Listings line numbers and figure

I'm using listings to typeset some C inside a figure environment next to a diagram, and I have the numbers on the left. My problem is in two-column mode the line numbers appear in what should be the ...
1
vote
1answer
110 views

Order of `float` and `caption` packages in preamble

I am using float and caption packages in my document, and also packages like tabularx, listings, algorithm... that (as far as I know) define floating elements or elements that have captions ...
4
votes
1answer
948 views

How to add color to source code under the listings environment

I would like to color a few keywords in my slides under the listings environment In the following contrived example, I would like to color the __shared__ word with orange and WIDTH with blue. How ...
12
votes
2answers
20k views

Decrease font size in a listing

Hi I am trying to include a short code snippet into one of my beamer slides However one of the lines is not fitting into the slides. Please let me know how to decrease the font size to make the ...
9
votes
1answer
12k views

How do I add syntax coloring to my C++ source code in beamer

I have just learned how to insert source code into beamer with the listings package. However I dont know how to go about adding any syntax coloring on the C++ source code. How do I do that? Here ...
8
votes
3answers
6k views

How to put C++ source code into beamer slides [duplicate]

Possible Duplicate: How display LaTeX code in LaTeX document? How do I fit java style source code in one frame in beamer? How do I add C++ formatted and coloured source code to my beamer ...
3
votes
1answer
736 views

Background color in inline code listings with linebreak

I want to highlight code inline with a gray background. Preferably with listings. This question is related to Colored background in inline listings. But as my MWE shows it doesn't work with line ...
2
votes
1answer
287 views

\lstinputlisting of a whole java project

I'd like to print the complete source code of my java project, which has multiple .java files in several packages (i.e. folders), many .properties files and many .xml files, and others. I want to use ...
2
votes
1answer
624 views

vim type Display for C Code in Latex

Target Display: My Latex Code: % xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet STARTS xxxxxxxxxxxxxxxxxxxxxx \lstset{ language=C, % choose the language of the code stepnumber=1, ...
6
votes
1answer
584 views

How to Format C Program Code Block Nicely

I am using the following settings to format my code blocks: % xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet STARTS xxxxxxxxxxxxxxxxxxxxxx \lstset{ language=C, % choose the language of ...
6
votes
1answer
168 views

Is it possible to change the font of line numbers in a code listing?

Using LyX I can add line numbers to my code listing. However, these are in the document (serif/Roman) font and look strange next to code blocks (Typewriter font). Is it possible to change the font of ...
4
votes
1answer
344 views

Treat a dotted suffix as keyword in listings

I'm writing C++ code in latex with listings. I'm trying to get listings to recognise the suffix .t() as a keyword (it means matrix transpose in the Armadillo C++ library). I tried to get the ., ( ...
2
votes
1answer
159 views

Listings not breaking up

I have a code listing as shown in the picture (number 4) that goes a bit out of the margin although breaklines=true. When I try to break new line it gives me an error Listings Error: lstinline ended ...
1
vote
1answer
273 views

How to obtain Sweave(l) listings with rounded corners?

I downloaded the Sweavel.sty-File from here: http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SweaveTemplate/Sweavel.sty Now, for a modern look, I would like to produce rounded corners in the R code ...
5
votes
1answer
143 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
174 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
190 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
337 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
502 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
61 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
617 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
385 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
4k 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
293 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
324 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
90 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" ...
6
votes
1answer
818 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 ...
5
votes
1answer
274 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
374 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 ...
3
votes
1answer
1k 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
385 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
192 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 ...
4
votes
2answers
842 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: ...
3
votes
1answer
214 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
485 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 ...
9
votes
2answers
863 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
293 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
865 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, ...