{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

3
votes
2answers
61 views

Saving language preferences for inputing source code

Using the listings package, I am trying to input a Java source file into my document using a specified, user-defined style. This works just fine if I have the specified style definition in the same ...
1
vote
2answers
45 views

embedding listing code into tables?

I want to create a simple table in this case with the first column having snippet of code, and the secon column describing it. The command \java is just defined as: ...
9
votes
1answer
215 views

How to show similar display of codes of different programming languages in LaTeX

I am very new to LaTeX and I am writing my thesis. In a chapter, I want to show my codes, which are in Mathematica. I use the listings package as follows: \documentclass{article} ...
4
votes
1answer
23 views

Inserting caption for listings in LyX

I'm using LyX 2.1.1 and want to put captions for listings. I can do this by using LaTeX code in ERT but would like to do by using LyX built-in capabilities of Insert > Program Listing. Any help ...
2
votes
1answer
55 views

Annotate insertions/deletions in listings

I'd like to annotate some lines in my lstlisting environment as having been added or deleted. To do this I'd like to put a (+) or (-) symbol next to the line numbers, like this: 1 function foo ...
5
votes
1answer
43 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
39 views

How to pass the option “listings” to examplep

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
26 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
18 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 ...
2
votes
1answer
39 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
39 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
58 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
33 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
56 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
37 views

Listings - Keyword with Regex

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
46 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): ...
3
votes
1answer
55 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
36 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
19 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
85 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
51 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
45 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 ...
3
votes
0answers
25 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, ...
1
vote
0answers
27 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
55 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, ...
9
votes
3answers
151 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
69 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
38 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 ...
4
votes
1answer
37 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
38 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
29 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
134 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
21 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
94 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
37 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. ...
5
votes
0answers
47 views

Listings package - distinguish between […] and \[…\]

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, ...
5
votes
0answers
110 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
67 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
114 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
64 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
72 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
68 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
86 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
33 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 ...
0
votes
0answers
41 views

How can I mimic the style of 'algorithm' in an 'lstlisting' environment?

In my LaTeX document, I have an algorithm added using algorithm and algorithmic: \documentclass{article} \usepackage{graphicx} \usepackage{apalike} \usepackage{setspace} \usepackage{amsmath} % ...
5
votes
2answers
86 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
33 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
61 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 ...
8
votes
0answers
324 views
+100

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