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

Setting Entries of List of Listings in LaTeX. Package Listings

I'm trying to put an hyphen after the entries of the "List of Listings" as follows: List of Codes Code 1 -- First Code ................................ 7 Code 2 -- Second Code ...
6
votes
1answer
99 views

Can I have a pipe character inside the argument of \lstinline?

I'm using the Listings package and I wanted to ask whether it is possible to use the pipe character | with the \lstinline command as it uses the pipe as beginning and ending character. ...
5
votes
1answer
79 views

How can I put a code listing in a tikzposter \block?

I'm trying to put a code listing in my poster, but I get the following error: TeX capacity exceeded, sorry [input stack size=5000] What am I doing wrong? \documentclass[portrait, a0paper, ...
1
vote
1answer
100 views

Adding a horizontal rule between caption and lstlisting inside a tcolorbox

I have example listings for a book. I'd like a horizontal rule the width of the tcolorbox between the caption and the listing. The code used to produce it: ...
1
vote
0answers
40 views

Using xtable with listings package

I am the listings package as suggested by the following solution provided in this question: Getting Sweave code chunks to stay inside page margins? More specifically, I am using the following piece ...
3
votes
1answer
49 views

Using lstenvironment in another environment

The following simple latex code doesn't seem to work for me and there seems to be no reason why: \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{listings} ...
2
votes
0answers
80 views

linewrap included Javafile with lstinputlisting

I've spent few days already trying to properly include a Java source file dynamically in a tex file. The text is included. However the lines don't wrap. The following is the "srinked" project ...
2
votes
1answer
53 views

Use macros within listing

I would like to use I macro I have defined (including mathematical symbols) within a listing environment. However, the following code prints "\foo{x}" rather than "bar(x)". Is there any way of ...
1
vote
0answers
28 views

Listings - two word keywords [duplicate]

I use the OPL language for optimization and I’m writing some notes on Latex using "listings". I defined the language and the keywords, so far no problems. However I have a keyword “subject to” and a ...
3
votes
1answer
94 views

Context dependent keyword color (listings). Question regarding (ab)using “otherkeywords”

I found it difficult to phrase this question briefly. Therefore I will try to construct it in such a way that I at least ask it clearly. My question is specific to: "otherkeywords" in the LaTeX ...
6
votes
2answers
187 views

How to define macros in order to reuse key-value parameters?

I use the listings package to typeset code in my document. I have defined a new environment via \lstnewenvironment in which I use \lstset to set a large number of options through a list of key-values. ...
3
votes
1answer
138 views

Combining MATLAB and C++ code in Latex

I have included MATLAB code in my report with \begin{lstlisting} and \end{lstlisting} but, in the same report, I need to include C++ code. I want it to recognise the language and highlight with colors ...
6
votes
1answer
95 views

Highlight code with squared brackets

I want to show some .ini file in my work. The ini file works with squared brackets. I try to use \lstdefinelanguage but I can't handle it. That is what I try before and in my understanding it should ...
1
vote
0answers
48 views

use path with spaces in listings fails when \usepackage[dutch]{babel} is used

EDIT: I just discovered that it is not due to the spaces but the " ": {"E:/Cloud storage/GitHub/JS_PCI/afronden2.js"} this line works if Babel is disabled and this one: {E:/Cloud ...
2
votes
0answers
26 views

XeLaTeX Listings package tabsize not correctly shown

I'm using XeLaTeX and I used the listings package to display some source code. In \lstset I set the tabsize to 4: \documentclass[a4paper, 11pt]{article} \usepackage{filecontents} ...
3
votes
1answer
78 views

Change caption of lstlisting from file

I load some code to my document like this: \lstinputlisting{MergeSort.txt}. This works perfectly, however I would like to add a caption in footnotesize to the bottom of the source code (without any ...
1
vote
0answers
32 views

Changes sides of lstlisting line numbering when switching pages

I am currently writing some tesxt for my masters thesis. I have a coste listing which expands on two pages. I would like the listing to change sides of line numbering when switching the page. Is there ...
0
votes
1answer
187 views

Undefined control sequence listings package

I'm working with TexMaker and I can't compile my documents because it apears de problem "Indefined control sequence", with the \usepackage{listings}. How do I fix it? \documentclass[10pt]{article} ...
1
vote
0answers
52 views

Highlight indentation level in code listings

I try to highlight the indentation level of some code listings to explain indentation behaviour of my language. My language is whitespace sensitive. Indentation indicates block structure similar to ...
1
vote
1answer
160 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 ...
0
votes
0answers
52 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 ...
5
votes
3answers
132 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 ...
2
votes
1answer
62 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
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 ...
2
votes
1answer
48 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
48 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 ...
1
vote
1answer
48 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 ...
3
votes
1answer
65 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 ...
7
votes
1answer
57 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 ...
5
votes
2answers
123 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 ...
6
votes
1answer
126 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 ...
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 ...
0
votes
0answers
23 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, ...
1
vote
0answers
85 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 ...
1
vote
1answer
56 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
219 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: ...
3
votes
0answers
200 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 ...
1
vote
2answers
78 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
133 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
98 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
65 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
0answers
42 views

Listing caption numbers are reverse in the list of listings [closed]

Consider the following code: \documentclass[a4paper,10pt]{book} \usepackage{listings} \usepackage{xepersian} \settextfont{FreeFarsi}% http://sourceforge.net/projects/fpf/ \DefaultMathsDigits ...
4
votes
1answer
57 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 ...
1
vote
1answer
104 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 ...
2
votes
2answers
66 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 ...
5
votes
1answer
100 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} ...
1
vote
1answer
53 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
63 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 ...
2
votes
1answer
138 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
47 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 ...