{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

1
vote
1answer
87 views

Listing package only outputs black colored source code even though the language parameter is specified

The problem is pretty much in the title. With this code: \documentclass{report} \usepackage{listings} \begin{document} \lstset{language=Python} \begin{lstlisting} def ...
8
votes
1answer
173 views

How do I refer to a line of code from a C file?

I have a source code listing in my appendix. I have added it like this: \lstinputlisting[language=C]{Appendix/tcas/tcas.c} I want to refer a line, e.g., line 72, from this file. How do I do this ? ...
4
votes
2answers
3k views

LaTeX - a single code listing over multiple pages

I'm using the lstlisting package in my diploma thesis to include code snippets. Unfortunately one of them won't fit on a single page. Stil LaTeX won't split it over multiple pages and instead the text ...
7
votes
2answers
343 views

tcolorbox: option for “listing outside (but ABOVE) text”

The tcblisting environment provided by the tcolorbox package allows one to display LaTeX codes in the lower part of a tcbox and the output in the upper part of the same tcbox, using the text and ...
3
votes
1answer
122 views

Draft mode breaking with listings in sublists

%sublisting.tex \documentclass[draft]{beamer} \usepackage{listings} \begin{document} \begin{frame}[allowframebreaks] \begin{itemize} \item Here follows the source code of this document. ...
4
votes
1answer
786 views

R language parameters for `listings` package

I tried all answers posted here or on other pages, but nothing worked. I need to set the parameters for listings package to simulate R code, so: \usepackage{listings} \lstset { language=R, % ...
1
vote
0answers
223 views

Listings: spacing between linerange and numbering [closed]

This is a combination of hacks, and only of interest for those who want hacks down to the detail. It is actually a two part question. I was going through some listings setups and hacks: Firstly ...
7
votes
1answer
137 views

Two block commands in \newenvironment [duplicate]

What is wrong with following document? \documentclass{article} \usepackage{xepersian} \usepackage{verbatim} \newenvironment{code} {\begin{latin}\begin{verbatim}} {\end{verbatim}\end{latin}} ...
5
votes
1answer
18k views

Use package listing error: Listing.sty not found

I want to use the listings package, but every time I compile my document in Texmaker I get the following error: !LaTeX Error: File `listings.sty' not found. Before this happens Texmaker displays me ...
6
votes
3answers
593 views

tcolorbox listing error using beamers begin{frame}

I've just started using the tcolorbox package for slides for a LaTeX course. It works nicely to box LaTeX code, interacting with the listings package. However, I ran into trouble when I tried to make ...
2
votes
1answer
397 views

Alternate colback and colbacklower in tcblisting

I have written a new environment based on tcblisting from package tcolorbox. I want the background color for code always in "gray" and the background color of the text compiled in "white". He held ...
9
votes
4answers
657 views

Verbatim, wrappable and Unicode text included from a file

I am trying to output several megabytes of UTF8 text into a printable format. As enscript and friends don't like Unicode, this Unix SE question soon turned to LaTeX. Summary of requirements: ...
3
votes
1answer
377 views

Problem with special characters comments in listings package

I'm employing the listings package to show VHDL code in my document in a nice way, to do so, I have defined my own version of VHDL, thus: \documentclass{article} \usepackage{listings} ...
1
vote
0answers
47 views

Listing Moved to End of Document / Other Locations [closed]

I have a listing that is pretty long and it's forced to the end of my document. If I shorten the code, I've noticed it allows it to stay where it should be, otherwise it gets pushed behind/in front of ...
2
votes
2answers
699 views

Avoiding math mode inside a lstlisting

I'm using listings to highlight some PHP code. My problems comes when the code to insert contains the '$' symbol, for example: \begin{lstlisting}[style=PHP] Select * FROM users WHERE user_name = ...
4
votes
1answer
1k views

Make arrows inside lstlisting

Inside my lstlisting environment I want to make the assignment symbol an arrow instead of =. How can I do that? Adding just \leftarrow doesn't work, because then the whole word is displayed.
0
votes
0answers
29 views

Suppress extra inter-character horizontal space in lstlistings [duplicate]

When I use the lstlisting environment from the listings package, there is a bit of extra space between characters, even in a monospaced font. For code, I use a monospaced font (basicstyle=\ttfamily), ...
3
votes
1answer
1k views

How to define default 'program listing' title and parameters in Lyx

I'm using LyX software and need to embed python code snippets and the option I found is to put snippet in a file and then use: insert> file> Child Document ----> choose the snippet file ----> set ...
11
votes
2answers
236 views

Maintainable typesetting of placeholders in code snippets

I'm looking for a maintainable way of typesetting placeholders in code snippets. In my listings, I would like that anything contained between the two delimiters @< and >@ be typeset in ...
3
votes
1answer
79 views

Adjust width of listings including pagebreaks

I have my own lstlistings environments which are framed. Since I wanted to adjust the width so the frame starts with the text I used a minipage inside the lstlisting. (See MWE). But as I have quite ...
9
votes
2answers
165 views

Line numbering of listings

In the listings package, the stepnumber option controls the interval of line numbering, but I found there's no such option which controls the starting number. Is there a way that I could show numbers ...
14
votes
1answer
697 views

How to make figure and listing share their counter

I'm using the "listings" package to write pieces of code (XML, RDF, Java, etc) and I want them to have the same counter of the Figure environment. For example, Listing 1: blablabla Listing 2: ...
7
votes
1answer
1k views

YAML Syntax Highlighting

The listings package does not support YAML out of the box. Does a package exist that extends listings with YAML support? More generally, is there a good listing somewhere of extensions to listings?
8
votes
2answers
2k views

How to have straight single quotes in lstlistings [duplicate]

All single quotes in code samples are displayed as backticks and the copy-pasted code can't be compiled without fixing the quotation. Is it possible to prevent this? for example: ...
5
votes
1answer
189 views

margin notes disturb line numbering of listings

I've tried to add margin notes for listings (PS: footnotes work fine), but when line numbering is on, the margin notes disturb the numbers: \documentclass{article} \usepackage{listings} ...
5
votes
2answers
832 views

Displaying C++ source code with TikZ

I’m trying to have some C++ source code displayed in a TikZ environment (I'm using TikZ to have several copies of the same text on a single page, so that when it is printed I can cut the sheet into ...
6
votes
1answer
116 views

Suppress modification of listings in draft mode

In reference to this: HERE How can I suppress draft mode from altering my input listings, or, at least rendering a box of the same size as what the listing would occupy. Draft mode is very useful ...
3
votes
0answers
368 views

Show vertical line for indentation of LaTeX code listing [closed]

Is it possible to enable a continuous vertical line on code to show indentation? I am trying to use the following code from a stackoverflow question. Originally, the documentation suggests using ...
4
votes
1answer
285 views

Why does a space destroy my keywords in listingspackage?

I am using the following: \usepackage{listings} \lstset{ language=C, keywordstyle=\color{pantone309!90}, morekeywords={ omp, parallel, \#pragma } ...
6
votes
1answer
5k views

color a text line in a code {lstlisting}

I try to use the package xcolor into a lstlisting code as follows: \begin{lstlisting} \color{red}{text...} \end{lstlisting} but I can't color the "text..." comments. Someone could help me, ...
4
votes
1answer
631 views

Consolas: Straight Quotes

I am using the listings-Package to display code. As I am using The Consolas Font as the Monotype-Default I expected straight quotes which isn't the case (check my MWE) ...
6
votes
2answers
2k views

How to put source code in a LaTeX table?

I am comparing source in a paper and I would like to put them in a table, so the differences are easily spotted. I used the following LaTeX code: \begin{tabular}{ | l | l | l |} Option 1 & ...
5
votes
2answers
414 views

How to line-number 1,5,10,15,20,25… in Program Listing in Lyx

I basically want every 5th line numbered, but would like to keep to 5,10,15,20,... as that seems intuitive to readers. So that means 1,5,10,15,... The first gap is 4, all subsequent ones are 5. Is ...
10
votes
1answer
2k views

Lstlistings reference to line number

How can I place a 'label' marker inside a lstlisting environment (external file imported and formatted via the listinputlisting command) so that I can cross-reference a particular line number? In ...
2
votes
1answer
275 views

2 column: how to squeeze line numbering closer, shift code over in Lyx

I'm using 2-column in otherwise-default Lyx, with several program listings. Some of them have line numbers. Due to the 2-column layout, the line numbers take a good chunk of the gutter between ...
7
votes
2answers
3k views

How to reduce Program-Listing line spacing in LyX

Using LyX 2.06. I have a standard document with 1.5 line spacing, but I want my program listings to use 1.0 line spacing. Is there a simple way to do this?
7
votes
2answers
3k 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 ...
4
votes
1answer
414 views

How can I get identifier style to apply to '%' (in a Perl listing)?

When using Perl variable names with sigils with listings, the $ and @ sigils somehow get coloured in identifierstyle, but the % sigil remains unstyled. Therefore, this code: \documentclass{article} ...
1
vote
1answer
4k views

Caption below lstinputlisting in multicols + redefining lstlisting caption format

I have 2 problems with caption for lstlisting. I can't get the caption of lstlisting to go below the list when it's in a multicols environment. Although I've added ...
4
votes
2answers
442 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 ...
2
votes
1answer
244 views

Multiple listings in one box with sub captions and using listings counter

I am using separate counters for (graphics) figures and listings. I am using the caption and subcaption packages. I construct sub-figures using subfigure: \begin{figure} ...
3
votes
2answers
430 views

Caption package destroys center/varwidth

I have received a wonderful comment how to get listings centered: \documentclass[a4paper]{book} %\usepackage[hang,small,it,hypcap=true]{caption} % screw hypcap \usepackage[T1]{fontenc} ...
2
votes
0answers
58 views

Center a Listing [duplicate]

What is a simple way to make a lstlisting centered? Like \documentclass{article} \usepackage{verbatimbox} \usepackage[T1]{fontenc} \usepackage{fancyvrb} \usepackage{listings} \lstset{ ...
6
votes
1answer
549 views

\lstset{numbers=none} not working

I'm trying to have LaTeX examples in a document. I use the showexpl package which lets me use the listings package options. Because all fragments are short, line numbers are redundant. The following ...
5
votes
1answer
148 views

Font for inline Listings is not changing

I am writing my thesis in LaTeX and use \lstinline{} a lot. The problem is that the font on the output does not change to 'this', but rather continue like 'this'. How do I correct this behaviour? I ...
6
votes
1answer
564 views

How can I put a curly brace inside a listing to group code lines?

I am using the listing package. Is it possible to use curly braces to group some lines in the listing so as to be able to put an explanation to the right? I'm trying to use the code given in Peter ...
3
votes
1answer
86 views

How can I use \vfill in a lstlistings environment?

I'd like to do something like this: \begin{lstlisting} public do(int whatever} { \vfill } \end{lstlisting} So basically, I want a method definition and then add spaces in the body of the method ...
2
votes
1answer
308 views

listing package error

I am using listing package for inserting code snippets in my thesis in several chapters of my thesis. I use the following style to insert code snippets : \lstset{emph={sensors, string}, ...
7
votes
1answer
300 views

Wrong border position on tabular when using lstlisting

I have encountered a problem while using tabular environment. The following code \documentclass [12pt,a4paper,oneside]{report} \usepackage {listings} \usepackage {fontspec} \usepackage {enumitem} ...
4
votes
1answer
381 views

Wrap lines of code with curly bracket and add some text next to it

I am currently studying algorithmic complexity of some programs, I have to deal with lines and lines of code and it would be really nice and helpful if I could wrap some of those lines in a right (or ...