{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

3
votes
1answer
1k views

Showing only specific lines using the listings package

I am very new to TeX. My source code is in an external file, let's call it source.java, and I use \lstinputlisting{source.java}. How could I use only the lines 3-5 for my code listing? (and not the ...
3
votes
1answer
2k views

Line Numbers in Listing Outside of Paragraph

I use the listings package for code listings and I turned the line numbers on. But they appear left of the paragraph. I want them inside the paragraph. In the documentation it looks just right. Here ...
1
vote
1answer
405 views

lstaddons: Dynamic linewidth calculation

I use the package called "lstaddons" (creator, initial question) to get colored line backgrounds on listings. I want to color the whole line to the frame. What I miss there is a dynamic calculation ...
0
votes
0answers
72 views

How to undo the feasible breakpoints of `lstlisting`?

Is there a way to prohibit pagebreaking at the beginning/end of an lstlisting environment? I'm trying to keep together the following two pairs of lines: the first line of lstlisting and the line ...
0
votes
1answer
2k views

How to prevent beamer from removing the tab alignment of lstlisting?

I want to show my C# code snippet on the presentation slides using beamer. Because the code is long, I set the frame to be breakable using the frame option allowframebreaks. The code now can be shown ...
12
votes
1answer
263 views

Test if a number is in a comma separated range/list of numbers

Martin Scharrer posted a very elegant answer for the question "Creating a zebra effect using listings". I want to extend that code to highlight only lines given in a comma separated list. The ...
11
votes
1answer
6k views

How to change code example font in listings?

Does anyone know how to change the font for code snippets in the listings package? I'd like to have a constant width font, rather the fancy variable-width looking font that it has by default.
8
votes
1answer
344 views

How do I create a new command \listofcodes in latex?

In addition to tables and figures, I have a bunch of code pieces. Just like follows: \begin{figure} \lstinputlisting[ language=C++, breaklines=true, keywordstyle=\color{blue}, ...
7
votes
2answers
86 views

autounindent cannot work together with hyperref and hypcap

This question is related to my previous question answered by Jubobs here. I compiled the given code below with both TeX Live 2013 and TeX Live 2014 pretest. Both produce the same result. Case 1 The ...
7
votes
1answer
230 views

Scaling inline code to the current font size

Edit: Don't even bother reading the question. Just jump straight to Heiko Oberdiek's answer :) With the listings package, typesetting listings in some absolute font size is very easy; all you have to ...
6
votes
1answer
388 views

Listings line numbers that match the linerange specification

This is a follow-up question to First line number in lstinputlisting environment. Consider the MWE: \documentclass{article} %\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox ...
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 ...
6
votes
2answers
376 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) ...
5
votes
1answer
429 views

lstlistoflistings isn't showing the lstlistingname

I've actually a problem with my document. I redefined the listing for my ruby code: \usepackage{listings} \renewcommand\lstlistingname{Quellcode} \lstloadlanguages{Ruby} \lstset{% ...
5
votes
2answers
1k views

Listings alternative

Well like the title says I am asking if there is an alternative to the listings package. With more programming language definitions and the likes, and updated definitions for the current languages.
4
votes
1answer
109 views

How can I mimick the listing caption style for my custom “Listing (cont.)” caption?

I have the following LaTeX code which works fine: \documentclass[12pt,a4paper]{article} \usepackage[a5paper]{geometry}% just for the example \usepackage[utf8x]{inputenc} \usepackage{listings} ...
4
votes
2answers
167 views

Math escape in listings and surround white space

I want to use the double right arrow for some Scala code in listings. I thought I'd use the mathescape option and $\Rightarrow$. However, this "eats" whitespace around it, e.g. if I have foo ...
4
votes
3answers
563 views

Combine \listoflistings and \listofalgorithms into one list

