Tagged Questions

{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
1k views

lstlisting ignores float setting

My document starts with: \begin{document} \lstset{ % language=Java, float=tb } However all listings appear exactly just where they have been defined, e.g. this one: ...
8
votes
2answers
629 views

Attach listing to PDF

I would like to add listings source as attachment to a PDF (created by pdflatex). For \lstinputlisting this is pretty easy: \RequirePackage{listings} \RequirePackage{embedfile} ...
4
votes
1answer
340 views

Using listings for R code with ## in rangeprefix

In R, comments are preceded by the symbol #. Moreover, to avoid messing with the indentation, it's usually ## instead of #. Therefore, as I want to include some R code in a LaTeX document, I am using ...
3
votes
1answer
212 views

Is there a way to tell listings what to do immediately after escaping?

What I want to do is having two or more possibilities when escaping from normal code formatting. For instance, if I give the option escapechar=\⠶ I would like to avoid saying something like this: ...
6
votes
1answer
4k views

Colored strings by listings package

I'm trying to type my C++ homework by LaTeX in order to prepare it as a pdf file. I want to have my keywords in blue, my numbers in violet and my strings in reddish brown. I could do the two first by ...
5
votes
1answer
1k views

Showing only specific lines using the listings package

I am very new to TeX. My source code is in an external file, let's call it source.java, and I use \lstinputlisting{source.java}. How could I use only the lines 3-5 for my code listing? (and not the ...
0
votes
0answers
43 views

I cannot get an image and `lstlisting` aligned in a table [duplicate]

Possible Duplicate: How to align picture top left in a table? I want to display an image and some lines of monospaced text with line breaks (as far as I know, lstlisting is the only ...
4
votes
1answer
532 views

remove unwanted contents from list of listings

The following code adds a wrong line to the list of listings \documentclass{scrbook} \usepackage{listings} \usepackage{filecontents} \begin{document} \begin{filecontents*}{democodefile} ...
3
votes
1answer
359 views

Sync listings caption numbers and add all to List of Listings

I want to create a list of all listings. Listings itself allows to add captions and list them in a list using \lstlistoflistings, but they can not float. If I set up such a floating environment using ...
4
votes
1answer
559 views

lstinline loses braces when used as an argument to another command

I'm using the listings package, for the Java language (which, as all C-like languages, uses braces as a block delimiter). I intend to use \lstinline{...} as the second argument to a command for ...
5
votes
1answer
537 views

How to define macro that only makes argument substitution?

I am having some problems when I define a macro whose content has the lstlisting environment. For example, (assume ! is the escape char inside the lstlisting environment) \def\mycode#1{ ...
4
votes
1answer
997 views

Custom line numbers in lstlisting environment

I am using the lstlisting environment to display code and it works great, however for my current application I need something like: line 1; 3.1: line 2; line 3; 3.1.5: line 4; ...
2
votes
1answer
902 views

Using “listings” package to colorize the source code of ANTLR grammar file?

I use listings package in my diploma thesis for source code. Besides the mainstream languages like Java and C# I also need to include the sources of the language grammars (.g) which are pure mark-up ...
8
votes
1answer
896 views

listings bug: space after literate replacement lost with spaceflexible/fullflexible columns

Problem with space being lost in listings immediately after a literate replacement when using columns=spaceflexible or columns=fullflexible (appears correctly with columns=flexible). A small example ...
3
votes
0answers
105 views

listings bug: space after quote collapsed when inlined with spaceflexible/fullflexible columns [duplicate]

Possible Duplicate: listings bug: space after literate replacement lost with spaceflexible/fullflexible columns I seem to have stumbled upon a minor bug in listings (version 1.4 as of ...
13
votes
1answer
2k views

Manual highlight of TeX code in a verbatim environment

Friends, I'm stuck with a unusual situation: I'm trying to highlight specific words of a TeX code inside a verbatim environment. I know listings can help me by defining a set of keywords, but in this ...
2
votes
1answer
356 views

Latex Listing Format Error

I'm having some difficulty with getting the listings package to properly format code snippets. In particular, it does not consistently bold keywords and italicize comments. The code I am currently ...
5
votes
1answer
1k views

Remove top and bottom margins around listings

When using the lstlisting environment, or similar ones from the listings package, there are paragraph-like margins above and below the actual text. This makes sense in a paper, but gets in the way if ...
10
votes
1answer
492 views

Draw comparison lines between two listings

I have a LaTeX code set up as so: \documentclass[a4paper,10pt]{report} \usepackage[utf8]{inputenc} \usepackage{fullpage} \usepackage{listings} \usepackage{graphicx} \usepackage{float} ...
4
votes
1answer
3k views

Define a new caption in a listing environment

I want to have different listings with different types of captions, consider that I've got the following: \documentclass{article} \usepackage{listings} \usepackage{color} \usepackage{caption} ...
10
votes
3answers
1k views

Avoiding “minus sign” dash in listings commentstyle

Is there a general way to get listings package to typeset a hyphen as a minus character in the rest of the code (the default behavior), but typeset a hyphen as a true hyphen if it occurs in comments ...
4
votes
1answer
663 views

How to color digits with the listings package

For my project, I've been using the listings package in order to color the keywords, comments, strings, and digits in the code. The thing is, I've managed to color the keywords, comments and strings, ...
3
votes
1answer
193 views

Problem with listings-ext [closed]

I am using listings-ext on Ubuntu 11.10 (with LyX) and listings.cfg defines the style colored-code - which I also use in the LaTeX preamble: \usepackage[style=colored-code]{listings-ext} But ...
7
votes
1answer
1k views

Problem with underline in listings

I want to underline some code in my source code included using listings. I did the following but the underline is including the white space before the statement. How could I do it so that it only ...
9
votes
3answers
3k views

Typesetting UTF8 listings with German Umlaute

I'm having some issues with listings that include German Umlaute. The following example code generates a completely messed up PDF. \documentclass{article} \usepackage[utf8]{inputenc} ...
4
votes
1answer
88 views

Handling Truncated Listings

I included some listing in my document using the listings package but some of the lines are rather long and are being truncated. How do I best handle this issue?
8
votes
2answers
1k views

Full width code listing within two column text

I am using multicols to create two columns for body text. For code typesetting I am using the listings package. For the latter I have created an environment using \lstnewenvironment command, used as ...
12
votes
1answer
1k views

How can I pass underscore to \newcommand properly?

I'd like to simplify my code appendix with this command definition: \usepackage{listings} % ... \newcommand{\CodeListing}[1]{% \lstinputlisting[caption=#1]{#1}% } That is, the caption should be ...
4
votes
1answer
344 views

Using LaTeX listings throughout the document

I've got a LaTeX document with a main file and many sub-files. Because we're writing a documentation we use code snippets everywhere. How can I define a listing and use it throughout the documents? ...
7
votes
1answer
381 views

How can I prevent lstlisting with shadowbox-style to be split?

I have my listings styled with frame=shadowbox. In some cases the lower or upper border of a listing appears on the previous or next page (see screenshot). I do not wrap the listing in a minipage ...
12
votes
3answers
1k views

How to typeset - - with lstlisting package?

Consider this small example: \documentclass[a4paper,10pt]{article} \usepackage[utf8x]{inputenc} \usepackage{listings} %for listings of the source code \begin{document} \lstset{language=sh} ...
7
votes
1answer
245 views

How would I recursively add the document source code to an appendix?

For kicks, I would like to include the source code as an appendix. It's rather superfluous, yes, but it's puzzling. I commonly have documents that are structured thusly: main.tex includes: ...
2
votes
1answer
698 views

how do I remove “Listing 1” from my lstlistings code?

This is my latex code: \documentclass[12pt]{article} \usepackage{listings} \begin{document} \begin{lstlisting}[caption=Figure 3] Source | SS df MS Number of obs ...
2
votes
2answers
494 views

LaTeX Source Code Listing Horizontally In Figure With Subfloats

I'm trying to embed a couple of listings \begin{lstlisting} >>> from sympy import Integral, latex >>> from sympy.abc import x >>> latex(x**2) x^{2} \end{lstlisting} ...
4
votes
1answer
253 views

How to highlight a non-ascii keyword using the listings package? [duplicate]

I'm trying to highlight a couple of keywords which contain non-ASCII characters using the listingsutf8 package. This is the relevant part of my document: \usepackage[brazilian]{babel} ...
6
votes
1answer
93 views

Can I let a listing move up two lines without introducing a break in a paragraph? [duplicate]

Possible Duplicate: How to prevent lstlisting from splitting code between pages? I have a rather long listing on a page that has 3-4 lines on the following page. Just before the listing is ...
0
votes
2answers
150 views

Mysteriously fails to compile when I comment a line

I set up a github repo with a not-so minimal working environment (sorry for that). As the README at github says, uncommenting the following stupid line solves the problem and makes the ...
3
votes
2answers
439 views

How to emphasize the character '&' within a listing?

How do I emphasize with the listings package the column separators in a tabular environment? This is my MWE: \documentclass{article} \usepackage{lmodern} \usepackage{graphicx} ...
5
votes
2answers
865 views

How to mark whole line or part of line with background color in a listing (listings package)?

I want to highlight either a whole line of code in a listing, or a part of line (a subexpression) using background color (to not interfere with syntax highlighting). I use lstlistings environment ...
3
votes
2answers
1k views

How do I tell alltt environment to wrap text?

I have an already formatted text (space-wise) that is also being colored etc, so I am using alltt environment to print it. The text is code actually, but I am not using listings because I don't want ...
2
votes
1answer
337 views

Force minted to insert new space in code that won't fit on the page

Essentially I would like to have listings' breaklines option on minted. I can't seem to find it. I could manually insert new lines but it becomes difficult when the code comes from an external file.
7
votes
3answers
836 views

Best way to write an xml tag

I'm writing a document about an XML schema, and I will be talking a lot of times about that <tag1> or that other <tag2>. Since I'm only mentioning them and not printing a whole XML file, ...
2
votes
1answer
1k views

LaTeX/Packages/Listings and subindex

I am using LaTeX/Packages/Listings AND this code to make a rectangle with sql source code inside of it, but I would like to have the option to insert subindexes... I try it using the following but ...
5
votes
1answer
1k views

How can I use multiple declarations (\textbf, \emph) in listings' emphstyle?

How do I provide multiple emphstyles with the listings package? \begin{lstlisting}[emph={if,for},emphstyle={\textbf\emph}] if something end if \end{lstlisting} Both styles above (\emph and \textbf} ...
2
votes
1answer
1k views

How to render XML tag brackets bold with listings package?

I'm currently using the listings package to render my XML snippets. The default XML language settings recognize elements, attribute and text properly and my style is set to render tag names bold, ...
1
vote
1answer
3k views

Listing of a file with underscores in its name/path

I am writing a report with LaTeX and I need to list some source code. One of the files has some underscores in its path/name. When compiling the following line : ...
5
votes
1answer
864 views

Highlighting strings between [ and ] in lstlistings

I want to use lstlisting to present a file like this: #comment [keyword] key1=value1 key2=value with RegEx [keyword:NewKeyword] key1 = value1 key2=value with RegEx and this is my language ...
11
votes
1answer
5k views

lstlisting in two columns

I would like to have two listings, side by side. They have approximately the same length, therefore I don't care about how it's layed out if one part is longer. I tried \begin{minipage}{\textwidth} ...
4
votes
1answer
232 views

Multiple listings using range markers and PGF's \foreach

I've been trying to include multiple code snippets from a unique source file by using listings's range markers (named lines) and PGF's \foreach macro: \foreach \x in {1,2,...,8} { ...
4
votes
2answers
2k views

How can I put lstlisting block into subfloat block?

I'm trying to compile my document but it's exploding. I've narrowed it down to this section: \begin{figure}[h] \caption{These are my awesome code snippets} \subfloat[This code runs every cycle.]{ ...