{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

4
votes
1answer
378 views

Combining newenvironment, quote and lstlisting (mcode)

I am trying to combine various packages and commands with PdfLaTeX (through MikTex on MS Windows), including newenvironment, quote, mcode and lstlisting, to create an environment to define multiple ...
10
votes
1answer
236 views

Strange interaction between listings and sections

Consider this example: \documentclass[a4paper]{article} \usepackage{listings} \lstnewenvironment{shell}{}{} %\usepackage{verbatim} %\let\shell\verbatim %\let\endshell\endverbatim \begin{document} ...
7
votes
2answers
368 views

Uniform Unicode for text, math and listings?

What should I put in the preamble (preferably packages) for this to work as expected with its unicode characters? \documentclass{article} \usepackage{listings} \begin{document} $α$ α ...
4
votes
1answer
370 views

Using listings inside mdframed causes unknown compilation error

I have a problem with the listings and the mdframed package together. The following code compiles with errors, but the only info I managed to get about it is that it was fatal. ...
9
votes
4answers
226 views

Widow Orphan lstlisting

I have a listing of 6 lines. The listing box does not seem to fit on one page (it is on the bottom of the page) so the rest of the box is printed on the next page. There is nothing actually in the box ...
0
votes
1answer
1k views

Listing numbers go outside margin [duplicate]

I'm trying to add sample code to my document. It seems that the listing is left aligned with the margin, and the numbers go outside it. How should I align the number, instead of the code? Here is my ...
7
votes
1answer
134 views

Listings package - the symbol \ isn't colored while rest of the macro is

I am using the package listings for code printing, but I have come across a problem. I usually write down a lstlisting environment like this (this is for the LaTeX language): ...
4
votes
1answer
421 views

Captioning an mdframed box without making unbreakable

I would like to a have a caption below my mdframed box (outside the border if possible) which sometimes span across multiple pages. I managed to create a caption several ways but the pagebreaks are ...
7
votes
1answer
457 views

\lstMakeShortInline with @ delimiter

I'm including a fair amount of inline C++ code in a beamer presentation I'm making, and I want to be able to use the short syntax for \lstinline. My code displays fine if I use, for example, the ! ...
2
votes
1answer
111 views

Conditional execution based on style existence (listings)

Is there a way in LaTeX (or e-TeX) to check if a style is defined using the listings package (inside a \lstnewenvironment definition)? I mean something like this: \lstdefinestyle{tmpdefaultstyle}{} ...
2
votes
1answer
535 views

Adding caption and counter to source code environment

I have a source code listing with minted environment. How can I make a counter/caption to be shown as follows. I also need to make \tableofsourcecode to enlist all the source code references. The ...
0
votes
1answer
156 views

listings: using Python and Matlab code [duplicate]

Can I \lstset to define both Matlab code and Python code? or will last one override the first one? or does listings know the difference when there is a .m or .py extension and use the correct \lstset? ...
5
votes
2answers
152 views

Listings, Cleverref, and Appendix: Weird Alignment

I'm using the packages listings and cleverref in my thesis. When I put a listing in the appendix, however, it seems to be somehow indented: \documentclass{article} \usepackage{listings} ...
5
votes
2answers
355 views

mdframed label multiply defined (with listings and paracol)

I use three packages (in a latex "book" document) to display source files (not only tex and sometimes loaded from external files) and their outputs (sometimes loaded from external files) side by side. ...
9
votes
1answer
108 views

How to omit the last four lines of a sample code in listing

I am using the listings package to include xml samples in the documentation I am writing. I am aware of the firstline and lastline attributes \lstinputlisting[firstline=4,lastline=24]{example.xml} ...
5
votes
2answers
336 views

lstlistoflistings formatting problem

I'm using \lstlistoflistings to create list of listings. Everything generates well except for the formatting issue I have. I tried to fix it but don't have enough knowledge. This is how the ...
3
votes
1answer
428 views

How to have center title in listings when you have subcaption (workaournd conflict between listing caption and subcaption class)?

I want to use listings package (\usepackage{listings}) to show a matlab code in a paper (using elsarticle class) but the title is not aligned in center below the code. This happened after I added ...
1
vote
2answers
526 views

Listings numbering doesn't restart

I have problem with listing numbering from this topic. Numbering isn't restarted, it just continues. \AtBeginDocument{% \renewcommand{\thelstlisting}{% \ifnum\value{subsection}=0 ...
2
votes
0answers
156 views

break line at comma inside listings [closed]

I'm trying to do some listings environments, but I'm encountering problems. The ideal output is this: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,⤦ ⤷ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
3
votes
2answers
1k 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, ...
4
votes
1answer
136 views

Insert section title within index in ConTeXt

Background Each recipe in a recipe book has ingredients, and those ingredients can be common for different recipes throughout the book. For example: Code I've added the comma and colours as ...
2
votes
1answer
211 views

Handle % character in verbatim inside a grey box

I found this snippet on the internet which is used to produce a text area inside a greybox. \newcommand\greybox[1]{% \vskip\baselineskip% \par\noindent\colorbox{lightgray}{% ...
0
votes
0answers
23 views

Using bold for just one word inside listing? [duplicate]

I have a similar structure like this: \begin{lstlisting}[language=bash] Family |-father |-mother |-elderson |-younger son |-younger daughter \end{lstlisting} I need to make "mother" and "younger ...
5
votes
2answers
291 views

How do I extract repeated functionality (exsheets workaround) to make it reusable?

Speaking with Clemens (exsheets maintainer) he pointed me to a workaround by Gonzalo Medina, that helps put verbatim and listings code in the exsheets pseudo (Clemens' word choice) question and ...
6
votes
1answer
1k views

Change the color of background of code of Matlab

I use the following code in LaTeX to input the code Matlab there but I want to change the color of the background: \usepackage{textcomp} \usepackage{listings} \lstdefinestyle{customc}{ ...
1
vote
1answer
419 views

Using lstlistings in two columns

My goal is to display source code (awk, Python, R and SAS) and text (their output) side-by-side. Both are loaded from external files, and can be pretty long sometimes (pagebreaking is inevitable), the ...
8
votes
2answers
234 views

Allow source code to wrap around a figure

I would like to be able to wrap source code around a figure. Here's a MWE that should make it clear what I have in mind: \documentclass{article} \usepackage{wrapfig} \usepackage{listings} ...
9
votes
1answer
278 views

Incorrect placement of quotation marks

I just want to include some sourcecode by using the listings package wit XeTeX. Here is my minimal example: % !TEX TS-program = XeLaTeX % !TEX encoding = UTF-8 Unicode ...
18
votes
1answer
1k views

Latex and code blocks: how to mark statements that way?

I’d like to show you a nice technique used in this book to describe code listings (see pag. 6 and 7 of the PDF -- 116 and 117 of the book), in which relevant statement are labeled with special ...
6
votes
2answers
1k views

Beamer Latex Code Error In Listings Environment

I want to display a short latex code in my beamer. The code is also the about beamer. And I don't want to use the \lstinputlisting{file.tex}. So is there any way to do that? Here is the code without ...
10
votes
3answers
510 views

Fixing lstlisting inside exsheets question and solution environments

I am trying to use exsheets to prepare the tests for Foundation of Programming exam. I need to include snippets of C code in some question and solution and I am going to use listings (with the options ...
1
vote
0answers
28 views

Is it possible to automatically set numbers=none for single-line lstlisting environments? [duplicate]

I apologise if the answer to my question can be found in the listings documentation and I missed it. Essentially I would like line numbers to be set only if the number of lines is greater than one.
1
vote
1answer
177 views

Customize the name of custom listings in their “list of”

As I would like to separate the listings in my document, I decided to create two separate lists of them: one for the algorithms, and one for the sources. In addition, the sources must be loaded from ...
3
votes
0answers
344 views

How to make listings display characters special characters

I am trying to show a directory structure of a tree using the listings package like so: ├── controllers │   ├── application_controller.rb what I get looks like this: controllers ...
1
vote
1answer
353 views

Syntax highlighting for SPARQL query in a listing? (works fine in minted environment but not in listing with mint)

I can do syntax highlighting in the minted environment, for any SPARQL query using this Pygments lexer thanks to this answer. My problem is how to get SPARQL syntax highlighting to work with mint in ...
3
votes
0answers
118 views

How to make an inline landscape 2 column page look the same as a separate one from pdf? [closed]

I have a document I would like to add a code listing to. The document format is as shown: \documentclass[a4paper, 12pt]{report} \begin{document} \end{document} this is a large project with lots of ...
13
votes
2answers
225 views

Filecontents and newenvironment issue

I need to write some inlined code on an external file, then load it with listings. I would like to define a new environment, but if I do, filecontents does not save the first line of code (see MWE): ...
3
votes
1answer
195 views

Using collect to gather content with listings, comments or verbatims

I was looking into a way to set up a project with multiple files, in which several files could declare content to be included in different sections of the main tex document. After this Q&A, I ...
14
votes
1answer
13k views

Can't insert code in my beamer slide

I want to put some PHP code in my slide with the package listings but I have this error message: Argument of \frame has an extra }.<inserted text>\par } My latex code : ...
3
votes
1answer
181 views

breaking lines in listings enviroment

I am trying to make listing enviroment brake lines. Unfortunately breaklines=true does not work for me. Here is my code: \usepackage{listings} \begin{document} ...
0
votes
1answer
131 views

saner listings monospace font size relative to surrounding text size [duplicate]

Is it possible to make listings and especially inline listings font size to be saner? It appears that the font size is chosen so that capital letters of the monospace font are full height of a line. ...
8
votes
3answers
1k views

Unwanted White Lines in listings environment

\documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{basicstyle=\ttfamily\footnotesize, ...
5
votes
1answer
3k views

Change caption style of listings package without “caption” package

Is there a way to change style of a caption in listings without the caption package (make it smaller and non-bold)? I am using \lstnewenvironment to create my own customized environment and then use ...
3
votes
2answers
159 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 ...
5
votes
1answer
6k views

listings: Set tabsize while using spaces for indentation in the loaded file does not work

I am writing a report where I want to include some source code. To do so I use the listings package to load the content of the source files directly. Because of coding standards I am using 4 spaces ...
5
votes
1answer
691 views

Placing listing and figure side by side in memoir

I am writing a document using the memoir class where I want to place listings (with the listings package) and figures side by side. My first approach was to save the listing in a box and use subbottom ...
2
votes
1answer
437 views

How to prevent the source code overflow over the frame in a listing? [duplicate]

I am trying to ident my source code in a frame using the listing package. An example code is given below: \documentclass[article]{llncs} \usepackage[english]{babel} ...
2
votes
0answers
141 views

Deciding whether to end a line with a character or not in lstlisting [closed]

I need to write a document where there are written inputs and outputs of unix command line interface software (through bash). For example I need to show something like: $ git log --pretty=format:"%h ...
3
votes
1answer
459 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.) ...
2
votes
2answers
2k views

How to preserve tabs and whitespaces in \parbox in latex

I am currently trying to insert a batch file programming code in my report. I am using the code listing. I am not able to preserve white spaces and tabs to format my code! I tried using \hspace but it ...