{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
424 views

LaTeX commands in Verbatim using fancyvrb and listings

I am trying to use LaTeX commands like \textbf, \textit, \textcolor in fancyvrb combined with listings. Especially I want to bold and color any text or entire blocks of Java code (not just keywords) ...
7
votes
1answer
173 views

Faster compiling [duplicate]

I'm writing at my thesis and it has now about 60 pages.. When I want to compile it (to pdf), it lasts about 20 seconds.. Is it normal? I think, the included graphics costs a lot of time?! ...
4
votes
2answers
115 views

Integrating listings with fancyvrb

I am trying to use fancyvrb with listings and I get an error saying l.2 ...{Verbatim}[formatcom={\lstset{style=Java}}] Package Listings Error: language java undefined. ...
4
votes
1answer
54 views

Listings environment within another environment

\newtheorem{alg}{Algorithm}[subsection] \begin{alg}\label{alg:1} \begin{lstlisting}[frame = single, breaklines = true, numbers = left] test code \end{lstlisting} \end{alg} How can I prevent the ...
1
vote
0answers
10 views

include “\end{lstlisting}” inside lstlisting block [duplicate]

I'm writing a shell script that returns all shell scripts in LaTeX lstlisting environments. Now, the shell script that does this is also included in the LaTeX file it generates, which gives me a ...
2
votes
1answer
64 views

Listing / lstinline and line breaks

I'm using \lstinline among other things for writing file names of my source files. For example \lstinline{foofoo.pl} Then, sometimes I have the problem that some lines containing this string are ...
4
votes
2answers
86 views

How to colorize escaped math in syntax highlighted listings?

my listings are syntax highlighted using \lstset with escapechar=$ and commentstyle=\color[rgb]{0,0.5,0}. Now my C-code looks like int16_t speed; // calculated speed in $\(\frac{cm}{s}\)$ and the ...
5
votes
2answers
139 views

Why is the space between words in my source code listing so big?

I used the following code to list my java code, but the it looks like there's too much space between words. What can I do? % source code listing \usepackage{listings} \usepackage{color} ...
4
votes
1answer
105 views

Math symbols in listings

Does anyone know how to write math symbols such as sums and integrals inside a listing? \begin{lstlisting} vl(i)= \sum\limits_{i=1}^N{Al(i,j)*xl(j)} ; i = 1,3 \end{lstlisting} UPDATE: ...
3
votes
1answer
74 views

How to set a background color for a listing?

Someone who knows how to fill with color only the box? \begin{shaded} \begin{lstlisting} if (a < b) { printf("A is smaller than B!\n"); } a = b; \end{lstlisting} \end{shaded}
5
votes
1answer
68 views

Adapt labelling facilities of listings package

I compiled a catalogue from past exercises for a lecture (running to several hundred pages), which makes consistent labelling a bit of an issue. My solution is to use labels of the form ...
6
votes
1answer
53 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 ...
2
votes
1answer
97 views

Footnotemark in caption of listing causing problem

I have the following listing: \begin{lstlisting}[float=h,caption={Description\footnotemark.}, label={listing2}, keywordstyle=\color{blue}\bfseries, ndkeywordstyle=\color{black}\bfseries, ...
4
votes
1answer
114 views

Weird spacing issue using listings delimiters

I'm using moredelim (with prefix il) to typeset one-line "comments" in a very specific way: delimiter %% in red, rest of the line in blue. My approach works mostly as expected, aside from some ...
7
votes
2answers
110 views

Can comment delimiters be typeset in a style different from commentstyle?

Using listings, I'm trying to typeset single-line comments in a very specific way: although whatever follows should be typeset according to the value passed to the commentstyle key, the opening ...
9
votes
1answer
71 views

How can I execute some code at each occurence of an EOL character in a listing?

My question is very similar to Peter Grill's, How to detect a tab character when processing a literate in lstlistings? I'm trying to count the number of ^^M characters encountered in my listing ...
3
votes
1answer
102 views

How can I define multiple identifier classes and styles in listings?

I'm trying to add different styles (color, etc.) to different groups of words in the listings package. Note that my question is different from How can I use multiple declarations (\textbf, \emph) in ...
3
votes
1answer
109 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 ...
6
votes
1answer
100 views

Equal spacing for figures and listings

I want to include figures and listings in my document and I want them to have the same spacings to text and captions. \documentclass[a4paper,12pt,openany,parskip,oneside,ngerman,headsepline]{scrbook} ...
5
votes
1answer
60 views

Preventing a code listing of multiple pages to be split to several parts

I have a lstlisting that doesn't fit on one page. It continues correctly on another page but instead of putting the last lines in the beginning of the next page it actually splits into three parts on ...
5
votes
1answer
86 views

Emphasize (color) contents between two delimiters in listings, but not the delimiters themselves

I want to typeset some LaTeX source code by listings. I've tried this: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{ delim = [s][\ttfamily\color{orange}]{$}{$} } ...
11
votes
1answer
182 views

How can I typeset LaTeX source code with this very specific syntax highlighting? [closed]

I want to put some LaTeX source code in my PDF output with the style like this: Color in text mode is white, in math mode is yellow and in comments is grey. For control sequences, I divide it into ...
1
vote
1answer
50 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
111 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 ? ...
3
votes
2answers
379 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
183 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
54 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. ...
3
votes
1answer
113 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
90 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
91 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}} ...
3
votes
1answer
3k 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 ...
4
votes
2answers
146 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
137 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 ...
8
votes
4answers
215 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
77 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
32 views

Listing Moved to End of Document / Other Locations

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
232 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 = ...
1
vote
0answers
205 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
23 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), ...
2
votes
1answer
259 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 ...
10
votes
2answers
154 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
53 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
96 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 ...
11
votes
1answer
121 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: ...
3
votes
1answer
196 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?
5
votes
2answers
113 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: ...
4
votes
1answer
58 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
310 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 ...
5
votes
1answer
33 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 ...
2
votes
0answers
90 views

Show vertical line for indentation of LaTeX code listing

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 ...