{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

2
votes
2answers
341 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
439 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
24 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
644 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
182 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
58 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
119 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 ...
13
votes
1answer
243 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: ...
4
votes
1answer
489 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?
6
votes
2answers
269 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
90 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
417 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
51 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
150 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
119 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 } ...
5
votes
1answer
1k 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
249 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
545 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 & ...
4
votes
2answers
159 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 ...
5
votes
1answer
308 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
139 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 ...
0
votes
0answers
127 views

multiple listing styles with hyperref and caption packages

This is a follow-up question to Multiple listings styles. The MWE from the accepted answer works fine. Unfortunately, when I add the hyperref package OR the caption package (or both of them), the ...
3
votes
1answer
1k 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?
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 ...
4
votes
1answer
139 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
715 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
188 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
113 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
167 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
56 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{ ...
5
votes
1answer
181 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
78 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
258 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
72 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
173 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
155 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
222 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 ...
4
votes
1answer
178 views

How to wrap floated minted listing in my own environment?

Here's what I'd like to do: \begin{code}{c}{Hello World in C}% I would prefer the caption to be optional #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ...
7
votes
1answer
132 views

Printing index of keywords in listings for first mention only

I am writing a technical report, which integrates chunks of code using listings. I would like to add an index of the keywords used in the listings (using index=[1][keywords]), but reporting in the ...
1
vote
0answers
429 views

Change font style for \texttt [closed]

I am afraid if this is a repeat question. I have checked the following links for any hints: Change font size of \texttt globally? Using same font for \texttt and \Verb The question is simply. I ...
7
votes
1answer
281 views

Listings - break on whitespace+

I'm using listings for the first time, and have some rather long lines of code. I get that I can break lines automatically with breaklines=true, and I can break only on whitespace with ...
1
vote
0answers
71 views

Can I get the list of all letter/digit/other characters inside LaTeX? [closed]

I'm searching for a command which is (almost) the inverse of \catcode. Is there a command to print all the characters of a character group? Use-case: disable linebreaking of listings at all but one ...
3
votes
1answer
1k views

Problem with lstlinsting biblatex utf8 T1 and babel

I am a Spanish speaker. I have in my TeX file all the usual stuff for my language. Also I use lstlistings and now I want to use biblatex (ex bibtex user). However I can not get working together this ...
1
vote
0answers
92 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 ...
4
votes
1answer
242 views

How to avoid double dash seem as a continuous line?

I'm using listings to show some source code (bash scripts) in my document but there is a problem, when using mono spaced fonts, the space between dashes is very small and in the printed document two ...
4
votes
1answer
203 views

Making Inline Code Printing Pretty

I have to include small code snippets like method and class names within continuous text. I do not want to display those snippets as complete seperated listings, they should be displayed inline, ...
5
votes
1answer
173 views

Unicode characters in a listing environment are not colorized!

When using the package listing, colorized comments will not yield colorized exotic unicode characters. This is a minimal working example: \documentclass{minimal} \usepackage{ ...
7
votes
1answer
129 views

How can I arrange 3 equations in boxes with arrows like this picture?

Can any one tell me how to make a figure exactly like this picture, with 2 arrows etc. This is my unsuccessful attempt: \begin{figure}[ht] \centering \begin{minipage}[b]{0.35\linewidth} ...
4
votes
1answer
176 views

Color lines in source code that is embedded in LaTeX

I am looking for a way to mark some lines in a source code sample that will be integrated into my LaTeX code. I already found solutions to embed source code and have syntax highlighting like this ...
4
votes
1answer
110 views

Listing composed of multiple “sublistings”

As a workaround currently I am using framed Verbatim, but I would like that this set of listings appear as a single listing in the list of listings the codes be rendered by the listings package ...