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

lstlistings in defined Tikz box

I have created a box using \newcommand, based on TikZ named "mybox". The equation easily insertable in it. But I want to insert a \lstlisting environment in it. But it doesn't work. How can I do it? ...
6
votes
1answer
592 views

Reference to a listing returns wrong number

I'm using the following code to create a listing with sourcecode: \begin{lstlisting}[caption={caption_text}\label{lst:a_label},language=Java] // Code... \end{lstlisting} Unfortunately, a ...
4
votes
1answer
362 views

How to add lstlisting to Algorithms List

I have written a document where I use pseudo code to describe some general algorithms (with \usepackage{algpseudocode} ) which can be viewed at the begining after toc as „List of Algorithms”. I also ...
0
votes
1answer
250 views

Only Select Code without Line Numbers [duplicate]

I'm writing a LaTeX document and want to include several listings for source code examples. Is there a way to disable the selection of line-numbers when selecting the source code? My prof just wants ...
1
vote
1answer
152 views

Use Listing in newenvironment

I am trying to do a new environment or command (i tried both) where i can put in the name, description and code of a Method in c++ and it gives me a new section with the MethodName, the code listed ...
4
votes
1answer
181 views

Two columns for grammar environment

My grammar is long and thin. I'd like to space it out horizontally, as two columns. \newenvironment{BNF} {\captionsetup{type=lstlisting}} {} \begin{BNF} \caption{My Grammar} ...
0
votes
1answer
290 views

Issues when including a tex file [closed]

I have this without any issues if I use it alone. However if I call it with input or include I get this Why?
0
votes
1answer
168 views

Long codes using listing or mcode which do not break into 2 pages

I'm using the mcode package for including my codes into my documents, but the problem is that when my codes are too long, and they need more than one page the program tries to keep them in one page, ...
1
vote
1answer
1k views

Several errors concerning lstlisting

In my Bachelor Thesis I'm using highlighted code using lstlisting, which comes with the listingspackage. Unfortunately I'm getting some errors and I cannot figure out why they appear. Especially ...
1
vote
0answers
26 views

How to use \lstinline inside figure environment's caption argument [duplicate]

Here is the code that I have (I have removed parts which I think are not relevant): \documentclass[12pt]{article} \usepackage{listings} % Python style for highlighting ...
1
vote
1answer
102 views

Extend keyword list for fancyvrb / listings, based on a given language

I use fancyvrb and listings packages, and I have defined a language scala, which is the default to use. In one occasion, I have an extension of that language, escala, which adds additional keywords. ...
1
vote
0answers
127 views

LaTeX places a float in the middle of my script. How do I prevent this? [closed]

I have a multi-page script in my thesis, and I have used the listings package to format the source code. This works really well, however LaTeX wants to put a float in the middle of this code, which ...
6
votes
1answer
2k views

Problems with the lstlisting environment (margin and white line)

Consider the following example: \documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{columns=fullflexible, ...
3
votes
1answer
682 views

More sophisticated syntax highlighting of Prolog code

I'm wondering, does listings allow you to define your own syntax highlighting, and if so, how sophisticated is its system? Here's a minimal example: \documentclass{article} \usepackage{listings} ...
0
votes
2answers
127 views

What's a good way to insert very few lines of code?

I know about the listings package, but it seems that it can't be put where I want it to be (h in float). And since I just maybe want to insert exactly one line of code, I really want it to be where I ...
5
votes
1answer
998 views

lstlisting in a tabular enviroment

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} ...
4
votes
1answer
478 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
843 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
108 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
695 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
53 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
495 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
441 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
237 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 ...
2
votes
2answers
435 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 ...
34
votes
1answer
473 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 ...
7
votes
3answers
298 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 ...
6
votes
4answers
571 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 ...
3
votes
1answer
5k 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
248 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
418 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
116 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 ...
3
votes
1answer
391 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
202 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
213 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
75 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
131 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 ...
5
votes
1answer
4k 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
201 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
184 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
805 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 ...
3
votes
1answer
2k 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
245 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
158 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
26 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 ...
6
votes
1answer
3k 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
108 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 ...
3
votes
1answer
4k 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 ...
6
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} ...
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 ...