{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

2
votes
1answer
48 views

Tabular inside listings

I'm trying to get this with this style but I'm getting the error ! Misplaced \omit. \multispan ->\omit \@multispan Here is a MWE: \documentclass{article} ...
1
vote
1answer
80 views

Syntax highlighting in an HTML presentation

This example shows how to produce PDF slides with syntax highlighting of source code. The example uses beamer and (presumably) pdflatex. Another example shows syntax coloring for HTML output using ...
6
votes
1answer
557 views

Enumitem, Listings, Tabbing to a Certain Point

I was wondering whether it was possible to align a lstlisting environment to a certain point within an enumerate . The purpose of my doing this is to fit as much code sample on the page as possible, ...
52
votes
6answers
12k views

Syntax Coloring in LaTeX

Is there any way to include Python code in a LaTeX file and automatically color its syntax? Is it possible to do syntax coloring with any other language? If yes what packages can I use to do that?
0
votes
0answers
38 views

Many \lstinputlisting[..]{…} — but need standalone *.tex file

For the final submission to a journal of our manuscript, they need one foo.tex file (plus a foo.bib, the figures as *.pdf). Our manuscript however uses dozens of ...
4
votes
3answers
275 views

tcolorbox listing error using beamers begin{frame}

I've just started using the tcolorbox package for slides for a LaTeX course. It works nicely to box LaTeX code, interacting with the listings package. However, I ran into trouble when I tried to make ...
5
votes
3answers
89 views

How can I get my IDE to recognize listing labels?

I'm using the listings package to print code snippets. My IDE is TeXstudio 2.8.8. I mention this for the sake of completeness - I assume the behaviour is the same for all IDEs, which is why I wrote a ...
1
vote
0answers
30 views

line length in code listings [duplicate]

Using the listings package, is there a setting using which I can control the number of characters listed per line? I see that there is a \lstset{linewidth= <>} option, but based on observation ...
0
votes
0answers
53 views

issue with listings package [closed]

I am trying to use listings package with Miketex 2.9 but when I try to compile using pdflatex I get the following error: ! Package caption Error: For a successful cooperation we need at least version ...
4
votes
2answers
48 views

Reset counter automatically after lstlinputlisting or lstlisting

I have a number of code examples annotated with a number set by a counter, lstNoteCounter and referred to in the text below the code: My markup works, but it isn't convenient for a large document: ...
2
votes
1answer
34 views

Bold code in listings environment

I want to do a box like this but the bold text doesn't appear. Edited: \documentclass{article} \usepackage{listings,xcolor,etoolbox,lmodern} \definecolor{verbgray}{gray}{0.9} ...
4
votes
1answer
37 views

Put default text in listings environment

I want to make a gray box with some code inside but it should already appear a centered tilde followed by a dollar sign. Or how can I use a command inside the environment to obtain certain text like ...
7
votes
2answers
267 views

How to insert a keyword with accents (extendedchars) in listings

This is what I would like to do: morekeywords={SENÃO, ENTÃO, FAÇA, ATÉ, ENQUANTO, PARA, SE, DECLARA, DECLARE, E, OU, FIM_ENQUANTO, FIM_PARA} I'm defining a new language, and I would like to use ...
1
vote
0answers
61 views

Extra space in \lstinline

When using the \lstinline macro from listings, like \lstinline|subl| some extra whitespace is added to the intended text. It is especially painful at the end of the line: it behaves as if it were ...
6
votes
1answer
103 views

How would you typeset this type of programming documentation?

Consider, for example, this pdf document which defines the standard for the C programming language. The description of the library functions follows a fixed structure composed of three sections, as ...
3
votes
2answers
60 views

Disable formatting for a selection inside listing?

I am typesetting my MATLAB code with package matlab-prettifier, which is essentially listing. However, sometimes I do not want the formatting. I simply want pure unformatted text. For example, in the ...
1
vote
1answer
33 views

Using \lstinputlisting to include portion of file using labels instead of line numbers

I know I can include a portion of a code file like so: \lstinputlisting[language=XML, firstline=37, lastline=45]{source_filename.xml} But the line numbers will change if I modify the code file. Is ...
6
votes
1answer
35 views

Extra inter-line space becomes visible then loading package listings inside amsbook

I am typesetting a document using amsbook. In the document I would like to print some computer code using the listings package. However, it turns out that the options backgroundcolor and frame cause ...
3
votes
1answer
40 views

Why aren't my keywords recognized when immediately followed by a comma?

I am using listings to display custom keywords in bold. In my listings, those keywords are sometimes followed by a comma. However, in the example below, any comma following a keyword will prevent the ...
2
votes
3answers
871 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 ...
5
votes
3answers
2k views

Can I get a shadowbox with rounded corners? (using `listings` package)

I'm using the listings package as below: \usepackage{listings} \lstnewenvironment{pythoncode}[1][] {\lstset{language=Python, basicstyle=\ttfamily\footnotesize, frame=shadowbox, ...
9
votes
2answers
2k views

How to define a new environment with a fancy box (tikz) around sample source-code (listings)?

This is what I want to do: \documentclass{beamer} \begin{document} \begin{frame}[fragile]{Frame 1} Some \structure{Python} code here: % I want to define a new "pythoncode" environment, so ...
4
votes
1answer
40 views

Adding Keywords to Existing Language for Listings Package

I would like to add more keywords to an existing language definition so that when I use \begin{lstlisting} ... \end{lstlisting}, the new keywords are highlighted along with the predefined ones. This ...
1
vote
0answers
15 views

Lstlisting running off screen [duplicate]

The text in my lstlisting is running out of screen on the right. I googled, but only found problems with the code box's position on the left side, and white lines. My problem is that it does not know ...
2
votes
1answer
100 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} ...
0
votes
0answers
17 views

