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

lstlisting in a tabular environment

I am following Adding C++ code in Latex for adding C++ code to the document. What I have is a table with the following format: \documentclass[12pt,a4paper,final]{report} \usepackage[utf8]{inputenc} ...
7
votes
1answer
1k views

How to copy/paste from lstlistings? [duplicate]

I'm trying to write code in a LaTeX document that can be copy/pasted from an outputted pdf using Adobe Reader and that also word wraps, rather than breach the right margin. I've found that in ...
6
votes
1answer
2k views

Using beamer's \uncover with the listings package

I want use listings package with uncover command. He's my code \usepackage{listings} \lstnewenvironment{Exemplecode}{}{} \newenvironment{Framecode}[1] {\begin{frame}[fragile, ...
3
votes
1answer
182 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 ...
5
votes
1answer
2k views

avoid empty vert space after lstlisting

After some \begin{lstlisting} ... \end{lstlisting}, LaTeX adds some additional vertical space. How can I avoid that?
1
vote
0answers
57 views

LaTeX listings / email quoting [duplicate]

I've been trying to do someting with LaTeX. I have some emails that I want to insert in a document. I've searched all over the web but can't find a valid solution. What I want to do is to have those ...
2
votes
2answers
919 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> ... ...
1
vote
1answer
846 views

lstnewenvironment and include

