{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
0answers
31 views

lstlistings messes up spacing before subsequent section headings [duplicate]

I'm typesetting a grammar specification for a programming language, which leads to many short snippets of grammar and example code interleaved in the document text. The issue I observe is that an ...
2
votes
0answers
40 views

Problem with beamer and listings package, cannot obtain pdf [closed]

I want to use \usepackage{listings} in a beamer presentation. I obtain "Process exited normally" but it says "Error no file found". The process exits normally but texmaker doesn't find any pdf file. ...
9
votes
1answer
91 views

How can I highlight \[…\] properly in LaTeX listings?

The listings package provides the option moredelim, allowing for custom styles for words enclosed by given delimiters. I would like to give $...$, \[...\] and $$...$$ custom colors. \[...\], however, ...
6
votes
1answer
145 views

Keywords with spaces in Listings

I want spaced keywords in listings (that is, keyword, with spaces in between). Now, there are some questions in this site already answered, like this one, where the official answer is that “it is not ...
2
votes
1answer
75 views

How to set different color in listing?

I want to split the listing into three different colors. How to do it? I have read Peter Grill's answer and apply it like this: \documentclass[12pt]{article} \usepackage[utf8]{inputenc} ...
7
votes
1answer
170 views

RequirePackage and usepackage behave differently

I design exams which should contain code samples using pdflatex. In lecture scripts I successfully use the listings package. The general design is done via the exam document class. I created my own ...
4
votes
1answer
68 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 ...
2
votes
1answer
80 views

Condensed comment font in listings

I'm trying to condense the size of my comments by using a condensed font however its not working correctly. The font shape looks fine with ttfamily enabled in basicstyle, however, there is a huge ...
3
votes
1answer
84 views

Verbatim environment with gray background color and italics

I want a verbatim environment with gray background color and italics(bold fonts may be used also). The \lstlisting can set background but can't set italics. The \mdframed combined with \alltt can ...
7
votes
2answers
89 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 ...
2
votes
1answer
40 views

Listing package showing newline after the last line of code

I haven't been able to suppress this newline only with configuration. In the listings documentation it is said that the showlines option if set to false won't let the newline appears, but that is not ...
5
votes
2answers
99 views

How can I force lstlisting to expand an argument?

I'm trying to use the listings package with a variable language (it's actually for a package). However, I can't seem to pass a macro as the value half of a key-value pair. Here's a simple example: ...
2
votes
1answer
48 views

texcl option to listing package's lstset - not working in block comments

I am using the listings package to typeset code listings. I am further using the texcl option in my \lstset (\lstset{texcl}) so that I can write TeX code, including math, in comments. However, this ...
3
votes
1answer
85 views

How to define colors in style file (lstlang0.sty)

Per the listings package documentation, I have a file lstlang0.sty in the same directory as my .tex file (well, .lyx file) which defines a new language. I used to have this language definition in my ...
10
votes
0answers
384 views

TeXLive and MikTeX behave differently in handling BOM

It is a followup of my answer that has been converted to comment (click) posted several decades ago. Shortly speaking, MikTeX does not remove leading BOM but TeXLive does as shown in the following ...
2
votes
2answers
81 views

Arabic font for Listing

Currently, I am using Listings package in order to insert my XML text in the document. For example the code: \begin{lstlisting} <Product Title="نوکیا" Type="گوشی"> \end{lstlisting} The ...
1
vote
1answer
31 views

How should I use reference with setcounter{lstlisting}{0}?

I specified in my lstlisting both caption and label. Also before every section I use: \setcounter{lstlisting}{0} My listing from PDF view looks like: Listing 4.1.2 SomeCaption When I am using ...
3
votes
1answer
178 views

Why am I getting this “Couldn't load requested aspect” error?

I want to include some Matlab scripts in my thesis. Unfortunately, I can't get listings to work properly. If I try to compile the following code, \documentclass[11pt]{report} \usepackage{listings} ...
2
votes
2answers
72 views

\input produces errors, copy&paste not

I'm working currently on a beamer-document and want to use LaTeX-code. Therefore I set up the listings-package in the following way: \documentclass[12pt]{beamer} \usepackage{listings} ...
4
votes
2answers
97 views

Trouble Displaying Listings Package

