{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
2answers
2k views

Can I get a shadowbox with rounded corners? (using `listings` package)

I'm using the listings package as below: \usepackage{listings} \lstnewenvironment{pythoncode}[1][] {\lstset{language=Python, basicstyle=\ttfamily\footnotesize, frame=shadowbox, ...
3
votes
1answer
109 views

Environment for two columns with lstlistings

In order to reduce copy-pasting, I want to create an environment that will produce a two-column table with headers and two listings in different languages, like below: \begin{tabular}{l l} Python ...
3
votes
1answer
207 views

odd displays of accentuated characters in lstlisting environment

when i try to write accentuated characters (éà...) in a lstlisting environment, hence : \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{xcolor} ...
3
votes
2answers
411 views

listings: General settings for a language seem to be overwritten/not respected

I struggle with the following listings styles. I have code of two different languages (R and LaTeX) in my .tex file. As some settings are the same for R listings and LaTeX listings, I define the style ...
3
votes
1answer
320 views

How to remove the skip after a listing when “\parskip” is increased with “\baselineskip”?

I've increased \parskip with \baselineskip to use the "skipped" paragrahs style instead of the default "indented" style. However, this causes all listings to automatically include a baselineskip ...
3
votes
2answers
581 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
3answers
916 views

Changing side of line numbering in two columns documents

I'm trying to type some report and I have a small problem with the twocolums document class and the line numbering in listings. The document is on two columns : ...
2
votes
1answer
74 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} ...
2
votes
1answer
581 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, ...
2
votes
1answer
195 views

How to prevent figures from floating 'into' listings [closed]

I have a problem with floats and listings. Sometimes it happens that a listing is split over two pages and when a figure is near the listing it happens that the listing starts on the first page, on ...
2
votes
1answer
206 views

empty page afterpage listings

I get an emptypage on multi page listings if I use listings with afterpage. \documentclass{scrartcl} \usepackage{listings} \usepackage{afterpage} \begin{document} \afterpage{% %some fancy stuff } ...
2
votes
1answer
386 views

How to add a keyword with a blank space in Listings package? [duplicate]

I am trying to define a listing style in order to have fortran source codes which look like vim style colors. For example, I would like to give a specific color to end program or end module or ...
2
votes
0answers
103 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 ...
2
votes
1answer
445 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 ...
2
votes
3answers
2k views

Any ideas why this \newcommand{\n}{\lstinline|\n|} macro doesn't work?

So I created a new macro \newcommand{\n}{\lstinline|\n|} but for some reason when I use it, all I get is bold 'n' letter and not a nice \n. Any ideas?
2
votes
1answer
442 views

Multipages side by side listings

Could you tell me what should I do to be able to insert multipages, side by side listings in Latex document? I have already tried with \begin{minipage}, but it doesn't work with multipages. EDIT: ...
1
vote
1answer
173 views

Using lstlistings in two columns

My goal is to display source code (awk, Python, R and SAS) and text (their output) side-by-side. Both are loaded from external files, and can be pretty long sometimes (pagebreaking is inevitable), the ...
1
vote
1answer
347 views

Why does pdfLaTeX fail when I try to use `begin{lstlisting}` inside a user-defined environment?

I'm having trouble with the listings package. I can't compile the following minimal example through pdfLaTeX: \documentclass[a4paper, 11pt, twoside, openright, english]{memoir} \usepackage{listings} ...
36
votes
4answers
2k views

Has the time come for a LaTeX3 successor to 'listings'?

I'm currently looking for a nice and challenging open-source project to work/collaborate on after my thesis. I don't have a Comp. Sci. background, but I'd like to learn more about compiler ...
30
votes
1answer
371 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 ...
15
votes
2answers
6k 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, ...
15
votes
3answers
3k views

Preferred method for inline code samples

I tend to use the minted package for including code samples within my documents, which produces very nice output. However, because Pygments always produces a verbatim environment there's no way to ...
12
votes
2answers
401 views

Combine minted and tcolorbox

I have the idea to combine minted with tcolorbox. At first, I have created my own minted environments: \newminted[mycsharp]{csharp}{tabsize=2,fontsize=\footnotesize} ...
6
votes
1answer
477 views

How to Format C Program Code Block Nicely

