{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

1
vote
0answers
37 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): ...
0
votes
0answers
31 views

embedding inline code listings [on hold]

I saw a solution here for embedding programming language snippets using \lstinline{code} This is great for displaying a phrase of code, but what can I do if I want multiple lines and don't want to ...
3
votes
1answer
49 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
27 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
17 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
83 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
47 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
39 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
23 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
54 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
144 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
64 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
36 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
28 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
127 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
93 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
36 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
46 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
104 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
65 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
106 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
62 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
69 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
64 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
30 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
40 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
83 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
31 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
57 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 ...
6
votes
0answers
285 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
69 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
20 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
92 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
63 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
89 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
26 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
32 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
60 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
33 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
52 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
123 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
0answers
55 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
55 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
35 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 ...