custom lstlisting environment [duplicate]

I'm using the listing package for displaying source code in my document. I want to use the minipage environment to avoid page breaks within the listing, but I don't want to write, at every listing, ...
3
votes
1answer
80 views

Line breaks inside inline code break syntax highlighting. Any workaround?

I want to have both code snippets ABC and ABC_DEF in red (in both cases only ABC is red). If I remove the literate line it works but I also want to have automatic line breaks at underlines. How can I ...
1
vote
1answer
30 views

Unwanted line spacing inside lstlisting, inside enumerate

I want to place some code inside of an enumerate whose labels are encircled letters. I'm following this question to get the encircled letter labels, but I'm having a spacing issue: ...
6
votes
1answer
114 views

IPython Notebook cells with listings

I would like to include in my document some code examples that look like the IPython Notebook cells in this image: I have produced something that looks a bit like it with the code below: ...
2
votes
0answers
79 views

fancyvrb + listings inside a list

I'm trying to put Verbatim environment from fancyvrb package, with activated interface to listings package, inside enumerate environment. When Verbatim environment is first element in \item, item's ...
6
votes
2answers
754 views

Listings language definition keyword suffixes

I'm trying to create a listings language definition for ARM assembly and many of the instructions have prefixes/suffixes (i.e. BGT, BLE, BNE, BEQ branch instructions). Is there a way to define B with ...
35
votes
3answers
25k 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 ...
1
vote
2answers
38 views

Add custom entry to \lstlistoflistings

I am using the listings package for code listings. I am using \lstlistoflistings to generate a list of code listings. I have one code 'pretend' listing which is actually plain latex code, however, ...
2
votes
1answer
68 views

Curly braces in my Java lstlisting are not shown

I'm writing my thesis with ShareLatex online tool (pdfLaTeX compiler) based on template; METU Thesis Template on ShareLatex. When I try to add a lstlisting or lstinputlisting to my document, curly ...
3
votes
1answer
39 views

