{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
53 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}} ...
2
votes
1answer
25 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 ...
5
votes
2answers
59 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} ...
0
votes
0answers
22 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 ...
7
votes
1answer
191 views

Making Source Code Copyable with listings

I'm using listings to display some matlab code in my latex document but i'd like to have syntax highlighting. I've tried two ways of getting syntax highlighting and neither make the code copyable. The ...
3
votes
1answer
31 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 ...
0
votes
0answers
27 views

error while using listing package “ argument of lst@for has an extra”

In my current document, I am using listing package for including external code snippet. See the following code, where I am inserting code snippet externally using \lstinputlisting. \lstset{emph= ...
1
vote
1answer
35 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]", ...
2
votes
1answer
42 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 ...
2
votes
1answer
31 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 ...
3
votes
1answer
137 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 ...
13
votes
4answers
4k views

Using \ttfamily with \bfseries (or how to enable bold in fixed-width font)

I'm using listings package, and I've added basicstyle=\ttfamily\footnotesize. However, when I do that, the keywords from the embedded source-code are not bold anymore. I figured that \ttfamily ...
4
votes
1answer
66 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} ...
2
votes
1answer
65 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 ...
6
votes
1answer
232 views
+50

Strange error when combining Beamer, Animate, Tikz and Listings

I'm working on some slides where I show how code is actually executed in Java. Therefore I'm working with the animate package to generate animations. Without going into details, I've written a macro ...
4
votes
3answers
58 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, ...
1
vote
0answers
41 views

Latex to HTML using Pandoc

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 : ...
0
votes
0answers
28 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 ...
5
votes
1answer
156 views

is it possible to add line numbers to input files read using \verbatiminput?

I know one can use \usepackage{listings} which supports line numbers. And I use that for pdf files. But I also generate HTML using Latex2html, and l2h does not support this package. It only supports ...
4
votes
1answer
39 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
29 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: ...
2
votes
1answer
91 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 ...
5
votes
1answer
51 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
66 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
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 ...
0
votes
0answers
44 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
50 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
74 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 ...
3
votes
1answer
61 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? ...
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 ...
10
votes
3answers
2k views

Phantom spaces in listings (pdf)

I have a problem with SQL code in a PDF document. For code representation I'm using the listings package. Everything works perfect until I copy-paste that code from the created PDF document. I get ...
0
votes
0answers
41 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 ...
4
votes
1answer
91 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. ...
1
vote
1answer
51 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 ...
0
votes
0answers
32 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 ...
5
votes
1answer
102 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:
2
votes
1answer
53 views

Use pxfonts in listings only

I really like the pxfont package for displaying code in listings. I would usually just do this to load pxfont for the entire document; \usepackage{pxfonts}. However, this time I am required to use a ...
6
votes
1answer
126 views

Typesetting an interactive “screen session”

Suppose I want to typeset a screen session in some programming language (GAP in my case, but it could be Python, BASH, or something else with an interactive read prompt just as well). So on my screen, ...
8
votes
2answers
101 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. ...
8
votes
1answer
1k views

How can I use LaTeX-commands inside of a listing?

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the ...
3
votes
1answer
79 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
53 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: ...
12
votes
0answers
80 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}{ ...
4
votes
1answer
45 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? ...
2
votes
1answer
62 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
56 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
73 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
54 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
44 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, ...
1
vote
0answers
45 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 ...

1 2 3 4 5 17