I will show the settings of the listings package, like this MWE: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstset{ backgroundcolor=\color{yellow!10}, ...
1
vote
1answer
47 views

Listings in Minted not working

To surround the code with a box, the documentation suggested to use listing environment. But the code has no effect at all. What is the issue here: My MWE: \documentclass[a4paper , 12pt]{article} ...
0
votes
1answer
37 views

Spanish character not working in 'listings' package [duplicate]

I have a Spanish character not working in 'listings' package. In the code example below, the first occurrence of the word 'ignorará' works. The second generates the error: ! Package inputenc Error: ...
3
votes
1answer
79 views

Use textit in listing

How can I use \textit in a listing? \documentclass[a4paper]{article} \begin{document} \begin{lstlisting}[label=test] Some code. \textit{This should be italic.} Some code. \end{lstlisting} ...
1
vote
1answer
38 views

Extra the word 'numberstyle' in listing

What's wrong with this ? I define listing style like below. \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} ...
3
votes
2answers
55 views

Obtain a single TOC from using both listings and SASnRdisplay

I began using LaTeX just yesterday and I'm stuck on a frustrating problem. I need to automatically include a lot of source code into my document and getting it code-highlighted, row-numbered, labeled ...
7
votes
2answers
157 views

highlight line numbers in listings

I would like to highlight the line numbers of the lines I refer to with lstlistings. I use escape characters to define labels in my Listing to which I refer later in my document (e.g. see Line X of ...
2
votes
1answer
90 views

How to include program listings in C# with custom font and syntax highlighting in LyX?

I'm rather new to LaTeX and use LyX editor to create my documents. There are similar questions but none of them answer how to do that in LyX. I am wondering, how to include a program listing in ...
3
votes
1answer
79 views

lstlisting `moredelim` doesn't work with comments

I'm trying to add some overlays to a piece of code, and I'm defining it using moredelim. However, when I use it on comments within the code, the moredelim stops working. What am I missing? ...
1
vote
1answer
43 views

error when using tcolorbox + listings for multipage source

I'm try to highlight source code with colored background, but I face a bit error. first image is created with listings only and that is what I need. You can see on the last image that basicstyle ...
1
vote
1answer
60 views

How can I highlight keywords with special characters or numbers in them?

In the following MWE the declared keywords te-st and 999 are not highlighted as expected: \documentclass{scrartcl} \usepackage{listings,xcolor} ...
3
votes
1answer
91 views

Problem with mdframed, lstlisting and subfig

I'm trying to understand why the following code does not compile. \documentclass[12pt]{article} \usepackage[svgnames]{xcolor} \usepackage{filecontents} \usepackage{tikz} ...
1
vote
1answer
72 views

lstlisting environment with UTF-8 encoding [duplicate]

I have a problem using lstlisting environment with utf8 encoding. I got this error Package inputenc Error: Unicode char \u8:�\expandafter not set up for use wit MWE \documentclass{article} ...
1
vote
2answers
256 views

How to change font size for specific lstlisting

I have a java lstlisting and it is too big and does not mach a single page. Is there any way to specify font for specific listing, not all listings in document?
3
votes
0answers
86 views

Object-oriented class typesetting? [closed]

I am looking for a way to beautifully typeset an OO class like : classname { properties: prop1 : integer prop2 : Node methods: someMethod() } With the look ...
3
votes
1answer
110 views

How can I highlight a keyword that contains a dash or a slash? [duplicate]

I have a Clojure listing and I want to colour certain keywords whereas I can only do for strings not including any dash ('-') or slash ('/). But I also need to consider keywords consisting of with ...
4
votes
0answers
103 views

Issues using listings package [closed]

I am using LaTeX to write my internship report (I started to learn it one month ago), and I have some issues using the package listings. I'm not sure if everything is possible: How can I add a ...
4
votes
1answer
94 views

after change \lstset, reset of normal characters can NOT display

I met one problem(maybe three, I will describe them in detail), I'm trying to add code list in latex with listings package. First with limit configuration: \usepackage{listings} ...
5
votes
1answer
75 views

Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX? ...
1
vote
0answers
52 views

Center code in a lstlisting float

Out of pure laziness, I decided to create lstlisting floats with the option offered by the package: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \begin{document} ...
2
votes
1answer
54 views

How to temporarily disable a comment delimiter when using listings [duplicate]

In the preamble of my document, I put the following command to allow strings wrapped with < and > printed as italic-styled comment: ...
3
votes
1answer
69 views

Spacing looks wrong in listings when using fixed columns

When I use columns=fixed to present my listings, the letters are spaced too far apart. Why is that? \documentclass{article} \usepackage{listings} \lstset{columns=fixed, basicstyle=\ttfamily}} ...
0
votes
0answers
22 views

Formatting Annotations in Comments [closed]

I like to format annotations that occur within comments of C source code with the listing package. Here is an example of the code: //@ ghost unsigned int no_btn_press = 0; /*@ @ behavior ...
4
votes
1answer
88 views

\lstlistoflistings causing error

my problem is, I added some listings to my Tex document. On the first run everything went fine and all was shown. After the second rerun, it does not compile anymore. Error: !Paragraph ended before ...
1
vote
0answers
7 views

Extra endlstlisting when the code include endlstling [duplicate]

I want to print the following code \usepackage{listings} \usepackage{color} \definecolor{name}{rgb}{0.5,0.5,0.5} ... \lstset{key1=value1,key2=value2} ... \begin{lstlisting} Code \end{lstlisting} ...
3
votes
0answers
36 views

Code in listing not formatted correctly [duplicate]

My preamble is as follows: \documentclass{llncs} \usepackage{xcolor} \usepackage{harvard} \usepackage{listings} \usepackage{chngcntr} \makeatletter \lst@InstallKeywords ...
3
votes
0answers
46 views

Relatives/absolute path for listing with subfiles

I have problem with path management. Let me explain you: I work with subfiles that are arranged in this way: REPORT --Main.tex --lab1 ----Matlab ------CodeLab1.m ----Report ------Report_P1_1.tex ...
5
votes
0answers
39 views

How can I make a custom environment that wraps listings?

Thanks to this answer, I know it is possible to float and wrap text around a listing. I would like to setup an environment for mini-code snippets that always floats and wraps the same way. I can ...
0
votes
0answers
110 views

interference listings styles in tcolorbox [closed]

I'm trying to create a package to encapsulate pstricks examples using tcolorbox and showexpl. Defined a new environment PSTexample and style for listings (mystyle) that does not interfere with ...
4
votes
3answers
108 views

Put a grey background behind code extracts in a Latex document (like this site does)

I'm using the listings user package to insert extracts of code into my document, however it isn't distinct enough from the normal text as I'd like. Is there a way to put a grey background behind the ...
4
votes
1answer
106 views

How can I highlight SPSS Syntax code with the listings package?

I'm writing my master thesis at the moment and I want to add some code listings to the appendix. The code is written in "Syntax", the programming language of SPSS Statistics. Is there a way to ...