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

Inserting TeX code into beamer - Problem with otherkeywords

I am preparing a beamer presentation and using the lstlisting environment in order to put in TeX code. I am using the following code which is largely copied from here: ...
9
votes
1answer
1k views

Beamer - Using \pause within lstlisting

I am preparing a beamer presentation and using the lstlisting environment in order to put in code. However, I would like to use the \pause command within lstlisting. By definition that is not ...
11
votes
2answers
1k views

highlight lines in listings

I have code that i have included into my document using the texcode below \begin{minipage}{.48\textwidth} \centering \lstinputlisting[numbers=left,xleftmargin=2em,frame=single,framexleftmargin=2em, ...
4
votes
1answer
117 views

How to edit latex-generated text in Captions?

I want to take the answer to the question LaTeX source code listing like in professional books one step further, and change the (latex-generated) text in the caption from Listing n to something more ...
4
votes
1answer
552 views

Set styles for numbers in listings package

I am using the listings package for Smalltalk programming language but since it does not come out of the box, I am trying to do it by hand. Now I have a problem with numbers. No matter if I change: ...
4
votes
2answers
516 views

How to detect words starting with # in listings package?

I am writing some code with the listings package and I need to detect the words starting with the number sign (#) and apply certain style. For example, if I have this code: something #foo ...
2
votes
1answer
312 views

treating multiple code listings as one figure (listings package)

Please note that I am quite new to tex/latex. For my paper I need to reference specific parts of my source code as one code listing. This allows me to skip specific lines of the source code that are ...
4
votes
1answer
124 views

listing's lst@BeginWrite gobbles '->' and '=>' from input [closed]

I'm trying to write a package that takes verbatim input and appends it to several files. My current approach is based of off an answer by Martin Scharrer to a similar problem. The difficulty arises in ...
6
votes
2answers
347 views

How to detect a tab character when processing a literate in lstlistings?

In the solution to Making more easy the itemized of item with tabulation system, I am counting up the number of spaces in order to determine the type of leading character to insert. However, if the I ...
2
votes
1answer
235 views

listings ignore final newline

When I write listings in my LaTeX code I usually follow this format \begin{lstlisting} foo bar baz \end{lstlisting} and when I put this inside a normal LaTeX document, things look fine. But when I ...
5
votes
1answer
2k views

lstinputlisting does not include file within lstnewenvironment?

I want to use lstinputlisting to include a file with code within an lstlisting block, which is defined through a new environment. However, the lstinputlisting command itself, not the code, is ...
1
vote
1answer
404 views

Quotation mark in \lstinputlisting becomes white

How can I fix this issue with everything inside and including the "quotation mark" itself becomes white, in my case invisible due to the white background. Thanks in advance. I almost forgot that im ...
1
vote
1answer
253 views

Using listings package without installing it

I am finishing writing a paper that uses the listings package. Sadly, the submission system I have to use for submitting my paper does not come with this package. Is there any way to use the features ...
9
votes
2answers
356 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 ...
65
votes
3answers
2k views

Is there a LaTeX trick to prevent a PDF viewer from copying the line number?

A PDF output is obtained by compiling the following code. \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstset { language={[LaTeX]TeX}, numbers=left, ...
18
votes
4answers
5k views

LaTeX Source Code Listing

I want a code listing, but the code I'm listing is LaTeX. When I simply use: \usepackage{listings} ... \begin{lstlisting} ...LaTeX document goes here... \end{lstlisting} The listing looks like ...
6
votes
1answer
318 views

How to share a counter for a subfloat

I am trying to make a listing float containing 3 subfloats. I have managed to to make the actual float by combining the answers from question1 and question2. Now I only need to make mylisting use the ...
5
votes
1answer
764 views

avoid linebreak in \lstinline if possible

By using \lstinline{mysourcecode} I put some code within my document. I would like to avoid that this code is broken to a new line, if possible. so, if the codeline itself is less long than a full ...
7
votes
1answer
671 views

C preprocessor commands in listings package

I am using the listings package, which is mostly formatting things nicely. However, it fails to syntax highlight indented preprocessor commands correctly. For example, \documentclass{article} ...
4
votes
1answer
998 views

Highlight certain texts in listings or minted [duplicate]

Possible Duplicate: Manual highlight of TeX code in a verbatim environment I want to highlight certain parts of a program output listing which represent user input. For example I want to ...
0
votes
0answers
73 views

My lstlisting environment only shows “2” above the first line, instead of numbers before each line, when Hebrew is enabled [duplicate]

Possible Duplicate: backgroundcolor in lstset does not work I've recently changed my document skeleton and now my code segments, defined with \begin{lstlisting}...\end{lstlisting}, changed ...
4
votes
1answer
1k views

How can I get lines to break automatically using the LaTeX listings package?

I am using the listings package to include sample Perl source code in LaTeX. I included the package with \usepackage{listings}, and used the following code: \lstset{language=Perl} ...
6
votes
3answers
554 views

Invisible listing captions

Short version: how can I make a listing's caption show up in the List of Listings but not in the body of the document where the listing is? I'm writing a university report, and many of my subsections ...
3
votes
1answer
9k views

Package listings: Error “Undefined control sequence.” because of single-quote-symbol?

I'm using the package listings and came across a problem displaying an SQL statement within an java environment. This is the MWE. \documentclass[]{report} \usepackage{listings} ...
0
votes
1answer
249 views

\afterpage issue with \lstlisting

I have issue with \afterpage command and \lstlisting, it's add one blank page after beginning code listing, and after blank page is two of my command. \appendix \section*{APPENDIX A} ...
5
votes
1answer
2k views

Strange character when using listings package

I'm seeing an odd character like a very flat U, where there should be a space, with the listings package. See example below. Does anyone have any idea why this is happening, or how to get rid or work ...
7
votes
1answer
2k views

Set font in listings in XeLaTeX

I want to set specific font just for listings in XeLaTeX. \newfontfamily\consolas{Consolas} \lstdefinelanguage{MyLanguage}{ basicstyle=\ttfamily, .... % my language definition } ...
6
votes
1answer
3k 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?
7
votes
3answers
787 views

An environment for writing regular-font pseudocode

I want to create a pseudocode environment that looks like this: Basically, the font doesn't change - it's just the same as that of the surrounding text. It allows mathmode. And there is a box ...
3
votes
1answer
5k views

\usepackage{caption} breaks references to tables

I'm formatting the listings captions as follows: \usepackage{caption} \DeclareCaptionFont{white}{\color{white}} \DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}} ...
3
votes
1answer
877 views

How to set frame size in a listing

I'm trying to put a frame around my code, but the frame has the wrong dimension. How can I set them right? ...
5
votes
2answers
787 views

Add keyword with special character

I'm trying to add a language (Scheme) in the lstlisting package. \section{Scheme} \lstdefinelanguage{Scheme} {morekeywords={,lambda, cond, case, display, let, import, quote, quasiquote, unquote, ...
4
votes
2answers
476 views

Problems When Escaping from Listings

I would like to use LaTeX to document my C++ code, since I am able to typeset mathematics easily, as well as create diagrams using TikZ. I made a minimal LaTeX template for testing, but I have already ...
5
votes
2answers
3k views

Lyx is ignoring typewriter font setting for program listings

I'm using Lyx's Insert|Program Listing to insert a code listing into my document. Unfortunately, Lyx seems to ignore the Typewriter font selection I made in DocumentOptions under Fonts ⇒ ...
2
votes
1answer
1k views

Micro symbol µ in lstlisting

I'm writing a report about a website I'm working on to play cards online. I use lstlisting to display my PHP, JavaScript and HTML code. The problem is that I'm using a lot of µ's in my JavaScript ...
3
votes
1answer
1k views

Custom divider between 2 minipage and lstlisting

I am using the following code to have 2 boxes beside each other for code comparison: \documentclass[12pt]{article} \usepackage{listings} \begin{document} \begin{singlespace} ...
10
votes
2answers
220 views

Including sections of source code as a listing, while being robust to source code edits

Is there a way to input particular sections of source code using \lstinputlisting (from the listings package) in a flexible way? It's possible to use the firstline and lastline options to input ...
1
vote
1answer
830 views

Pointing to Java files not in root latex folder using listings

I am trying to use listings to point to a Java source code file. The file path is different from the Latex document. Below is an example of what I am trying to do, though it doesn't compile it says it ...
4
votes
1answer
267 views

Getting listings to highlight Func<x,x,x>

Given this image: How would you create a lstdefinelanguage that would make Func<double, double, double> highlighted without having to add spaces after each comma? \documentclass{book} ...
8
votes
1answer
663 views

Cleveref can't refer to line numbers in listings

Consider the following minimal example: \documentclass{article} \usepackage{listings} \usepackage{cleveref} % \crefname{lstnumber}{line}{Line} \begin{document} % \section{Section} ...
2
votes
1answer
599 views

captionof{lstlisting} Listingsnumber not in caption shown

Hi there having another problem. In the following Minimal Example a listing with captionof doesnt show the Listings Number in the Caption :( \documentclass[ 11pt, % Schriftgröße DIV10, ...
0
votes
0answers
54 views

Add keyword to a lstlisting language [duplicate]

Possible Duplicate: Extend a language with additional keywords? I'm using the package listings to write some Scheme code. I setted: \lstset{language=Lisp} since "Lisp" is the most ...
2
votes
1answer
654 views

The whitespace character in listings [duplicate]

Possible Duplicate: Explicit space character? The listings package by default replaces spaces in (for example) strings with a strange underscore style thing, almost like a square bracket ...
7
votes
1answer
942 views

Remove the header of List of Listings

I'm using classichtesis and I would like to remove the header of List of Listings. Before posting here, I tried the following strategies: The command \renewcommand\lstlistlistingname{}, suggested ...
5
votes
2answers
667 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, ...
8
votes
1answer
3k views

x86-64 assembler language dialect for the listings package

I'm writing a paper with a lot of x86-64 code listings in it. Unfortunately, the listings package itself does not have support for x86-64 instructions and register names (which are just named ...
8
votes
4answers
2k 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 ...
3
votes
1answer
2k views

LyX Error: Could not find LaTeX command for character '' (code point 0x2009)

I have been trying to copy and paste some code into LyX (via the 'Program Listings' menu item), and when I compile the document I get the LyX error: Could not find LaTeX command for character '' ...
6
votes
2answers
398 views

How to add numerical (ala No Starch Press) listing notes without XeTeX?

I've been following the instructions and code available at: https://zuttobenkyou.wordpress.com/2010/12/05/latex-saner-source-code-listings-no-starch-press-style/ I would like to add notes (and style) ...
6
votes
2answers
719 views

How to highlight all identifiers starting by '@'?

I would like to highlight any expression made of letters and that starts with one @. The use of moredelim=*[s][\color{blue}]{@}{\ } works only in case like @name is followed by one space. The ...