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

2
votes
1answer
348 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
488 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
996 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
640 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
189 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
86 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
337 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
370 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
987 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
243 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
673 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
488 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
251 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
433 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
853 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
334 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
820 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
2k 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
852 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
229 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.]{ ...
1
vote
1answer
157 views

Listing not printing inside “ ” [duplicate]

Possible Duplicate: Listings package not correctly showing PHP strings I'm using listings to include C code, but I've a problem: when I insert in the listing a printf like the following ...
17
votes
2answers
2k views

Coloring digits with the listings package

I'm trying to typeset some python code, and I would like integer literals to be highlighted. I've come up, after about two hours of fighting with the documentation and various other questions here and ...
4
votes
1answer
7k views

lstlisting: how to set code color and frame color

I am using lstlisting to show some code in my PDF. The problem is that when I use: basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red}, to change the code color (not only the language ...
2
votes
1answer
1k views

Frame on lstlisting opened on the bottom when code longer than one page [duplicate]

In my \lstset I have: \lstset{ language=Java, % the language of the code basicstyle=\sffamily\large, % the size of the fonts that are used for the code %numbers=left, ...
1
vote
1answer
203 views

Using package listings with sciposter

Could you please provide a working example in which a source code delimited by listings environment word wraps its lines, without breaking the column layout of sciposter? Whenever I put a long line ...
2
votes
1answer
510 views

babel package and lstlisting caption incompatibility

I am using babel package for Turkish language and I also use listings package. A code sample for one of my listings is as follows: \begin{lstlisting}[label=some-code,caption=Poo Class] public class ...
9
votes
2answers
6k views

Setting up specific font for use in listings

I'm writing my dissertion using TeX. I would like to use a specific font in my lstlisting source code. How can I use a specific font like Monaco or Arial? I usually found solutions with basicstyle ...
17
votes
3answers
10k views

Using \lstinputlisting to include a file but only certain lines or line ranges

I wanted to tidy up a TeX document and was curious if you can use \lstinputlisting or a similar function to include a certain part of a source-code file. Example, I have a 500 or so line source file ...
1
vote
1answer
408 views

Listings settings for command line arguments [closed]

I am typesetting a set of instructions which includes several (Unix) command line arguments. I have been using the listings package to include these arguments, but the colouring is less than ideal. ...
15
votes
3answers
3k views

\autoref does not capitalize initial character in sentence when referencing label in listings environment

I have defined the following \providecommand*{\lstnumberautorefname}{line} and within my text \begin{lstlisting} |\label{sdd_1}|<sqlCallStatistics>YES</sqlCallStatistics> ...
5
votes
1answer
493 views

Narrow underscore in listings package

I've been using the listings package for a while, but have only recently noticed that the underscore is rendered with less width than the other characters. I'm working on some code snippets now which ...
1
vote
2answers
1k views

LaTeX listing counter counts with every \pause-command?

I'm writing a TeX-File for a beamer presentation and have a problem with the \pause-command and the listing counter: The Listing counter increments its count with every \pause command – although I ...
4
votes
1answer
862 views

Suppress line numbering for specific lines in listings package

I would like to suppress the line numbering for specific lines in listings package by identifying the specific lines using some kind of command.
5
votes
1answer
3k views

Fortran syntax highlighting in listings

I've got some Fortran 90 source code I want to put into my thesis appendix. For this I'm using the listings package. Is it possible to have colored syntax highlighting for the Fortran code?
6
votes
2answers
2k views

Suppress line numbering for empty lines in listings package

The listings package quite nicely formats my pseudo code listings. Is there a way that one can specify that line numbering should be suppressed for empty lines?
3
votes
2answers
5k views

Frame around minipage containing listing in beamer

I am working on the sheets of a course on LaTeX and would like to have several sheets in which you see on the left an example of a source document and on the right its output. I have this working now ...