{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

8
votes
2answers
2k 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 ...
5
votes
1answer
3k 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
402 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
210 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 ...
8
votes
1answer
5k 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
182 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 ...
4
votes
1answer
8k 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 ...
7
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} ...
5
votes
1answer
5k 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 ...
2
votes
0answers
2k views

Latex to HTML using Pandoc [closed]

I have a bunch of tutorials I have written and they are written in Latex. Now I want to convert them to HTML and to Blogger also. I heard about Pandoc and decided to try it. Below are my results : ...
5
votes
3answers
937 views

Combine \listoflistings and \listofalgorithms into one list

The title said it all...I want to combine the two under one list with the title "Algorithms and program code". Style wise the page should match the usual style of the other lists (\listoffigures, ...
0
votes
0answers
35 views

How to pagebreak within listings? [duplicate]

I have a quite big txt file, and the problem is, if I include it with listings, latex tries to put it on one page, but it is too big for one page. So a part is missing. I am wondering, if Latex could ...
4
votes
1answer
86 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. ...
2
votes
1answer
131 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: ...
5
votes
1answer
204 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
345 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} ...
4
votes
1answer
640 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}} ...
5
votes
2answers
312 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 ...
3
votes
1answer
566 views

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 ...
1
vote
1answer
247 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
59 views

Define listing for different languages [duplicate]

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
885 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 ...
6
votes
1answer
625 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 ...
6
votes
1answer
1k 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? ...
5
votes
1answer
276 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. ...
3
votes
1answer
357 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 ...
3
votes
1answer
537 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
397 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
1k 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 ...
8
votes
2answers
868 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
188 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
613 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
3k 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) { ...
4
votes
2answers
496 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
3k 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
1k 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
242 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
365 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
125 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
7
votes
1answer
7k 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
58 views

How to add a caption to a listing with minted? [duplicate]

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 ...
14
votes
1answer
225 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}{ ...
5
votes
1answer
128 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 ...
12
votes
2answers
716 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
210 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} ...
4
votes
1answer
2k 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 ...
8
votes
1answer
821 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 ...
7
votes
1answer
904 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
352 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} ...