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

How listing and verbatim do to escape special character?

I use one macro to display text using texttt style. For the moment this macro is very basic. For example, if I want to use the character _, its catcode must be changed. Is there a clever way to ...
3
votes
1answer
472 views

Visual separation when using linerange in listings

I have read through the listings documentation and couldn't find an answer to the following question: How do I insert some sort of visual feedback in a listings listing when using the linerange ...
3
votes
2answers
2k views

How to use a comma in lstlisting keywords?

I am creating a language for the doxygen tool. I need to create a set of new keywords. When I try to use the comma in one of them, it does not highlighting. I protect comma with a backslash, but it ...
3
votes
1answer
1k views

How to increase the padding in the code snippet box when using `listings`?

So I am writing a book on Awk programming language, and I have enabled a single frame via \lstset{frame=single}. However, I would like the code within the snippet box to be further away from the frame ...
3
votes
1answer
815 views

Custom numbering of listings

I have a number of listings in my document, numbered 1, 2, 3 and so on. I need a table with three listings (say, three different variants of the same algorithm), that will be numbered as 2a, 2b, 2c. ...
3
votes
2answers
1k views

Listing inside tabularx?

I have a tabularx environment where I want to put an lstlisting into. But Latex fails to compile it. Testcase: \documentclass[a4paper,12pt]{scrreprt} \usepackage[utf8x]{inputenc} ...
2
votes
1answer
93 views

How can I insert a thin space (\,) in a listing?

Is it possible to create small space in listing? I tried / and \, but it doesn't work in listing environment \begin{lstlisting}[caption={Inicializace ELM327.}, label={lst:initELM},captionpos=b] ...
2
votes
1answer
74 views

Coloring ) in listing [duplicate]

I'm trying to create a style using for coloring \ and brackets in code sample (PStricks) using the listings package; I tried using the answer given by Marco Daniel in this question using literate for ...
2
votes
0answers
56 views

Problem with Listings package concerning line breaking and wrong alignment [duplicate]

Hello I have the following code: \documentclass[12pt]{article} \usepackage[top=0.3in, bottom=1.5in, left=0.8in, right=0.8in]{geometry} \usepackage[utf8]{inputenc} \usepackage{setspace} ...
2
votes
1answer
82 views

How can I highlight a freestanding regexp in string style?

I'm using listings to format a piece of JavaScript code, and I met a problem for the following code: ... regex = /abc/; ... ratio = 1.0/2.0; ... I want the regex is highlighted as a string, but if ...
2
votes
1answer
63 views

inline code listing runs into right margin

I am trying to typeset an inline C# code listing using the listings package. However, the chunk of inline code spans a few lines, so listings has to insert a coupe of line breaks into my code. So far, ...
2
votes
1answer
400 views

listings doesn't print my keywords bold in lstlisting

I've got the following problem: I want to print a listing with the listings package and lstlisting: \documentclass{scrreprt} \usepackage{listings} \begin{document} ...
2
votes
2answers
384 views

Including HTML code side by side in Latex [duplicate]

I want to write HTML codes of two pages side by side in LaTeX like as follows: <html> <html> <head> <head> </head> </head> <body> <body> ... ...
2
votes
1answer
195 views

adjustbox and lstnewenvironment

I'm trying to use adjustbox to make a frame around listings (I know that listings itself can do this, but its implementation produces sub-optimal results when the line heights are not equal throughout ...
2
votes
1answer
1k views

Add keywords to an existing language in listings

I've already read extending a language with additional keywords and I have found kind of a solution, but I'm not quite sure if it's the right way and if I won't have problems in the future. The ...
2
votes
1answer
580 views

minted list of listings and TOC conflict

I am using minted for source code highlighting. I want a List of Listings, and I want the List of Listings to itself have an entry in the main Table of Contents. I thought I could do this with ...
2
votes
1answer
273 views

regular expression in listings

I'm looking for a possibility to find a way to colorize data. If a text starts in a line with XYZ from that point until the next blank line the text should be set in a defined colour. With the comment ...
2
votes
1answer
569 views

LaTeX listing of command line syntax

I have a LaTeX document using the listings package for some bash scripts. I'd like to create a different styling for text that is meant to show the syntax of a command. For instance, I have the ...
2
votes
1answer
270 views

\lstinputlisting of a whole java project

I'd like to print the complete source code of my java project, which has multiple .java files in several packages (i.e. folders), many .properties files and many .xml files, and others. I want to use ...
2
votes
1answer
307 views

How to escape backslash in rangeprefix?