The title said it all...I want to combine the two under one list with the title "Algorithms and program code". Style wise the page should match the usual style of the other lists (\listoffigures, ...
4
votes
1answer
901 views

texcl, escapeinside, and single character comments, with listings package

I'm using the excellent listings package to typeset some code in a language very similar to Scheme. The language has one type of comment: when an (un-escaped) semicolon is encountered, the rest of ...
4
votes
1answer
228 views

Command to insert filename in caption of a listing

I would like to have a command to insert listings that contain the filename in the caption. This works well as long as there is no "_" etc. in the filename. I also tried the suggestion from a ...
4
votes
1answer
486 views

remove unwanted contents from list of listings

The following code adds a wrong line to the list of listings \documentclass{scrbook} \usepackage{listings} \usepackage{filecontents} \begin{document} \begin{filecontents*}{democodefile} ...
4
votes
1answer
1k views

`backgroundcolor` in `lstset` does not work

When I use the backgroundcolor option in lstset, all I get is a colored line above the listing: \lstset{% language=Matlab, backgroundcolor=\color{blue} } and in the document: ...
4
votes
2answers
2k views

Can I get a shadowbox with rounded corners? (using `listings` package)

I'm using the listings package as below: \usepackage{listings} \lstnewenvironment{pythoncode}[1][] {\lstset{language=Python, basicstyle=\ttfamily\footnotesize, frame=shadowbox, ...
3
votes
1answer
136 views

Environment for two columns with lstlistings

In order to reduce copy-pasting, I want to create an environment that will produce a two-column table with headers and two listings in different languages, like below: \begin{tabular}{l l} Python ...
3
votes
1answer
258 views

odd displays of accentuated characters in lstlisting environment

when i try to write accentuated characters (éà...) in a lstlisting environment, hence : \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{xcolor} ...
3
votes
2answers
461 views

listings: General settings for a language seem to be overwritten/not respected

I struggle with the following listings styles. I have code of two different languages (R and LaTeX) in my .tex file. As some settings are the same for R listings and LaTeX listings, I define the style ...
3
votes
1answer
688 views

Problem with lstlisting in beamer… What am I doing wrong?

I am trying to to put an lstlisting environment in the left column, but I'm getting errors. Are lstlisting and the columns environment in beamer incompatible? Or is it something else? ...
3
votes
1answer
873 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 ...
3
votes
0answers
104 views

listings bug: space after quote collapsed when inlined with spaceflexible/fullflexible columns [duplicate]

Possible Duplicate: listings bug: space after literate replacement lost with spaceflexible/fullflexible columns I seem to have stumbled upon a minor bug in listings (version 1.4 as of ...
3
votes
1answer
350 views

How to remove the skip after a listing when “\parskip” is increased with “\baselineskip”?

I've increased \parskip with \baselineskip to use the "skipped" paragrahs style instead of the default "indented" style. However, this causes all listings to automatically include a baselineskip ...
3
votes
3answers
974 views

Changing side of line numbering in two columns documents

I'm trying to type some report and I have a small problem with the twocolums document class and the line numbering in listings. The document is on two columns : ...
2
votes
1answer
81 views

listings package: formating all numbers in language definition?

How to format all numbers in a code has been shown here. I have adapted it to include it in a language definition: \documentclass[fleqn, a4paper]{article} \usepackage{listings} \usepackage{color} ...
2
votes
1answer
737 views

Syntax highlighting for different programming languages [duplicate]

In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package: \lstset{frame=tb, language={[Visual]Basic}, aboveskip=3mm, belowskip=3mm, ...
2
votes
1answer
237 views

How to prevent figures from floating 'into' listings [closed]

I have a problem with floats and listings. Sometimes it happens that a listing is split over two pages and when a figure is near the listing it happens that the listing starts on the first page, on ...
2
votes
1answer
219 views

empty page afterpage listings

I get an emptypage on multi page listings if I use listings with afterpage. \documentclass{scrartcl} \usepackage{listings} \usepackage{afterpage} \begin{document} \afterpage{% %some fancy stuff } ...
2
votes
1answer
454 views

How to add a keyword with a blank space in Listings package? [duplicate]

I am trying to define a listing style in order to have fortran source codes which look like vim style colors. For example, I would like to give a specific color to end program or end module or ...
2
votes
1answer
476 views

babel package and lstlisting caption incompatibility

I am using babel package for Turkish language and I also use listings package. A code sample for one of my listings is as follows: \begin{lstlisting}[label=some-code,caption=Poo Class] public class ...
2
votes
3answers
2k views

Any ideas why this \newcommand{\n}{\lstinline|\n|} macro doesn't work?

So I created a new macro \newcommand{\n}{\lstinline|\n|} but for some reason when I use it, all I get is bold 'n' letter and not a nice \n. Any ideas?
2
votes
1answer
453 views

Multipages side by side listings

Could you tell me what should I do to be able to insert multipages, side by side listings in Latex document? I have already tried with \begin{minipage}, but it doesn't work with multipages. EDIT: ...
1
vote
1answer
198 views

Using lstlistings in two columns

My goal is to display source code (awk, Python, R and SAS) and text (their output) side-by-side. Both are loaded from external files, and can be pretty long sometimes (pagebreaking is inevitable), the ...
1
vote
1answer
2k views

Listing of a file with underscores in its name/path

I am writing a report with LaTeX and I need to list some source code. One of the files has some underscores in its path/name. When compiling the following line : ...
1
vote
1answer
366 views

Why does pdfLaTeX fail when I try to use `begin{lstlisting}` inside a user-defined environment?

I'm having trouble with the listings package. I can't compile the following minimal example through pdfLaTeX: \documentclass[a4paper, 11pt, twoside, openright, english]{memoir} \usepackage{listings} ...
37
votes
4answers
2k views

Has the time come for a LaTeX3 successor to 'listings'?

I'm currently looking for a nice and challenging open-source project to work/collaborate on after my thesis. I don't have a Comp. Sci. background, but I'd like to learn more about compiler ...
16
votes
2answers
7k views

How to highlight Python syntax in LaTeX Listings \lstinputlistings command

I am using package listings to import my Python source code into my LaTeX document. I use the command \lstinputlistings. I have a Python source like class MyClass(Yourclass): def __init__(self, ...
9
votes
1answer
247 views

How to show similar display of codes of different programming languages in LaTeX

I am very new to LaTeX and I am writing my thesis. In a chapter, I want to show my codes, which are in Mathematica. I use the listings package as follows: \documentclass{article} ...
15
votes
3answers
3k views

Preferred method for inline code samples

I tend to use the minted package for including code samples within my documents, which produces very nice output. However, because Pygments always produces a verbatim environment there's no way to ...
16
votes
1answer
151 views

How to strip a listing of all (line and block) comments without leaving white space?

I'm looking for an easy and robust way to strip all the comments from a listing. My approach (passing \@gobble to the commentstyle key) correctly removes all the one-line comments and block comments. ...
16
votes
1answer
380 views

How to remove the leading unnecessary white spaces when using linerange option?

To be honest, I am looking for people who already read the listings documentation completely. If those people also cannot solve it, then the documentation does not mention anything about it. Sorry for ...
11
votes
2answers
637 views

tcolorbox - list of listings?

In a book with figures, tables and listings, I figured out that all listings and some tables and figures look better when presented in a tcolorbox. The book has the usual tables of contents: ...
6
votes
2answers
2k views

Copy-pasting leading whitespace and blank lines in listings package (pdf) [duplicate]

I'm trying to use the listings package to typeset some code in a PDF document, in a way that allows me to copy-paste the resulting code. This mostly works well, if ...