{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
1answer
76 views

How to copy/paste multiple spaces from lstlistings?

This is a continuation of a question that I asked already: How to copy/paste from lstlistings?. The solution presented there does not work if the text within the lstlistings environment contains ...
3
votes
1answer
85 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 ...
3
votes
1answer
266 views

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about ...
3
votes
2answers
154 views

Caption package destroys center/varwidth

I have received a wonderful comment how to get listings centered: \documentclass[a4paper]{book} %\usepackage[hang,small,it,hypcap=true]{caption} % screw hypcap \usepackage[T1]{fontenc} ...
3
votes
1answer
260 views

latexdiff and lstlisting

I was wondering if it is possible to have latexdiff ignore all lstlistings from my documents when finding diffs. Most of my listings contain special characters. That works rather nicely within an ...
3
votes
2answers
453 views

Numbering of listings

I would like to numerate listings according to sections. If the listing is in subsection then it should have subsection numbers. This example is very good and I'm using it for some other numbering, ...
3
votes
2answers
105 views

Title of listing is missing

I am using the listings package to mark-up C and Assembler code. Unfortunately the title of the listing is missing (the same with the caption=... command). In the document section I using my clisting ...
3
votes
1answer
247 views

\lstinputlisting does not respect the \lstset 'float' option

How can I force \lstinputlisting[...]{filename} to obey all parameters set by \lstset? (Note the float option given to the TeX example, but not to the LaTeX example.) ...
3
votes
1answer
101 views

texcl and range prefixes in listings with shorter comments

I'm trying to use the line range markers from the listings package to include sections of code. I'd previously been using actual line numbers, but based on the answer to this question, I've been able ...
3
votes
1answer
366 views

Markup Haskell sources in complex structured document with `lhs2TeX`

Simple task Suppose there is a example.tex file with Haskell listings: \documentclass{article} \usepackage{fancyvrb} \DefineVerbatimEnvironment{code}{Verbatim}{fontsize=\small} \begin{document} ...
3
votes
1answer
250 views

listings range end markers in comments with texcl

I'm trying to using the listings package to generate nice listings of some Lisp-style code (where line comments begin with a ;). I'd like to keep the code compilable, and so put the range markers ...
3
votes
1answer
815 views

LaTeX - Using commands inside inline code

I want to be able to have inline code (printed in typewriter or something) where I can also use LaTeX commands like \myinlinecode{here comes a backslash: <\textbackslash>}. So it should be ...
3
votes
1answer
199 views

Use pxfonts in listings only

I really like the pxfont package for displaying code in listings. I would usually just do this to load pxfont for the entire document; \usepackage{pxfonts}. However, this time I am required to use a ...
3
votes
1answer
517 views

How to use angle brackets for a keyword in \listings?

I've got a code of a HTML website that I want to show in my LaTeX document. The problem is, that the HTML code has a tag called <canvas> and the JavaScript code inside the HTML document has a ...
3
votes
1answer
541 views

LaTeX source code listing with less space between characters [duplicate]

I want to write shell Code in my LaTeX document. I'm using the listings package, with a code sample adapted from Tormod Fjeldskår: \documentclass{report} \usepackage{color} \usepackage{xcolor} ...
3
votes
1answer
125 views

Auto include specific part of source files

I'm creating a lot of code to our small projects (in computer science), and finding myself copy/pasting my comments into the document. Would it be possible to make a reference point in the code file ...
3
votes
1answer
315 views

linerange reference in lstinputlisting

I have a listing that refers to my c code; I would like to reference the code using commented section in the code, as seen in the code example bellow. I have created a list style which does this, but ...
3
votes
1answer
253 views

Hide listing from listoflistings [duplicate]

Possible Duplicate: remove unwanted contents from list of listings How can I hide a listing from the listoflistings, similar to using \section*{Title} to hide a section from the table of ...
3
votes
1answer
693 views

Background color in inline code listings with linebreak

I want to highlight code inline with a gray background. Preferably with listings. This question is related to Colored background in inline listings. But as my MWE shows it doesn't work with line ...
3
votes
1answer
212 views

Headers and footers for listing environment?

What I need to be able to do is apply a header and footer when I use the listings environment. I have a few requirements: The header and footer should be outside the listing itself, i.e. they are ...
3
votes
1answer
706 views

Latex listings R: need mono-spaced font with bold keywords and correct caret (^)

I am using the listings package to display R code. I would like a monospaced font, bold keywords, and I would like code that works when the user cuts and pastes from the pdf file into rstudio. The ...
3
votes
1answer
889 views

Problem with alignment in listings

I have a follow up question to this post I am using listings in beamer. The content in listings is being pushed further left than the other contents on my slides. I am using the code below to correct ...
3
votes
2answers
611 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
484 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
1answer
2k views

How to highlight own keywords in HTML lstlistings?

I would like to highlight some words in a lstlisting. The language is HTML. However, \emph seems not to be working with HTML. Any suggestions how I could work around this problem? Right now I have: ...
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
2k 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
838 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
2answers
68 views

Counters for Chapter and Section environments when using tcolorbox for listings

This is a followup question of this question. With my MWE I'm getting wrong Listing numbers, wrong toc (including Chapter and Section environments from listings) and wrong bookmarks in pdf toc. Any ...
2
votes
1answer
44 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 ...
2
votes
1answer
94 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
79 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
57 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
93 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
68 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
480 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
452 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
202 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
2k 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
639 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
284 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
624 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
279 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
331 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
208 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
2k 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
982 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
1answer
59 views

How can I highlight keywords with special characters or numbers in them?

In the following MWE the declared keywords te-st and 999 are not highlighted as expected: \documentclass{scrartcl} \usepackage{listings,xcolor} ...
1
vote
0answers
78 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 ...