I am using the following settings to format my code blocks: % xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet STARTS xxxxxxxxxxxxxxxxxxxxxx \lstset{ language=C, % choose the language of ...
6
votes
2answers
2k views

Create a \lstnewenvironment that creates named listings

I am using the \lstnewenvironment to format a set of code listings in my document. \lstnewenvironment{code} {\lstset{language=haskell, basicstyle=\small\ttfamily, numbers=left, ...
21
votes
2answers
1k 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 ]; ...
17
votes
2answers
253 views

How can I redefine my macro to accept a charcode instead of a character?

I recently posted this answer to How to highlight all words of the form [0-9][A-Za-z0-9]* immediately following an equal sign?. It works, but it suffers from (a lot) of code duplication. What I have ...
15
votes
1answer
135 views

How to strip a listing of all (line and block) comments without leaving white space?

I'm looking for an easy and robust way to strip all the comments from a listing. My approach (passing \@gobble to the commentstyle key) correctly removes all the one-line comments and block comments. ...
10
votes
2answers
155 views

Maintainable typesetting of placeholders in code snippets

I'm looking for a maintainable way of typesetting placeholders in code snippets. In my listings, I would like that anything contained between the two delimiters @< and >@ be typeset in ...
10
votes
2answers
540 views

tcolorbox - list of listings?

In a book with figures, tables and listings, I figured out that all listings and some tables and figures look better when presented in a tcolorbox. The book has the usual tables of contents: ...
8
votes
2answers
441 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
2answers
316 views

How to deal with very long lstinline-phrases like long class names?

According to this Question: listing: How to deal with very long lines that do not contain spaces? My problem is that my \lstinline-phrases does not contain any special character like "-". In my ...
6
votes
2answers
1k views

Copy-pasting leading whitespace and blank lines in listings package (pdf) [duplicate]

I'm trying to use the listings package to typeset some code in a PDF document, in a way that allows me to copy-paste the resulting code. This mostly works well, if ...
4
votes
1answer
878 views

Code listing in subfigure

I am trying to use the subfigure package of LaTeX to display a code listing. Here was my first attempt: \begin{figure} \subfigure[Standard approach]{ {\footnotesize \begin{verbatim} var caps = new ...
3
votes
1answer
286 views

Background images for code listings in beamer

I asked this question originally in attempt to get background images behind my code listings. Background images for code listings What I did not mention is that I am using the beamer package for ...
13
votes
1answer
190 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}{ ...
11
votes
3answers
572 views

Why can't I use \newfloat more than once?

I've found the float package, which lets me specify \newfloat{program}{...} to get other named floats than Table and Figure. However, if I try to use this more than once, I get a cryptic error: ! You ...
9
votes
1answer
437 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} ...
9
votes
3answers
2k 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} ...
9
votes
2answers
3k 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
3answers
4k views

How to put C++ source code into beamer slides [duplicate]

Possible Duplicate: How display LaTeX code in LaTeX document? How do I fit java style source code in one frame in beamer? How do I add C++ formatted and coloured source code to my beamer ...
8
votes
1answer
772 views

Emphasize word beginning with uppercase letters in code with lstlisting package

Hi I am using the lstlisting package to format my Prolog code within my tex file. In Prolog all variables begin with an uppercase letter. I would like to emphasize them. Is there a way to for example ...
8
votes
2answers
4k views

How to align source code produced by listings package with main paragraph text

I'm using the latex listings package for the first time to format some HTML. I'm noticing that by default, the html code is being pushed further left than the main paragraph text of my document. Is ...
7
votes
1answer
785 views

Source Code Margin Comments

In the paper "Beautiful Code Compelling Evidence", by J.R. Heard -- Code is formated in a particular way which includes margin comments. I am looking for a way to do this as I think it is a very clear ...
7
votes
1answer
2k views

How to define a new environment with a fancy box (tikz) around sample source-code (listings)?

This is what I want to do: \documentclass{beamer} \begin{document} \begin{frame}[fragile]{Frame 1} Some \structure{Python} code here: % I want to define a new "pythoncode" environment, so ...
6
votes
1answer
877 views

Problems with the lstlisting environment (margin and white line)

Consider the following example: \documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{columns=fullflexible, ...
6
votes
1answer
4k views

First line number in lstinputlisting environment

I use the following code to display line 23-45 of sort.cpp: \lstinputlisting[language=C++,linerange=23-45]{sort.cpp} However, the line numbering starts with 1 while I want it start at 23. I found ...
6
votes
3answers
3k views

LaTeX beamer: Code listings in notes

How can I add a code listing to a beamer note slide? I tried the following which doesn't work: \note{{\tiny{This is a note \begin{lstlisting} foo bar \end{lstlisting}}} Any ...
5
votes
1answer
538 views

Remove\begin{Schunk} \begin{Sinput}

I am using Sweave to produce my tex. In addition I use lstlisting to highlight the source code as below. \begin{lstlisting}[caption={Computation $\widehat Y_4$ and its ...
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: ...