{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

1
vote
1answer
238 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
360 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
124 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
125 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
691 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
204 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
794 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
882 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
345 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} ...
10
votes
1answer
986 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} ...
2
votes
1answer
407 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
109 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
2k 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 ...
8
votes
2answers
360 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
74 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 ...
6
votes
3answers
926 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 ...
8
votes
2answers
746 views

Combining `tikzpicture` and `lstlisting`

I'm working on a custom lstlisting environment, in which I use TikZ to add a frame and a title. Because of the widespread curly braces of node I cannot use newenvironment, so I have to resort to ...
6
votes
1answer
437 views

Wider caption for listing using multicol

I am using the multicol and listings packages. I would like to have the caption spread across the entire listing for multi-column listings. Here is a MWE of what I am attempting, however the output ...
8
votes
2answers
342 views

How can I highlight an interactive GAP session just like so?

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, ...
3
votes
2answers
326 views

Overbrace in lstlisting of Scala code

I want to add an overbrace to some text in a Scala code listing (using lstlisting). \begin{lstlisting} object TypeClass extends FooParMain { def newApp(args: Array[String]) = new FooParApp { ...
5
votes
1answer
2k views

lstlisting in a box?

My problem is that I am trying to write a document with coloured sections for examples. Examples can contain code listings. Somehow I can't seem to combine a background colouring with a listing, or ...
1
vote
0answers
26 views

How to do source code listings in ConTeXt? [duplicate]

I am new to LaTeX and ConTeXt, so I hope I am not asking something obvious. I have been able to create a LaTeX document using \usepackage{listings}. Now I have discovered ConTeXt. Is it possible to ...
7
votes
1answer
3k views

“Display math should end with $$” error

I'm trying to write math in a code listing, like so : \documentclass{article} \usepackage{listings} \begin{document} \begin[mathescape]{lstlisting} $\infty$ \end{lstlisting} \end{document} I get ...
3
votes
0answers
368 views

Regular expressions in listings [closed]

I'm looking for a possibility to use regular expression in listings. I'd like to highlight each N thats followed by 4 decimal numbers for example N1234. How can I achieve that? Here is an example: ...
4
votes
1answer
297 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 ...
2
votes
1answer
689 views

Minted: customise listing name? [duplicate]

How do I customize listing name: Listing 1: thing -- when I use minted? Here's an MWE: \documentclass{article} \usepackage{minted} % \renewcommand{\lstlistingname}{Something} % doesn't work! ...
5
votes
2answers
141 views

How to combine listing and figure into a single figure?

I am using package listings, and I would like to combine a listing and a figure into a single float. As an example, I am using listings as follows: ...
2
votes
1answer
293 views

\lstlistoflistings doesn't have enough room between numbers and title

I'm using the \lstlistoflistings command from the listings package to generate my list of code samples. Unfortunately there isn't enough room between the number and the code listing title. See the ...
2
votes
0answers
376 views

LaTeX source code listing like in professional books for \lstinputlisting [closed]

Found this topic: http://stackoverflow.com/questions/741985/latex-source-code-listing-like-in-professional-books and I'm very satisfied with this soulution, it looks just great in a generated pdf ...
1
vote
1answer
184 views

lst include has first line indented [duplicate]

When I'm including a source file, by way of \lstinputlistings{file/path/to/file} However, This results in the following below: Why is the first line not being formatted correctly? And how do i fix ...
6
votes
1answer
2k views

Adding words to lstlisting for Python langaue

I wish to add a few keywords to some python code inserted into a latex document. I want to make 'True' & 'False' appear yellow and also some module calls such as 'ttk' appear red. I have tried ...
1
vote
1answer
324 views

lstlisting: how to align highlighted code

I want to define a couple of new commands in order to highlight parts of my code (this is actually for a trace dump, not for a programming language). My problem is that I can't seem to make the ...
2
votes
1answer
1k views

Syntax highlighting for different programming languages [duplicate]

In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package: \lstset{frame=tb, language={[Visual]Basic}, aboveskip=3mm, belowskip=3mm, ...
6
votes
1answer
615 views

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 ...
7
votes
1answer
15k views

How to change fontsize in lstlisting without losing bold syntax highlighting?

If I load the listing package to set nice code and change the font size (like suggested there: Shrinking monospace style for listings package), I lose the syntax highlighting, because the font does ...
1
vote
1answer
387 views

Highlighting a Chunk of Code within a lstlisting by specifying the line number

This question in somehow related to http://stackoverflow.com/questions/1304315/highlighting-a-chunk-of-code-within-a-lstlisting but not exactly the same. I want to make some slides with animation ...
3
votes
1answer
342 views

How to suppress automatic conversion of “<=” inside lstlisting/lstinline?

I have the following LaTeX code: some text \lstinline!u <= 1! some text In my output, the two characters <= get automatically joined to form a single "less-than-or-equal" chararacter (i.e. ...
4
votes
1answer
3k views

Default value for basicstyle in lstlisting

I have most of the code in Python, which renders very nice with this simple configuration of lstlisting At a certain point I have to include an XML file, so I switched to language=XML but it renders ...
4
votes
1answer
464 views

Ignore keyword in Listings

Consider the following minimal example: \documentclass{standalone} \usepackage{listings} \begin{document} \begin{lstlisting}[keywordstyle = \textbf, language = SQL, deletekeywords = {time}] create ...
1
vote
0answers
93 views

spacing before scope resolution operator [closed]

I'm new to LaTeX and I have encountered a problem with the listings package, I have a space before the :: operator of C++ . after reading lstlisting with c++: spaces around scope resolution operator ...
3
votes
1answer
1k views

Removing small gaps between lines in LaTeX lstlisting output

Whenever I set a somewhat dark background color in a code listing it becomes obvious that there are small line separations, these of course stay white making the overall appearance not desirable. My ...
0
votes
1answer
198 views

wrap listings package - Problem with verbatim argument

I would like to define a command that wraps a lstlisting environment in some other environments (esp. a minipage). I understand that working with verbatim arguments is a difficult task. I tried the ...
2
votes
2answers
127 views

How to prevent a listing from straddling two pages

If I have a small listing that happens to be at the end of a page, how can I force LaTeX to place it on a new page so that it does not straddle two pages, which looks ugly for a small listing.
4
votes
2answers
415 views

Spaces inside Cyrillic listings

I want to include source file using listing package. In that file there are some cyrillic symbols in comments. I setup listings like: \lstset{extendedchars=\true,basicstyle=\ttfamily} And in ...
5
votes
1answer
1k views

Make lstlisting honour baselinestretch

I have to use lstlisting instead of Verbatim in a particular case, because math escape doesn't work properly with the latter. I managed to have both look the same, but lstlisting ignores my ...
3
votes
1answer
860 views

Using math mode escapes with listings enabled fancyvrb

I am trying to escape math mode within Verbatim, using this answer. This works fine, until I use the listings package with fancyvrb=true \documentclass{article} \usepackage{fancyvrb} ...