{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
29 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. ...
1
vote
1answer
21 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: ...
4
votes
1answer
39 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
52 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} ...
1
vote
1answer
33 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}} ...
4
votes
1answer
41 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 ...
2
votes
1answer
78 views
+50

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 ...
0
votes
0answers
25 views

Description list looking like a glossaries list

Is there a package or something that allows me to create a list (like description) that looks like a glossaries list, where the descriptions are indented the same length? Like it is if the ...
0
votes
0answers
23 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
39 views

Define listing for different languages

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
44 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 ...
3
votes
1answer
68 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 ...
1
vote
0answers
21 views

Lyx program listings output wrong symbols [duplicate]

This is what I added to the preamble: basicstyle={\footnotesize\ttfamily} emph={si, //,{,}, <, >, if, para, cada, devolver, en, de} emphstyle={\color{red}} frame=single ...
0
votes
0answers
34 views

line spacing in lstinputlisting with floats

I have a document with many code listings using \lstinputlisting. Some are floats for convenience and some (multipage listings or others that need explicit placement) do not float. If the listing ...
3
votes
1answer
59 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? ...
4
votes
1answer
89 views

8 column table with lstinputlisting in LaTeX

I'd like to create a multicolumn table (up to 8 columns) to insert my code via \lstinputlisting{source.c}. But it seems to me that more then 6 columns aren't possibile even tough space is available. ...
0
votes
0answers
27 views

listings range end markers in comments with texcl

I'm trying to using the listings package to generate nice listings of some Lisp-style code (where line comments begin with a ;). I'd like to keep the code compilable, and so put the range markers ...
1
vote
1answer
47 views

Changing Style Inside LaTeX Listing

In short, I'm trying to combine some C code with its disassembly in LaTeX such that the x86 code is displayed after the relevant statement. In order to make this look nice, I would like to be able to ...
5
votes
1answer
98 views

Quoting shell commands

My question is, how would you typographically approach quoting of shell commands? My current solution does not satisfy me completely. Current look:
3
votes
1answer
74 views

LaTeX - Using commands inside inline code

I want to be able to have inline code (printed in typewriter or something) where I can also use LaTeX commands like \myinlinecode{here comes a backslash: <\textbackslash>}. So it should be ...
5
votes
1answer
48 views

error with LuaLaTeX, lstinputlisting and an extension-less file

I'm having troubles with LuaLaTeX and the listings package: the former doesn't seem to accept me performing \lstinputlisting on a filename that doesn't have an extension. Minimal example: Makefile: ...
4
votes
1answer
43 views

Dirtree and lstset side by side

A \dirtree and a \lstset should be shown side by side. With the code below the \dirtree is vertically not on the same level as the \lstset (above the \dirtree is some empty space). How can I fix that? ...
8
votes
2answers
97 views

Using listings package for documenting LISP code in two column mode

Using listings package, I am trying to write some LISP code. The issue is that LISP uses a lot of '-' in function name, and it makes the line width too large to break the boundary in two column mode. ...
2
votes
1answer
54 views

Environment lstlisting undefined

Hi I have installed the listings package in order to display my code. I am running the following code within my document: \begin{lstlisting} public static void main(String[] args) { ...
2
votes
2answers
54 views

Adding a caption or title to a listing in an mdframed environment

I have several pieces of Matlab script I have put into boxes using the below method. I want to be able to call them listings 1 2 3 4 etc. Preferably a command that will do it automatically for me. New ...
2
votes
1answer
68 views

Compilation fails with “! Missing \endcsname inserted.”

Hi I've got a strange problem. I've defined a new command to print Linux commands line in the document: \documentclass[12pt,a4paper]{article} \usepackage{listings} \newcommand{\shellcmd}[1] { ...
1
vote
1answer
48 views

Use multiple languages using lstset? [duplicate]

My MWE : \documentclass[12pt,a4paper]{report} \usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry} \linespread{1.5} \usepackage{listings} \usepackage{color} ...
1
vote
1answer
40 views

linerange in listinput firstnumber conflicts with stepnumber

If I create a code include as follows: \lstinputlisting[linerange=39-46, firstnumber=39]{./Matlab/script.m} And set the stepnumber to 5 in the lstset: \lstset{...,stepnumber = 5, ...} Line 40, ...
5
votes
1answer
65 views

Align appearance of listings and algorithm packages

I want the output generated by the listings and the algorithm package to be the same. Consider the following minimum working example. ...
0
votes
1answer
68 views

typing @ sign in lstlisting [closed]

is there a way to type the "@" sign in lstlisting? I have tried just putting @ or \@ but both don't seem to work: @testing 123 or \@testing 123 it just outputs testing123
1
vote
1answer
77 views

Trying to include R Code with listings package

I was trying to include some R Code in a simple LaTeX document, but for some reason I could not do it. I put the R Code in the same directory (I also tried putting the full directory for my R Code) of ...
1
vote
0answers
42 views

How to add a caption to a listing with minted?

Package minted provides a way to add captions and labels to a listing wrapping it around with listing environment. With this environment the code block is put inside a floating box which won't break ...
12
votes
0answers
74 views

Help defining PDF syntax with listings package

I'm trying to make a pdf language definition for the listings package, but I can't get the string definition to work correctly. This is what I have defined: \lstdefinelanguage{pdf}{ ...
2
votes
0answers
56 views

1. Orderly sorting questions, 2.Resulting right answers using package exerquiz

I have two datasets, each containing problems dealing with a specific topic. These problems are stored in external files (again, one file per topic) and loaded into the datasets in a order. I need to ...
0
votes
0answers
90 views

Cannot install listings through MikTex package installer

When I was trying to install the listings package through package manager, it showed that The operation could not be completed because the following file failed verification: ...
5
votes
1answer
65 views

Is it possible to use the listings package incrementally in beamer?

Given a frame that has code rendered in a \begin{lstlisting}...\end{lstlisting} environment, is it possible to use beamer's incremental frame building feature to highlight code snippets? Here is an ...
9
votes
2answers
165 views

Any way to show LaTeX example code *and* execute it? [duplicate]

In (La)TeX documentation and tutorials, it is common to show a snippet of code next to the output it generates. It might be two minipages side by side, or a code listing followed by boxed output, or ...
2
votes
1answer
42 views

resizebox fails for tikzpicture when used in conjunction with listing package

Here is the example that fails \documentclass{standalone} \usepackage{tikz} \usepackage{float} \usepackage{listings} \usepackage{color} \usepackage{textcomp} \usetikzlibrary{shapes,positioning} ...
3
votes
0answers
49 views

texcl, escapeinside, and single character comments, with listings package

I'm using the excellent listings package to typeset some code in a language very similar to Scheme. The language has one type of comment: when an (un-escaped) semicolon is encountered, the rest of ...
5
votes
1answer
55 views

Listings line numbers that match the linerange specification

This is a follow-up question to First line number in lstinputlisting environment. Consider the MWE: \documentclass{article} %\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox ...
0
votes
0answers
23 views

LaTeX - listings: Color digits but not in variable names

I am using the listings LaTeX package to so some C code high-lighting and I am facing a slight issue. I would like my numbers to be coloured in red, but not when they are part of a variable name. For ...
5
votes
1answer
75 views

tikz inside lstlisting inside tikz

Here is the minimum working example: \documentclass{article} \usepackage{tikz} \usepackage{float} \usepackage{listings} \usepackage{color} \usepackage{textcomp} \usetikzlibrary{shapes,positioning} ...
3
votes
1answer
59 views

verbments (listings alternative) and UTF-8

This is a follow-up question to UTF8 for listings With these MWE I will not see the german umlauts in the resulted pdf (XeLaTeX was used): \documentclass{article} \usepackage{verbments} ...
6
votes
0answers
118 views

UTF8 for listings

With German umlauts I have to define these characters (Typesetting UTF8 listings with German Umlaute) and the following MWE is working: \documentclass{article} \usepackage[utf8]{inputenc} ...
1
vote
1answer
44 views

listing package: colored numbers, but not colored in variable names

How to format all numbers in a different color has been discussed in this post. However, this also colors numbers that are part of a variable name. Is there an option to avoid that? ...
2
votes
1answer
39 views

listings package: formating all numbers in language definition?

How to format all numbers in a code has been shown here. I have adapted it to include it in a language definition: \documentclass[fleqn, a4paper]{article} \usepackage{listings} \usepackage{color} ...
3
votes
1answer
118 views

How to include Maple code in LaTeX?

At here Fanciest way to include Mathematica code in LaTeX we can include Mathematica in LaTeX. I want to include the code restart: with(geom3d): eqS:=Equation(sphere(S,(x-1)^2 + (y-1)^2 +(z-1)^2 ...
4
votes
1answer
43 views

How to refer to the count value of number of lines in a lstlisting

I need to refer to to the count value of the number of lines in a listing. Is there a way to do that ? \lstinputlisting[caption={SPARQL query used...},label={lst:sqry}]{codes/sparql_query.sparql} ...
3
votes
1answer
33 views

Add key for new Listings environment

I'm trying to add a new key to a custom listings environment. I have tried to modify this example. My problem is that the value I am attempting to pass through in the document for the key does not ...
4
votes
2answers
97 views

Listing with mixed english and russian symbols in comments

I'm using the listings package for formatting .cpp code in LaTeX. My code needs to have mixed English and Russian words in comments. The font must be monospaced (preffered Courier family). /* Prints ...

1 2 3 4 5 17