{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

9
votes
2answers
2k views

How can I remove “Listing #: ” from listings caption?

I am working on a C++ reference manual for myself and I want good-looking listings. The Stack Overflow question entitled LaTeX source code listing like in professional books was very helpful but, for ...
8
votes
2answers
3k views

\lstinline!Foo! vs \lstinline{Foo}

I wonder what is the difference or correct usage of \lstinline!...! and \lstinline{...}? I like better {} because I feel there it's more consistent with other commands but for example in below ...
8
votes
1answer
962 views

autogobble for lstinputlistings

In the manual for listings it says that gobble has no effect for lstinputlistings. Since the manual is about four years old now and after reading How to automatically skip leading white spaces in ...
8
votes
1answer
1k views

Package to indent and syntax highlight C++ code

I am looking for a package to have an environment for C++ source code, with options for syntax highlighting, automatic indentation, proper multipage behavior, etc. I read something about the listings ...
7
votes
3answers
245 views

Can I include Chinese characters in listings? If so, how?

I'd like to include Chinese characters in listings. Can it be done, and, if so, how?
7
votes
1answer
1k views

lstlisting in a newenvironment

I have a problem with the lstlisting package. I want to define an \newenvironment with one obligatory parameter, which will be the caption name for the lstlisting. I will also have other lstlisting ...
7
votes
2answers
939 views

Listing with background color not line breaking correctly

I'm working on a project where I want to display an amino acid sequence. I want to let tex decide where to put the line breaks, but it doesn't seem to work in conjunction with highlighting certain ...
6
votes
1answer
160 views

Listing with two columns in a single fancy frame

I am playing a little with lstlistings and I wonder whether such a thing would be achievable for all my listings: How to achieve this kind of things? Note : I am searching for a solution I can ...
6
votes
2answers
219 views

Improving the POV definition in the listings package

I'm attempting to create a language definition in the listings package that mimics exactly the syntax highlighting in POV-Ray 3.6 for Windows (http://www.povray.org/download/). Here is a screenshot ...
6
votes
2answers
324 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 ...
6
votes
3answers
354 views

How to skip both the first n rows & the last m rows simultaneously?

I am using showexpl.sty to display side by side the code snippet and its corresponding output. Because of the paper size limit, I intentionally want to remove the "redundant" rows, i.e., the first n ...
5
votes
2answers
690 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, ...
5
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 ...
5
votes
1answer
3k 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 ...
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
87 views

Strange interaction between hyperref, listings and animate

I am trying to have a listing inside an animate environment. However I can't manage to do it if the hyperref package is loaded. This is a MWE, obviously in the real application I need hyperref for ...
4
votes
1answer
262 views

Captioning an mdframed box without making unbreakable

I would like to a have a caption below my mdframed box (outside the border if possible) which sometimes span across multiple pages. I managed to create a caption several ways but the pagebreaks are ...
4
votes
2answers
4k views

\lstinputlisting will not continue to next page

So I have this LaTeX snippet: \section{Appendix} \listoffigures ... \begin{center} \begin{figure} \caption{MacroCell with 8 AND Gate Arrays} ...
3
votes
1answer
222 views

How to embed special markers into the code listing that will mark certain parts of code to be colored using a custom scheme?

I would like to color my C# code listings as Visual Studio does. However, all language definitions that I found so far only color the keywords and not the user types. I understand that it requires ...
3
votes
1answer
8k 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} ...
3
votes
0answers
105 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 ...
1
vote
0answers
93 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 ...
1
vote
1answer
450 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
1answer
3k 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
276 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.
10
votes
1answer
80 views

How can I define additional literate replacements without deleting existing ones?

I'm trying to improve some language definitions that ship with listings. Those improvements consists in, among other things, a number of literate replacements (see subsection 5.4 of the listings ...
8
votes
1answer
354 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
90 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 ...
6
votes
3answers
679 views

Listing with mixed english and russian symbols in comments

I'm using the listings package for formatting .cpp code in LaTeX. My code needs to have mixed English and Russian words in comments. The font must be monospaced (preffered Courier family). /* Prints ...
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
389 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
1answer
512 views

Narrow underscore in listings package

I've been using the listings package for a while, but have only recently noticed that the underscore is rendered with less width than the other characters. I'm working on some code snippets now which ...
5
votes
1answer
483 views

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about ...
5
votes
1answer
74 views

lstlisting directly after section start removes margin before next section

If I place an lstlisting directly after the start of a (sub)section, the margin before the following (sub)section (title) disappears. Here is a an example document showing the issue: ...
5
votes
1answer
607 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{% ...
4
votes
2answers
138 views

Bad Character code (256)/ \select@language{greek}

I was trying to install minted package in TeXLive. I installed it and then run sudo tlmgr update --all. It was running slow so I stopped it using Ctrl+Z in an ubuntu terminal and then I run sudo tlmgr ...
4
votes
1answer
128 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
205 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
717 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
1k 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
273 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
533 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
109 views

How to copy/paste multiple spaces from lstlistings?

This is a continuation of a question that I asked already: How to copy/paste from lstlistings?. The solution presented there does not work if the text within the lstlistings environment contains ...
3
votes
1answer
160 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
349 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
616 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
923 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? ...