Greek Text (babel) and English Code Text (listings): Problem

I use the babel package in order to write in greek with font "kerkis". I want to add code in english ("courier new" font) to my latex document but I get some difficulties. Can anybody help me, ...
4
votes
1answer
33 views

How can I apply two styles using moredelim?

I'm using lstlisting with moredelim to color sections of the listing. Now, I'd like to also underline the same sections. I found that I cannot simply add \underbar. \lstdefinestyle{foo}{ ...
1
vote
1answer
58 views

Duplicate entry on toc when using lstlistoflistings [closed]

Hi i am making my thesis on latex and i have write some code examples using the lstlisting package. Then i have used the command \lstlistoflistings to add all the example at the beginning of my ...
1
vote
0answers
27 views

Listing caption numbers are reverse in the list of listings

Consider the following code: \documentclass[a4paper,10pt]{book} \usepackage{listings} \usepackage{xepersian} \settextfont{FreeFarsi}% http://sourceforge.net/projects/fpf/ \DefaultMathsDigits ...
5
votes
1answer
53 views

lstlisting caption problem with xepersian

I am using the xepersian and lstlisting packages and I am having some trouble with the captions. Here is the code: \documentclass[a4paper,10pt]{article} \usepackage{listings} ...
4
votes
1answer
42 views

Shorthand for \lstinline{ … }?

I'm finding that I need to use \lstinline{...} a lot. I rather like the way that SX does inline code. Just enclose in back-ticks. Is this functionality available in LaTeX, or is it possible for ...
2
votes
2answers
37 views

Insert a lstlisting inside an algorithm2e

I would like to be able to present a C++ code snippet. I would like for this snippet to be captioned, referenced, and included in the Table of Algorithms generated by the algorithm2e package. This is ...
1
vote
0answers
37 views

How can I use a specific font in a program listing in Lyx?

I would like to know how to use a specific font (Arial, for example) in a program listing. The idea is to insert in my document a part of code in a 'program listing'. I found a way to insert some ...
7
votes
1answer
59 views

Automatically link identifiers in a code listing

I have some code listings (using the listings environment or the lstinline macro from the listings package) where I'd like to link all the identifiers defined in the present document to their ...
4
votes
3answers
372 views

How can I highlight text before a character with listing?

All is in the title. I would like to add a color to the text before a character with listing package. For example, I would like to add a color to text between the beginning of a line and : or =, in a ...
2
votes
1answer
84 views

TikZ annotation inside listing inside TikZ node

In the below code, on the first frame I typeset a code snippet with verbatim, and all is well. On the second frame I want to add a TikZ annotation to the code snippet, but I have to switch back to ...
2
votes
1answer
41 views

The comment is cut from a point [duplicate]

I am writing an algorithm in LATEX un=sing sharelatex.com. I have written a long comment and it is cut from a point. I have written this: %This is a LaTeX template for homework assignments ...
2
votes
0answers
28 views

Use dollar sign in verbatim environment within auctex

I am using something similar to the following, \documentclass{article} \usepackage{listings} \lstnewenvironment{shellsession}[1][] {\lstset{language=bash basicstyle=\small\ttfamily, ...
1
vote
0answers
43 views

Turn off colors using listings package in Beamer [closed]

I am using different languages in my Beamer presentation: C++, Assembler. For terminal output I have defined: \lstdefinestyle{bash-output-style}{ ...
1
vote
1answer
23 views

Center caption in boxed listings object

I have put some pseudocode in a listings object, with a caption and box around it. I have used the fancybox solution to listings objects suggested here: How to center a lstlisting Everything is fine, ...
5
votes
1answer
148 views

How can I automatically prepend a prompt (e.g. $) to each line of a listing?

I have something that looks as follows: \documentclass{article} \usepackage{listings} \lstnewenvironment{shellsession}[1][] {\lstset{language=bash, basicstyle=\small\ttfamily, numbers=none, ...