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

How to set the listings font for the whole document

How do I change the listing font size of the whole document? I am quite sure that it must be specified in Document->Settings->Listings but I do not know the input parameter for setting the font ...
2
votes
0answers
49 views

How to pass the option “listings” to examplep [closed]

I've been trying to pass the option listings to the examplep package. According to the documentation one can pass the options to activate the listing by doing listings=yes, listings={}. However, ...
2
votes
1answer
60 views

showexpl not showing caption of a lstlisting within

How can I make the LTXexample environment to show the caption (like it does with other environments) of a lstlisting that is inside it. Consider the following code \documentclass{article} ...
1
vote
0answers
26 views

Work around 'Dimension too large' using `framed` with `listings`

I'm including an external source code file as an appendix using the listings package. The framed package is being used to ensure multi-page listings frames are fully closed. The problem is if my ...
3
votes
1answer
106 views

Difference between fixed-width and proportional typewriter fonts in listings?

In the MWE below, I wonder why does the pcr (Courier) font align in both escaped and unescaped versions and for whatever column setting of {listing} - while the cmtt (Computer Modern Teletype) aligns ...
3
votes
1answer
47 views

Change Character Color in listing

I want to change some special character's color in listing for example all Parenthesis be red. I don't want to make them keywords they should have different color. is it possible?
6
votes
1answer
82 views

How can I prevent the background from overlapping the rounded corners in an \lstinputlisting?

I want to include listings of external files in my document. These listings should have a solid background and rounded corners. The problem is, that if I define a style with frameround and ...
2
votes
1answer
58 views

Highlight line numbers in listings, conflict with hyperref package

I want to highlight the line numbers of the lines of the Listing to which I refer. See the question Highlight line numbers in Listings for details about how to highlight one line number. Now I want ...
5
votes
1answer
82 views

How to use \pretocmd with \verb or \lstinline?

I write my document in other language, then I need to switch to English (switch font) when show code: \newcommand\code[1]{\lstinline{#1}} \pretocmd{\code}{\begin{otherlanguage}{english}}{}{} ...
2
votes
0answers
44 views

Listings - Keyword with Regex [duplicate]

I would like to colorize in a special color all my constant which are all in capital letters in my code and all my method variables which begin with an @. Is it possible to use Regex to define ...
1
vote
0answers
68 views

Code alignment using listings with proportional fonts is poor

I would like to typeset code using proportional fonts and the listings package, but no matter what I do, alignment is always off. Here is an example in Java (taken from Wikipedia): ...
4
votes
1answer
72 views

Formatting code into the style used in Stackoverflow

I know that there is minted and listings for displaying nice code in .tex documents. However, I'd like to use the style that is used for Stackoverflow code: example. Are there any packages for this, ...
4
votes
2answers
66 views

Latex listings package, issue with caption touching the frame and junk character instead of space

I am using listings package and facing two issues Following is the LaTeX code and output \lstset{language=Java, basicstyle=\small, frame=single, breaklines=true, ...
2
votes
1answer
31 views

XeTeX is printing explicit space characters inside quoted strings

I'm using XeLaTeX with this: \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{spanish} But when I write this listing \begin{lstlisting}[style=Pyshell] >>> print ...
2
votes
2answers
33 views

Latex create a second keywordstyle using listing doesn't work

I need to insert some code in my latex document, using listings. I create my own set, for a java language \lstset{ language=Java, aboveskip=3mm, belowskip=3mm, showstringspaces=false, ...
2
votes
2answers
102 views

Problem with 'é' character in listings

I have this MWE \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[frenchb]{babel} \usepackage{colortbl} \usepackage{lmodern} \usepackage{listings} ...
1
vote
2answers
59 views

Change space style using listings package

I'd like to make all space characters in the code gray. Is there an easy way to do this? Is there something like spacestyle (I've commented it)? \documentclass[a4paper, 10pt]{book} ...
4
votes
2answers
65 views

Aligning two minipages - one with lstlisting, one without - on top?

I'm already aware that two minipages with [t] align at the baseline of the top line, not at the top of their respective boxes/containers; however, this is somewhat different: when I use a small ...
4
votes
1answer
62 views

Using lstinline in caption of lstlistings with multicol?

Consider this MWE: \documentclass{article} \usepackage{multicol} \usepackage{listings} \begin{document} \def\extra{extra} \begin{lstlisting}[ multicols=2, caption={ [short] aaaa \extra, ...
2
votes
1answer
33 views

How to display a code using lstinputlisting that isn't separated with figures?

This is the code I used: \lstinputlisting[language=Python,breaklines=true]{seminar_ED.py} It works fine with displaying the code over multiple pages when I don't add other figures in the text. But ...
1
vote
1answer
64 views

Using mathastext with listing

In the following example code, I would like to use mathastext so as to use the same font than the one used by listings. In the code above, the output of the listing do not use a courier-like font, ...
16
votes
3answers
217 views

Fancy code environment

I'm writing a small tutorial about LaTeX. So I'd like to insert some code and obtain the result on the right. I'm almost there. I got the desired output but I'd like something more clear, that is, ...
3
votes
1answer
203 views

Error related to \spacefactor using 3rd-party macro \addmoretexcs

I am using the command \addmoretexcs for listings, which has its origin here. With the update to TeX Live 2014 (and probably an update to listings), the following code returns an error: ...
1
vote
0answers
47 views

List of Listings (LOL) multiple entries with the same name

I splitted some source code into various listing all with the same name "Company ontology" (to use the firstnumber=auto), now in my LOL I have multiple repeated entries, is there a way to solve, maybe ...
5
votes
1answer
71 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
68 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
33 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
158 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
102 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
42 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
98 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
154 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
80 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
242 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
76 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
92 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
98 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
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
115 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
57 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
94 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
395 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
88 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
34 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
236 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
78 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
99 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}, ...