{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
2answers
933 views

Package Listings Warning: Text dropped after begin of listing when calling function

I'm trying to this: \newcommand{\code}[1] {\begin{lstlisting} {#1} \end{lstlisting} } But I keep getting this error: Package Listings Warning: Text dropped after begin of listing I'm calling ...
0
votes
0answers
17 views

Indentation next to an algorithm

i'm new to Latex .Is there a way I can put a comment to the right of the line of an algorithm when using Listings ? I want to write the time it takes line by line , and want to include the file.java ...
3
votes
0answers
42 views

Define new command which insert environment [duplicate]

Am i able to do something like this: (without defining new environment) \newcommand{\code}[2] { \begin{lstlisting}[language=#1] #2 \end{lstlisting} } I don't want to write: ...
3
votes
1answer
49 views

Define a listing language in which scope and line comments share the same symbol

I'm trying to create a listings language in which the scope and line comments start with the same symbol. Basically, I want the # symbol to start a comment that ends at the end of the line or another ...
4
votes
0answers
46 views

(Clickable) cross-reference in lstlisting

To generate documentation for an 'application programming interface', I would like to have a syntax highlighted area (with the class declaration), which has clickable links to the documentation (which ...
1
vote
1answer
34 views

Install listings package manually

How do I install the listings package manually ?. With other packages I used to download all the files needed and copied in the right folders and then refreshing the packages and it worked perfectly, ...
11
votes
1answer
430 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} ...
11
votes
1answer
904 views

Automatic background coloring in listings using tikzmark

I am authoring Beamer presentations that feature numerous code listings, and I am required to highlight portions of code with semi-transparent balloons. Yet I've come up with a solution that uses a ...
2
votes
2answers
75 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: ...
4
votes
2answers
104 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 ...
6
votes
1answer
61 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
60 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 ...
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
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, ...
9
votes
0answers
339 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 ...
5
votes
1answer
44 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
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
40 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?
2
votes
1answer
34 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 ...
22
votes
4answers
7k views

Having problems with listings and UTF-8. Can it be fixed?

I'm having some problems with listings and UTF-8 in my document. Maybe someone can help me? Some characters work, like é and ó, but á and others appear at the beginning of words... ...
1
vote
0answers
48 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
2answers
211 views

Right-align the prebreak symbol in a listings environment

I’m using the breaklines and prebreak option with listings, but I find it visually not very pleasing that the prebreak-symbols are not vertically aligned. I’d prefer if they were all on the very right ...
3
votes
1answer
56 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 ...
10
votes
2answers
3k views

Avoid page breaks in \lstlistings

I'm trying to avoid page breaks in my lstlisting (seen in section 0.0.2) I know I can remedy this by floating my lstlisting, but it adds some unwanted white space (seen in section 0.0.1). Is ...
5
votes
1answer
308 views

Escape moredelim in lstlisting

I am wondering if it is still possible to print characters chosen to be moredelim in \lstdefinestyle. It turns out that since I've defined a character as moredelim, it can only be used inside quotes ...
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} ...
14
votes
2answers
3k views

\listings code style for HTML5 (CSS, HTML, JavaScript)

I would like to create a code style for HTML5 that can be used with the \listings package. An HTML5 document consists of three languages: CSS, HTML and JavaScript. That makes the whole thing a bit ...
4
votes
2answers
46 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 ...
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, ...
1
vote
1answer
465 views

Include a lstlistings keyword in lstlistings caption

I'm writing a small summary for my fellow students about VB in LaTeX. I have to cover the basic loops and found the \lstlistnigs package to be the best for writing colored code. I have already added ...
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, ...
7
votes
4answers
101 views

Only get filename and extension of listing, not whole path

I am trying to add the file name as caption. I was able to do this setting caption=\lstname but this shows the full path. I am now trying to get the name of the file and extension to show only. I ...
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 ...
31
votes
4answers
17k views

How to prevent lstlisting from splitting code between pages?

Is it possible to prevent lstlisting from splitting a code between pages if it does not fit on one page? Instead splitting I would like to have the code on the next page. I tried to put all ...
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, ...
28
votes
3answers
17k views

What can I use to typeset MATLAB code in my document?

This question led to a new package: matlab-prettifier Does anybody have a quick and easy way to typeset some relatively long MATLAB code in the appendix? I looked up a few methods, and the ...
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
40 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
31 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
136 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. ...