Tagged Questions

{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

5
votes
1answer
80 views

lstlisting environment as item in description

I would like to show some listings inside a description environment like this: \usepackage{listings} % fancy code listings \usepackage{caption} % fancy chapters for fancy code listings ...
1
vote
1answer
82 views

Set linewidth of listings inside animation?

How can I set the linewidth of a listings if this is inside animateinline? So far it seems that this setting is ignored in this situation. But it works outside the animate. This seems to be another ...
3
votes
1answer
35 views

Inconsistent style of “other keywords” when breaklines=true [duplicate]

Some keywords defined with the otherkeywords key are not formatted as expected when breaklines is set to true. Here is my MWE: \documentclass[12pt, a4paper]{article} \usepackage{listings} \lstset{ ...
6
votes
1answer
169 views

How can I delete non-letter keywords (such as '<-')?

I am using the package to try and format my R code, and I don't like some of the things that are being treated as keywords (for the coloring scheme). However, when I specify deletekeywords={*,<-} ...
1
vote
0answers
22 views

How can I prevent listings from replacing space characters by a weird bracket symbol? [duplicate]

I'm using the listings package and I'm not happy about the output I'm getting. More specifically, listings seems to replace some space characters by a weird bracket symbol. See the screenshot below. ...
3
votes
1answer
105 views

What is bad in these lines with listings?

How is bad in the line 28 (AppendTo....)? LATEX tell me that"missing $" \documentclass[a4paper,12pt]{scrartcl} \usepackage[utf8,latin1]{inputenc} \usepackage{listings,xcolor} ...
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
43 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
112 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
169 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
81 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
298 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
85 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
104 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
106 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
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 ...
2
votes
1answer
42 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
121 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
62 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
100 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
401 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
92 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
41 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
274 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
79 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
100 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
57 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} ...
1
vote
1answer
49 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
93 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
47 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
60 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
184 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
125 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
116 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
54 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
89 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
110 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
99 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} ...
2
votes
2answers
1k 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
106 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
130 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
126 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
109 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
90 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? ...
2
votes
1answer
82 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
69 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: ...
4
votes
1answer
93 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
25 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
107 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} ...