I want to escape backslash to be used as a rangeprefix as follows. The current MWE does not work as expected because it still imports all codes rather than the codes sandwiched by document ...
2
votes
1answer
198 views

Listings, problem with rendering embedded strings

this is my style defined for C#: \lstdefinestyle{CSharp}{ language=[Sharp]C ,captionpos=b ,columns=fixed ,morekeywords={var,get,set} ,basicstyle=\footnotesize\ttfamily ...
2
votes
1answer
1k views

Lstlistings: Getting pretty equations in display mode

I am currently trying to print my algorithms using the listings package. For clarity I always try to display the more complex mathematical expressions as formula instead of plain code. This results in ...
2
votes
1answer
943 views

Using the “combine” document class with the listings package

I am trying to use the combine document class (manual) to combine several pre-existing documents into a single file with consistent formatting. It works great, except that there is a conflict of some ...
1
vote
0answers
69 views

listings frame for multiple page code [closed]

My code is really long. And I really want to use the frame Shadowbox in my code. But the problem is since it is going over a single page, the box is actually completing at the end of the code ...
1
vote
1answer
155 views

\lstinline break at punctuation

I need listing package (\usepackage{listing}) to break at punctuation namespace::subnamespace::class ^ ^ at either these two locations
1
vote
0answers
33 views

Mixing multiple programming languages with different styles in same document [duplicate]

Possible Duplicate: Defining lstset parameters for multiple languages What's the easiest way to include code, using listings, from more programming languages? \lstset{ % language=Python, ...
1
vote
1answer
174 views

Combine listings package with my own enviroment [duplicate]

Possible Duplicate: How to use different lstset settings for listings? I have defined my own enviroment as: \newenvironment{codegui}[3]{% \def\tmplanguage{#1}\relax ...
1
vote
1answer
195 views

Using package listings with sciposter

Could you please provide a working example in which a source code delimited by listings environment word wraps its lines, without breaking the column layout of sciposter? Whenever I put a long line ...
1
vote
1answer
243 views

How to make my unusual environment accept one argument?

I cannot find a good title to express my question. Therefore, please parse the following code first. Minimal Code \documentclass[dvips,dvipsnames,cmyk,table]{book} ...
1
vote
2answers
813 views

Define a new environment to combine tikzpicture and lstlisting

I would like to define a new environment to combine the tikzpicture environment from package pgf/tikz and the lstlisting environment from package listings. The result would be to first produce the ...
1
vote
1answer
460 views

Without defining a new command for each setting, is it possible to pass the set of settings to the optional argument of lstinputlisting ?

Screenshot Scenario I want to define two sets of settings for \lstinputlisting--One setting for CSharp A and the other one for CSharp B. They are different only in the color settings. ...
0
votes
0answers
52 views

Force page break within lstlisting

How to force a page break within lstlisting? My listing contains two code examples and LaTeX added the page break immediately after the first line of the second code example, however, I want it to ...
0
votes
1answer
701 views

Standard single quotes for code in listings [duplicate]

In my code, I have curved quotes (see screenshot). Can I replace them with vertical quotes? This is my formatting code: \lstset{% % General design backgroundcolor=\color{lightgray}, ...
0
votes
1answer
152 views

Changing code in listings dynamically [closed]

I need to change dynamically the code in the listing by adding just one key word to the code. I tried to do it like this: \begin{lstlisting}[escapechar=|] class MyThread extends Thread { private ...
0
votes
1answer
228 views

\afterpage issue with \lstlisting

I have issue with \afterpage command and \lstlisting, it's add one blank page after beginning code listing, and after blank page is two of my command. \appendix \section*{APPENDIX A} ...
0
votes
1answer
368 views

Highlighting line ranges in listings

I've put here one adaptation for "no-beamer" documents of this code. Thanks a lot for the indications given below by Daniel. % Sources : % 1) ...
0
votes
1answer
669 views

Code fails with Emergency stop, when using \expandafter\csname and such in listings

I am further working on my code for LaTeX Examples. I want to use the package showexpl for the simultaneus printing of code and results. Unfortunately I get an '! Emergency stop.' ...
0
votes
5answers
730 views

How to prevent extendedchars=\true from producing a blank line?

My previous question How to suppress BOM effect in the output? has been solved by @Vaulty. Enabling extendedchars=\true, however, produces an unnecessary blank line at the first line as shown below. ...
0
votes
1answer
408 views

Align normal text inside a listing

I need a way to correctly align the escaped strings that I put inside of this listing. The problem is that they are presented right aligned. I want that this lines keep the indentation of the previous ...