{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

10
votes
3answers
431 views

Masking \end{lstlisting}

I am not sure if I am using the right wording in title. Basically what I need is to add the following source using the listing package. In preamble: \usepackage{listings} then and is here when I ...
9
votes
2answers
269 views

Can the listings package highlight by regexp?

I'm trying to typeset SuperCollider code using the listings package. Any "freestanding" identifiers that begin with a capital letter are class names, and should be highlighted; by "freestanding", I ...
7
votes
2answers
325 views

How can I define a custom listing environment?

I am trying to define an enviroment for a specific programming language, F#. Here's my code: \definecolor{bluekeywords}{rgb}{0.13,0.13,1} \definecolor{greencomments}{rgb}{0,0.5,0} ...
7
votes
2answers
3k views

How can I ensure that a listing is not going to be split?

How can I ensure that a listing is not going to be split? If it is going to be split I want that the entire listing to move to the following page, effectively moving everything at pass. I mean any ...
6
votes
1answer
148 views

Listings: text highlighting based on prefix

How can I apply different styles to keywords depending on their prefix? Here is some sample code: (-2,0,0) (2,1,1) op-registerbox !box1 ;box1 /Blue op-setproperties I'd like to typeset words ...
5
votes
1answer
4k views

Including XML file into LaTeX

I am using LaTeX for very first time and have very basic knowledge about it. I am using the template from here to write my thesis. I am using Ubuntu 12.04. When I try to include a small XML file in ...
5
votes
1answer
451 views

Listing, zebra effect and broken lines

In Creating a zebra effect using listings, I've found one solution to produce a zebra effect for listing. Unfortunately, this only works if the lines are not broken. Is there a way to fix this? Here ...
5
votes
2answers
1k views

Fixed Width Font with LTXexample environment

Not sure why this problem has eluded me but I can't seem to get fixed width font in the code portion. I thought that this question on how to change code font would do the trick but it doesn't for me. ...
4
votes
2answers
140 views

Indent content of verbatim / lstlisting environment relative to containing environment

I want the content of \verbatim to be indented relative to the actual indent of \verbatim, not the exact number of spaces. For example, I like to indent at sections to make the LaTeX source more ...
4
votes
1answer
276 views

How can I define multiple identifier classes and styles in listings?

I'm trying to add different styles (color, etc.) to different groups of words in the listings package. Note that my question is different from How can I use multiple declarations (\textbf, \emph) in ...
4
votes
2answers
651 views

How to avoid that listings are interrupted by floats?

And again I have another problem I just can't figure out. I defined a listing with some XML code: \begin{lstlisting}[captionpos=b, caption=XML detection strategy for Refused Parent Bequest, ...
3
votes
1answer
75 views

Listings package split frame when the page ends

When I use the listings package with frame in my code the frame "breaks" when the page ends and it is open in the end of the page. I want the frame to be complete with four sides and continue in the ...
3
votes
1answer
633 views

How to tweak the LOF and LOT without using any packages?

The list of figures/tables in default book class looks like: Default looking: List of Figures 1.1 Snapshots .................. 2 1.2 Snapshots .................. 4 1.3 Snapshots ...
34
votes
1answer
462 views

listings: Copy to clipboard feature?

I was just wonder if it would be possible to have a "Copy to Clipboard Button" next to each listing which would just copy the verbatim content of the lstlistings environment to the clipboard. An ...
17
votes
2answers
8k views

How to highlight Python syntax in LaTeX Listings \lstinputlistings command

I am using package listings to import my Python source code into my LaTeX document. I use the command \lstinputlistings. I have a Python source like class MyClass(Yourclass): def __init__(self, ...
14
votes
1answer
10k views

Source code listing with frame around code?

I'd like to make my code listing looking more sexy. I found a good example on SO, but one problem is remaining: I would like to not only have a horizontal line at the bottom of the listing but also ...
10
votes
5answers
6k views

beautiful listing for CSharp

Does anyone have a nice typesetting style for the C# language using listings? I configure it in this way: \lstset{language=[Sharp]C,,basicstyle=\footnotesize, ...
18
votes
1answer
23k views

Listings caption [duplicate]

I'm using the listings package with this \begin command: \begin{lstlisting}[caption=blabla, label=amb] This yields a nice code listing with a caption like "Listing 1.1 blabla". Is there a way to ...
17
votes
3answers
12k views

Shrinking monospace style for listings package

I am working on a thesis and putting together a "pretty" listing. I'm looking at setting up a small font style for a code view. What I have here is: \usepackage{listings} \lstset{language=C, ...
16
votes
1answer
412 views

How to remove the leading unnecessary white spaces when using linerange option?

To be honest, I am looking for people who already read the listings documentation completely. If those people also cannot solve it, then the documentation does not mention anything about it. Sorry for ...
9
votes
3answers
2k views

Listing: Syntax highlighting for SPARQL query?

I use the following listing to show a SPARQL query: \begin{lstlisting}[captionpos=b, caption=SPARQL query, label=lst:sparql] PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#> ...
22
votes
2answers
2k views

Ensure verbatim code block is copy/paste-able

After rendering a document containing this code block \begin{verbatim} if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist. if [ ! -f README.md ]; ...
13
votes
1answer
3k views

Double-column listing package

Not too well up on LaTeX, but I want to use the listings package for listings spanning a two-column format. Unfortunately, asterisks cannot save me (like for figures/tables); this doesn't work: ...
9
votes
2answers
4k views

How to insert code with accents with listings?

I'm trying to insert source code in LaTeX with using listings, but my code has accents and pdflatex gives me this error: Unicode char \u8:�\expandafter not set up for use with LaTeX. This is a code ...
8
votes
2answers
559 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 ...
8
votes
3answers
1k views

Problems with copy and paste from PDF using lstlisting

I'm using lstlisting to create course notes from which I am hoping that code can be copy&paste'd I've already implemented the suggestions in Phantom spaces in listings (pdf) to make sure that ...
8
votes
2answers
590 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} ...
5
votes
2answers
588 views

Position tikz pictures at left margin of a listing code block

I'm trying to finish my attempt at having good looking unlimited line annotations for the listing environments, using tikz. The original problem was that indentation caused shifts in the positioning, ...
12
votes
2answers
2k views

How to insert code and graphic in textbox

I want to put a graphic and a little linux bash code in a textbox, like the picture blow... with the follow in problem: all in a textbox with yellow backgroud left part is a graphic (a finger)... ...
10
votes
1answer
685 views

How to extend the \lstinputlisting command

With the answer from autogobble for lstinputlistings I've managed to create a command that gobbles \lstinputlisting and makes firstnumber to start by firstline. I would like to rewrite it as a ...
10
votes
3answers
11k views

How to use different lstset settings for listings?

I would like to specify two different lstset settings in one latex file: one for java code, one for html. Is this somehow possible? The solution of ...
9
votes
2answers
513 views

Two code blocks working syncronously

I need two code blocks in my beamer frame. One will be the code and other will be the output for each line of code. I want to uncover each code line and corresponding output line. So, first it will ...
9
votes
2answers
271 views

How to add listings environment to DTX files

I am working on my first DTX file and want to add a code example, which shall be printed with listings. This works so far, but since the documentation is commented the listings code is using a full ...
8
votes
3answers
775 views

Listing language for “screen session”

I am writing a set of tutorial documents on some command-line based tools. This tutorials need to show a "screen session". Something along the lines of: $ git status # on branch "master" I want to ...
7
votes
2answers
1k views

Grouping the list of listings by chapter

I am using the listings package. I want to print out a list of listings, which I can do. The thing is that in the other listings the typesetter "groups" figures/tables by chapter. Is it possible to ...
5
votes
1answer
159 views

How can I preclude copying & pasting of listings?

When I include code snippets in my documents, my lazier readers, i.e. students :), are often tempted to just copy and paste those snippets instead of typing them themselves. However, there are risks ...
5
votes
1answer
3k views