I have several environments for listings such as: \lstnewenvironment{JavaScript}[1][] { \renewcommand*{\lstlistingname}{Code (JavaScript)} \lstset{#1,language=Java} } { } This works ...
6
votes
2answers
318 views

“Isodat” language source code syntax highlighting

Isodat language is used for Mass-spectrometers from ThermoFisher Scientific®, which is used for Stable Isotope Mass-spectrometry. Parts of the language's syntax highlighting has been explored in ...
3
votes
2answers
1k views

Code listing spanning multiple pages with captions at top

Is it possible to span a lstlisting environment or lstlistinginput on multiple pages, such that the caption is repeated on each page (the listing counter stays the same), as well as being able to ...
36
votes
1answer
784 views

listings: Copy to clipboard feature?

I was just wonder if it would be possible to have a "Copy to Clipboard Button" next to each listing which would just copy the verbatim content of the lstlistings environment to the clipboard. An ...
8
votes
3answers
572 views

xelatex + frenchb introduce extra spaces before some characters in lstlisting blocks

When using babel 'frenchb' with xelatex, spaces are introduced before colons and other characters. This is great for prose, but this is also being applied to code snippets. This yields an unacceptable ...
7
votes
4answers
2k views

Is it possible to use a non-monospace font in verbatim environments?

I know it runs contrary to a lot of the point, but I'd like to experiment with different fonts to see which I like better. I can't seem to find any reference to a way to do this, if it's at all ...
10
votes
1answer
17k views

Styling a lstlisting caption using caption package

I'd like to style a caption in a specific way, but I can't seem to figure out the proper settings to do so. First off, I'd like to change the label from "Listing" to "Algorithm" when I use ...
8
votes
1answer
550 views

\ is escaping " character in lstlisting giving wrong output

The following code in VB has wrong output due to \ escaping the closing " of the string. Rest of code is then printed as if it was in a string. Any idea how to correct that? \documentclass{article} ...
3
votes
2answers
1k views

Subfigure with lstlisting: what am I doing wrong?

It keeps telling me: \begin{document} ended by \end{figure}, but I do not understand why. I tried to follow the guidelines for the subfigure package. Here is my MWE: ...
1
vote
0answers
146 views

Lyx - quotation mark in C program [closed]

I have a problem with double quotation marks in program listing. When I load a file.c as a child document in lyx and set it as program listing, I get error: #include "softSPI.h" undefined control ...
4
votes
1answer
694 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} ...
4
votes
1answer
390 views

Problem with \newcommand that mimics lstinline

I'm trying to replicate a part of a scanned book. Book is about programming (pure C). I need to use many commands with a same name but with different surrounding, for example, background color etc. ...
2
votes
1answer
412 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 ...
4
votes
1answer
90 views

wrapping long python arrays in listings package

NOTE I have tried the following answer to a similar question , but it doesn't work: lstlisting line wrapping My problem is trying to put the following code in latex: import matplotlib.pyplot as plt ...
7
votes
1answer
162 views

Writing environment content verbatim to file, calling Graphviz and including source/image

Based on Write environment body verbatim to a file I try to write the content of a environment verbatim to a file, call an external tool (in my case the awesome Graphviz) and include the source code ...
22
votes
1answer
19k views

lstlisting line wrapping

How is it possible to let lstlisting wrap lines? I've troubles with following block: \begin{lstlisting}[language=java] public class MeasureStationControllerV0Test { MeasureStationControllerV0 ...
3
votes
1answer
279 views

How to combine framed and listings packages in new environment

I always use this LaTeX code to display a source code in my article. \begin{listingbox}{VB style} \begin{singlespace} \begin{lstlisting}[style=BASIC] Private Sub Form_Load() Dim tex As String ...
7
votes
3answers
302 views

\listings environment inside \marginnote?

Is it possible to use \listings or similar environment inside \marginnote or in margins in general? \marginnote{ \begin{lstlisting} test \end{lstlisting} } If not, what would be a ...
8
votes
2answers
2k views

Highlighting haskell listings in large *.tex document [duplicate]

Suppose, there is a large *.tex document, which has many nested \input directives with many Haskell listings surrounded by \begin{code} \end{code} commands. How can all this code listings be ...
7
votes
1answer
5k views

Is there a possibility to make reference to the line in the lstlisting environment?

I was wondering if it is possible to refer to the lines of the code enclosed in lstlisting environment rather than just manually write a number of the line I want to describe. I have never met with ...
7
votes
1answer
531 views

How can I highlight a keywordsprefix in listings?

Ok, so here's my problem which I'm repeatedly gnawing on, whenever I try to typset source code. To this day, I have not found someone on the internet asking for the same problem. I want to add a ...
5
votes
1answer
249 views

How to make letter spacing in verbatim/fancyvrb look like listings

I've just noticed that the spacing between letters is different in verbatim vs. lstlisting environments: Given that I add the option columns=flexible to the lstlisting environment, the spacing in ...
0
votes
0answers
27 views

Listings: total line number count [duplicate]

Is there a way to determine how many lines a listings-environment has (included via \lstinputlisting) and display it in a text or caption? I found the counter \thelstnumber. But if it is used before a ...
11
votes
1answer
8k views

\textcolor within lstlisting?

I have some pseudo-code where I want to highlight some sections in a different color (this is why: in an assignment at university, I have some code given and have to adapt it. I want to highlight what ...
5
votes
1answer
273 views

Ugly spacing in lstinline

I am using the listings package to typeset Erlang source code in my thesis. For short snippets, I use \lstinline. The result is often unsatisfying. Consider the following example, which contains ...
6
votes
2answers
13k views

Listings Highlight Java Annotations

I am typesetting something that has a lot of Java code listings. Because the Java code has a lot of annotations, and that they are important to the reader, I'd like to have them highlighted, like ...
7
votes
1answer
2k views

LaTeX code formatting using lstlistings: custom keywords not recognized

I'm trying to add some keywords to an existing language using the morekeywords setting: \documentclass[12pt]{article} \usepackage{color} \usepackage[usenames,dvipsnames]{xcolor} ...
5
votes
1answer
7k 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
0answers
2k views

Latex to HTML using Pandoc [closed]

I have a bunch of tutorials I have written and they are written in Latex. Now I want to convert them to HTML and to Blogger also. I heard about Pandoc and decided to try it. Below are my results : ...
6
votes
3answers
1k views

Combine \listoflistings and \listofalgorithms into one list

The title said it all...I want to combine the two under one list with the title "Algorithms and program code". Style wise the page should match the usual style of the other lists (\listoffigures, ...
0
votes
0answers
36 views

How to pagebreak within listings? [duplicate]

I have a quite big txt file, and the problem is, if I include it with listings, latex tries to put it on one page, but it is too big for one page. So a part is missing. I am wondering, if Latex could ...
4
votes
1answer
96 views

break line within mathescape in listing

How do I solve the evergreen problem of breaking a long equation into multiple lines but this time within the lstlisting[mathescape] environment. Attached is the minimum working example. ...
2
votes
1answer
157 views

How to make a caption visible in a newly defined lstenvironment?

I have a new lstenvironment defined like this: \lstnewenvironment{xml} {\lstset{language=xml, basicstyle=\ttfamily, frame=single, captionpos=b}} {} Then I want to apply it in my code: ...
5
votes
1answer
229 views

Emphasizing some parts of string in lstlisting

I need to stress out some parts of string in lstlisting. I tried with \emph{}, but I got the verbatim result. Is there any way to that? \begin{lstlisting}[frame=single] Array1: 78 54 31 54 92 86 23 ...
6
votes
1answer
424 views

listings and keywords in the index

The listings package allows to index the appearance of keywords in a listing, for example similar to the following MWE: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{imakeidx} ...
4
votes
1answer
759 views

listings caption gray box meaning of code

Some time ago I copied this code from Stackexchange to have a nice gray box at the top of my imported source code which I displayed with listings: \DeclareCaptionFont{white}{\color{white}} ...
6
votes
2answers
457 views

Forbidding keywords in listings

I would like to force the listings package to be more selective when highlighting keywords. I'm currently including C source files in my document, and while I'm happy that occurrences of the float ...
3
votes
1answer
673 views

Horizontal dashed line on page break in listings environment

Well, the title says it all. I have code scripts that span over multiple pages. Is it possible to display a dashed line at the bottom and/or top of the page in which the listings environment ...
1
vote
1answer
314 views

XML with Listings: Different colors for attributes and elements

How can I make every attribute name in color X and every element name in color Y without adding keywords and stuff? What I did so far: \lstdefinelanguage{myXML} { morestring=[b]", ...
0
votes
0answers
61 views

Define listing for different languages [duplicate]

I'm writing a thesis where I need to highlight XML, C# and Python code, here is my definition, but all I get is the same highlight for all three types. \documentclass[a4paper,slovak,12pt]{article} % ...
2
votes
1answer
949 views

Lstinputlisting and listings styles

To further extend my recent question about new listings environments, found here: Multiple listings styles. How do I define a new lstlistings environment, via the command \lstnewenvironment, and, be ...
6
votes
1answer
725 views

Multiple listings styles

In using the listings package, how can I have a distinct \lstlistingname value for each type of listing. Lets say my document has C++, R and Pseudo listings, and I would like the \lstlistingname ...
7
votes
1answer
1k views

listing package and vbox warning

I have this many (see below) underfull warnings that are caused by using the listing package and creating \begin{lstlisting}\end{} to make code appear presentable. Is there a may to fix the warnings? ...