{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

9
votes
3answers
418 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 ...
4
votes
1answer
575 views

lstlisting produces empty row when used inside a tabular

Is there any way I can get rid of the empty new row produced by lstlisting inside a tabular? Here's a minimum working example: \documentclass[11pt]{article} \usepackage{listings} \lstset{ ...
11
votes
2answers
2k views

How to automatically include command line session output in documents?

When I write documents that contain source code examples and snippets the listings package is a great solution to include such things. Especially with the \lstinputlisting command and ...
0
votes
1answer
380 views

Highlighting line ranges in listings

I've put here one adaptation for "no-beamer" documents of this code. Thanks a lot for the indications given below by Daniel. % Sources : % 1) ...
11
votes
2answers
1k views

How to align comments with lstlistings?

I am using listings with these settings: \lstset{language=C++,basicstyle=\small\sffamily, numbers=none, frame=tb, columns=fullflexible, showstringspaces=false } I like the proportionally ...
4
votes
2answers
4k views

\lstinputlisting will not continue to next page

So I have this LaTeX snippet: \section{Appendix} \listoffigures ... \begin{center} \begin{figure} \caption{MacroCell with 8 AND Gate Arrays} ...
9
votes
2answers
267 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 ...
3
votes
1answer
946 views

Way to present programming code side by side to show the differences to the reader?

I am trying to make a side by side comparison of the result of listing-mode and minted-mode for a piece of Ruby and Java-code. I have problems making this look 'side by side'. Any suggestions to make ...
9
votes
1answer
775 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
6
votes
1answer
891 views

How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets?

How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets? E.g. using \bh and \eh commands from Highlight text in code listing while also keeping syntax ...
2
votes
1answer
206 views

Listings, problem with rendering embedded strings

this is my style defined for C#: \lstdefinestyle{CSharp}{ language=[Sharp]C ,captionpos=b ,columns=fixed ,morekeywords={var,get,set} ,basicstyle=\footnotesize\ttfamily ...
0
votes
1answer
310 views

listings package - including textfile - tabstops wrong [closed]

In MikTex with \usepackage{listings}, when including a textfile into a pdf-document using \lstinputlisting[]{textfile.xt} then ocassionally, the display of the tabstops in the created pdf-file ...
0
votes
1answer
395 views

Display FASTA File in LaTeX [closed]

Is there a proper way to show a FASTA file in LaTeX? So far I tried $'s or listings and TeXshade but this does not seems to work.
8
votes
1answer
8k views

Listings package for C#

I intend to use the package listings for including C# code in a LaTeX document. There are a lot of languages supported by this package, but C# lacks at all. Is there an extension for adding support ...
6
votes
1answer
2k views

In listings, how to show referenced linenumbers instead of standard ascending linenumbers

I'm just writing on my master thesis and have a (specific) problem with lstlisting package in LaTeX. I'm referring to the Random.class-file in Java and only want to print some specific line-ranges, ...
4
votes
1answer
773 views

How to avoid background / frame break in code listings with math / mathescape?

I have lots of C++ sources with LaTeX formulas in the comments. Ideal for using the listings packages to pretty print the source. However, most of the formulas break either, the background or the ...
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 ...
13
votes
5answers
3k views

How can I properly align the line numbers of a source code listing with the margin?

I want to include a code snippet in a document using the listings package. In my document, I have the following: \begin{figure}[!htbp] \setlength{\fboxsep}{0pt}% \setlength{\fboxrule}{0pt}% ...
15
votes
1answer
886 views

How to make listings code correct copyable from PDF and with hyperlink

If I generate listings code with line numbers and copy the result from the PDF I can not use it again as tex code. First the line numbers are included which they should not, second spaces are included ...
6
votes
3answers
263 views

Failsafe ways of using verbatim commands

All my ideas on how to do clever things with code examples and listings results further or later in 'Emergency Stop' errors. Let me briefly review what I am doing now and what I actually wanted to ...
4
votes
2answers
700 views

Why can lstlisting not be saved in a command?

This code fails with Emergency stop: \documentclass{scrbook} \usepackage{listings} \newcommand{\demo}{% \begin{lstlisting} foobar \end{lstlisting} } \begin{document} \demo \end{document} Why?
4
votes
1answer
829 views

\newenvironment fails with special listings environment

I want to use the showexpl, but define a new environment with predefined settings. But all I get is an emergency stop. \documentclass{scrbook} \RequirePackage{showexpl} ...
1
vote
1answer
685 views

Code fails with Emergency stop, when using \expandafter\csname and such in listings

I am further working on my code for LaTeX Examples. I want to use the package showexpl for the simultaneus printing of code and results. Unfortunately I get an '! Emergency stop.' ...
3
votes
1answer
306 views

\stepcounter increments by two, when used with listings [closed]

Users, my counter usually gets incremented by 1, when I use \stepcounter{mycounter} But surprisingly, it gets incremented by 2, when I use it together with listings: \lstinputlisting[ ...
4
votes
2answers
3k views

Table of code listings

I'm using the listings package to put a box around some source code in a document and also to provide some syntax hilighting. Is there an easy way that I could create a table of contents which just ...
6
votes
2answers
4k views

Is there a way to enable syntax highlighting coloring in Lyx for program listings?

I want to embed a small program listing and have used Insert -> Program Listing in LyX's menu for that. The settings dialog supports selecting a language (Java), but I can't actually see any ...
4
votes
2answers
1k views

Undesirable highlighting of a keyword name (dh) occuring within an identifier (0dh)

I'm using the x86masm dialect of Assembler and register names are emphasized even when they occur inside of a label or a hexadecimal number. For example, dh is register, but 0dh is a number, yet the ...
4
votes
1answer
202 views

How to change appearance of a particular line when using \lstincludelisting?

I'm using the listings package and include code into my document through \lstincludelistings. The problem is that I want to set some code lines to bold to indicate changes from previous code segments. ...
7
votes
1answer
2k views

Figure breaks listing, how to avoid that?

I have a listing in my document and some lines before it I'm inserting a figure, doing the following: \begin{figure}[htbp] \begin{center} \includegraphics[scale=0.7]{filename.png} \caption{Caption} ...
1
vote
1answer
866 views

LaTeX - Multiple pages on a code listing inside a beamer frame

I'm trying to put some Python code on a beamer slide. I would like to take one big file and print it with lstinputlisting. I've tried to set the frame fragile with: \begin{frame} [fragile] ...
22
votes
2answers
10k views

Extend a language with additional keywords?

I'm using listings and I want to extend a language with additional keywords for highlightning. I know there is an option morekeywords available, but that only works for a particular lstset declaration ...
4
votes
2answers
483 views

listings: framebox shows breaks in font

Using the listings package in LaTeX seems to put lines in the frame box. This happens for all frame box options and if I use a shadow box it is even more apparent... Is there any way I can stop this ...
15
votes
2answers
2k views

Colored background in inline listings

I would like to make inline code more distinguishable from the text surrounding it, and I thought that using a background might work (like it is done on the stackexchange pages.) Since I use the ...
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 ...
5
votes
2answers
1k views

Background overflows when using rounded corners for listings (package: `listings`)

I'm using listings to list code in my document, and I want the code to be displayed in a frame with rounded corners and a grey background color. But the background overflows the frame, as if the frame ...
16
votes
5answers
11k views

Using bold/italic text inside listings?

How can I use bold text inside a code listing? I wanted to make some parts of the code bold.
7
votes
2answers
303 views

How to emphasize within a listing two successive identifiers separated by a space?

I have this pgfplots code that I want to put in a lstlisting environment: \pgfplotsset{ every axis x label/.append style = { font = \small }, every axis y label/.append style = { ...
4
votes
3answers
2k views

Customizing the list of listings generated by \lstlistoflistings?

I'm using listings in my document, and its command \lstlistoflistings to generate the list of listings. The problem is that I've customized all the other lists (TOC, LOF and LOT). More precisely, I've ...
1
vote
1answer
374 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} ...
5
votes
1answer
343 views

Listing index uses wrong dashes

When generating an index of all my Listings, the library seems to use the wrong dashes to connect words: Expected Unported-2.0-Graphic Actual Unported—2.0—Graphic In the title of the listings, ...
3
votes
3answers
420 views

How to emphasize with in a listing an identifier containing a digit?

I have this LaTeX code that I want to typeset using listings: \documentclass[paper=a4,fontsize=12pt,version=last]{scrlttr2} I want to emphasize "scrlttr2" with a different format. How can it be ...
6
votes
3answers
1k views

Smaller frame with listings

I am using listings to put java code in my beamer slides. Sometimes, I want to frame the code but I do not want the frame to occupy the whole width of the page. I want the frame to occupy only the ...
9
votes
1answer
7k views

How to create beamer slides with source code that can be copied?

We are converting our course slides from Powerpoint to LaTeX, to be able to offer all code in a more open format and to let students easily copy code from the slides. However, the latter does not seem ...
6
votes
1answer
910 views

Problems with column alignment in the `lstlisting` environment

I'm having some problems with the column alignment in the lstlisting environment provided by listings.sty. In fixed-width column alignment mode, whatever the typeface being used, listings are ...
2
votes
1answer
337 views

Why compilation with a lot of \lstinputlisting is so slow?

I'm using a lot of \lstinputlisting in my document and the compilation of it is really slow. Why it takes so long? How could I make things better?
14
votes
1answer
4k views

How can I use LaTeX-commands inside of a listing?

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the ...
7
votes
2answers
2k views

Disable keyword highlighting in lstset

I have the following lstset defined for my listings \lstset{ numbers=left, numberstyle=\scriptsize, tabsize=4, rulecolor=, language=java, ...
5
votes
2answers
3k views

How do I prevent LaTeX from showing a whitespace following a quote when in an lstlistings environment? [closed]

When I am inside the lstlistings environment, it seems that using a quote such as (') or (") will toggle on the showing of whitespace indicators (small little half rectangles). Am I doing something ...
3
votes
1answer
2k views

How to highlight own keywords in HTML lstlistings?

I would like to highlight some words in a lstlisting. The language is HTML. However, \emph seems not to be working with HTML. Any suggestions how I could work around this problem? Right now I have: ...
3
votes
1answer
2k views

Listings in table of contents

I'm struggeling a little bit with the display of table of contents. I had previously a problem using natbib , and now the same issue with listings. Maybe I'm mixing something up with documentclass ...