lstlisting line wrapping

How is it possible to let lstlisting wrap lines? I've troubles with following block: \begin{lstlisting}[language=java] public class MeasureStationControllerV0Test { MeasureStationControllerV0 ...
5
votes
2answers
1k views

Minus signs vanish with listings and breqn - any solutions?

When using listings and breqn, the minus signs (or dashes, according to the unix.SX site then there's some controversy about which it is) disappear from code listing. Here's an example: ...
4
votes
1answer
271 views

Placing listing and figure side by side in memoir

I am writing a document using the memoir class where I want to place listings (with the listings package) and figures side by side. My first approach was to save the listing in a box and use subbottom ...
4
votes
2answers
3k views

How to prevent a \lstinputlisting being split across pages?

This question shows how to prevent a long listing from being split across several pages when the code is written directly into the tex file. I want to achieve the same effect when including code in ...
3
votes
1answer
4k views

Styling a lstlisting caption using caption package

I'd like to style a caption in a specific way, but I can't seem to figure out the proper settings to do so. First off, I'd like to change the label from "Listing" to "Algorithm" when I use ...
3
votes
1answer
732 views

Highlight language keywords in a paragraph?

While it is possible to highlight specific language keywords (such as public in C++) by using lstinline command from listing package as in: Highlighting a C++ keyword \lstinline|public| in a ...
13
votes
2answers
337 views

How can I make lstlisting look exactly like verbatim?

I like the way the verbatim environment looks, and I want to make my lstlistings look like it. I've tried setting the basic style to \ttfamily, but the letter kerning and line spacing seem to be ...
10
votes
1answer
136 views

Strange interaction between listings and sections

Consider this example: \documentclass[a4paper]{article} \usepackage{listings} \lstnewenvironment{shell}{}{} %\usepackage{verbatim} %\let\shell\verbatim %\let\endshell\endverbatim \begin{document} ...
9
votes
2answers
1k views

How can I remove “Listing #: ” from listings caption?

I am working on a C++ reference manual for myself and I want good-looking listings. The Stack Overflow question entitled LaTeX source code listing like in professional books was very helpful but, for ...
8
votes
1answer
349 views

Scaling inline code to the current font size

Edit: Don't even bother reading the question. Just jump straight to Heiko Oberdiek's answer :) With the listings package, typesetting listings in some absolute font size is very easy; all you have to ...
8
votes
2answers
3k views

\lstinline!Foo! vs \lstinline{Foo}

I wonder what is the difference or correct usage of \lstinline!...! and \lstinline{...}? I like better {} because I feel there it's more consistent with other commands but for example in below ...
8
votes
1answer
907 views

autogobble for lstinputlistings

In the manual for listings it says that gobble has no effect for lstinputlistings. Since the manual is about four years old now and after reading How to automatically skip leading white spaces in ...
8
votes
1answer
1k views

Package to indent and syntax highlight C++ code

I am looking for a package to have an environment for C++ source code, with options for syntax highlighting, automatic indentation, proper multipage behavior, etc. I read something about the listings ...
7
votes
3answers
236 views

Can I include Chinese characters in listings? If so, how?

I'd like to include Chinese characters in listings. Can it be done, and, if so, how?