{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
3answers
144 views

How to get listing to print only the header of a Matlab file?

How to extract the first line of a simple matlab file and the following lines just after that begin with the character % ? The number of lines to extract is unknown. Then I want to use listingsutf8 to ...
4
votes
1answer
94 views

lstlistings works strangely

I have some Java source code and want to display it in LaTex: \lstset{language=Java} \begin{lstlisting} IntentFileter intentfilter = new IntentFilter(); ...
4
votes
1answer
41 views

Listings and Babel (with some languages) are breaking hyphenation

In the following document \documentclass{article} %\usepackage[german]{babel} % also try english, ngerman and dutch \usepackage{listings} \begin{document} \thispagestyle{empty} \begin{minipage}{1em} ...
5
votes
1answer
48 views

How do I maintain structure in structured output?

I am trying to ensure output from a Linux command - which looks like: Into a LaTeX document with the same column structure with the output headers lined up with the output sections on the next ...
2
votes
1answer
32 views

Splitting a code listing inside a longtable

Is there a way to have code listings split across multiple pages when included inside a longtable? For example, the following code: \documentclass{article} \usepackage{listings} ...
0
votes
0answers
50 views

Don't break lines at certain characters in lstlisting

Is it possible to configure lstlisting such that it doesn't break lines at certain characters? In this example, a line break is inserted after the opening parenthesis: public void someMethod( ...
5
votes
2answers
82 views

Best way to deal with overfull inline listings

I am typesetting inline code listings using the listings package. Since I'm using C# syntax, oftentimes listings contain long words (type names/variable names). Since words in listings won't be ...
1
vote
0answers
25 views

Line breaks in inline listing + correct emphasiation?

I want to have both code snippets ABC and ABC_DEF in red (in both cases only ABC is red). If I remove the literate line it works but I also want to have automatic line breaks at underlines. How can I ...
3
votes
1answer
62 views

Escape comment syntax in strings with listings

Consider the following: \documentclass{standalone} \usepackage{listings} \lstset{ language=Python, morecomment=[s]{<<}{>>}, } \begin{document} \begin{lstlisting} def expand(): ...
1
vote
1answer
19 views

How can I have a hyphenated XML tag in a listing?

Consider the following valid XML according to http://stackoverflow.com/a/1478623/1443496? \documentclass{article} \usepackage{listings} \lstset{ language=xml, morekeywords=some-tag, } ...
5
votes
2answers
117 views

Manually break lines like auto-breaking in lstlisting

I would like to decide where the long line should break, but with actions pre-/postbreak and without advancing in line numbering. I've tried that one: \documentclass{article} \usepackage{color, ...
4
votes
1answer
66 views

Final linebreak in lstlisting, and linebreak in captions (with IEEEtran)

Using: lstlisting in two columns How to add line break to caption without using caption package ... I got to the following MWE: % \documentclass[12pt,a4paper]{article} ...
1
vote
0answers
23 views

Using mcode within a beamer frame [duplicate]

I have a presentation that I would like to include some matlab code in. For that purpose I have included the mcode package, that basically configures the listings package. My problem is that the ...
1
vote
0answers
56 views

listings frame for multiple page code [closed]

My code is really long. And I really want to use the frame Shadowbox in my code. But the problem is since it is going over a single page, the box is actually completing at the end of the code ...
5
votes
2answers
75 views

How can I 'set off' a \lstinline portion of text?

See the question below: \documentclass{article} \usepackage{listings} \begin{document} Here is some text where I would like to talk about a particular variable called \lstinline|var|. How can I ...
4
votes
1answer
88 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 ...
0
votes
0answers
20 views

\lstinline does not work with \frame in beamer [duplicate]

\documentclass{beamer} \usepackage{listings} \lstset{ basicstyle=\ttfamily\footnotesize, breaklines=true } \begin{document} \begin{frame} Normal text \lstinline{\usepackage} \end{frame} \end{document} ...
2
votes
1answer
75 views

Inserting MATLAB files with a lot of lines [closed]

I have a few MATLAB files with over 100 lines of code but when I use \lstinputlisting, I only get about the first 50 lines or so and it doesn't show up on the next page. Presumably, it's floating away ...
6
votes
1answer
62 views

How to rename \cref{} for lstlisting

At the moment I'm working on my Diploma thesis and after a long time of searching and trying, I still can't find a solution for my problem. Long story short: I want to refer to a ...
4
votes
3answers
80 views

How to left align lstlisting code with text

I'm using listings package to include sample code to my document and the frame option to surround the code inside a box. The problem is that I got too much white space between the left rule of the ...
2
votes
1answer
49 views

inline code listing runs into right margin

I am trying to typeset an inline C# code listing using the listings package. However, the chunk of inline code spans a few lines, so listings has to insert a coupe of line breaks into my code. So far, ...
1
vote
1answer
73 views

Why is lstlisting splitting my XML tags?

I have a little problem with this ambient. I have some XML to insert into my document and the thing that really bugs me is that the new line breaks a closing tag in two. I indicated to the environment ...
5
votes
1answer
124 views

Fixing vertical spacing after \captionof as a custom caption

I'm trying to get a single caption after two columns of code. For two columns, parcolumns is the only method I've found that allows a page break in the middle and is my current favorite. Using ...
2
votes
0answers
30 views

Page could not be rendered error while viewing YAP using listings package [closed]

I cannot view the DVI output in YAP, as it shows the below error (The page could not be rendered) if I use the listings package. Could any one suggest me how to solve this error?
10
votes
2answers
298 views

Rounded corner for the code listing

Is it possible to make a rounded corner for the tex code listing? Given: \documentclass[10pt]{article} \usepackage[usenames,dvipsnames]{xcolor} %used for font color \usepackage[utf8]{inputenc} ...
2
votes
1answer
69 views

display both an image and a code, side-by-side

I'd like to display both an image and a code using pdflatex, side-by-side to illustrate a concept. The code uses listing package. How could I do that ?
6
votes
1answer
61 views

Listings rule breaking into pieces when using xleftmargin=3pt,xrightmargin=3pt

I'm using the below coding in a Tex file and when I view the DVI output the frame rule for listings gets breakdown (please look into the screenshot below) Could some one help me in solving this ...
6
votes
1answer
111 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 ...
3
votes
1answer
39 views

Subimport star breaks listings languages

\subimport*{}{} from the package import seems to break listings languages, but only if listings with a language hasn't been used in the root document: ! Package Listings Error: Couldn't load ...
4
votes
1answer
157 views

Can the listings package be set up to highlight Prolog code like minted does?

I am interested to know how listings can be customized to mimic the Pygments's Prolog lexer (i.e. make Prolog code represented by listings look the same as it is done with minted) I previously asked ...
4
votes
1answer
77 views

Listing removing horizontal lines and autocrop to the size of code fragment

I am trying to include the code in my presentation. There are two things that I need to fix: there are horizontal lines appearing between the code lines I do not want to use the entire page, need to ...
4
votes
2answers
77 views

How to make a minted code listing centered on a page?

So, I am writing a report with Prolog code listings in it. I have been using lstlisting to make my listings and I made my code centered on the page, such as this: \renewcommand{\figurename}{Listing} ...
5
votes
2answers
142 views

graphic in tcblisting

I'm using the package tcolorbox to create a file with examples Latex, I have reviewed the options tcblisting environment and use these: text outside listing listing outside text listing above text ...
8
votes
0answers
117 views

Why should \lst@definelanguage be preferred over \lstdefinelanguage in a style file? [closed]

The listings manual (v1.5b, subsection 4.18) recommends using \lst@definelanguage instead of \lstdefinelanguage in a style file: Where should I put my language definition? If you need the language ...
4
votes
2answers
104 views

How can I reverse the caption numbering in listing

How can I make a reverse numbered caption with listings? So the package makes ''Listing 1.1'' style captions but I need it in form ''1.1 Listing'' .
6
votes
2answers
109 views

Use listings with different languages in same code block

My goal is to have a somewhat large verbatim block and use listings to give syntax highlighting to only particular parts. Here's a toy example: \begin{verbatim} How to include files in: C: ...
6
votes
2answers
137 views

How can you highlight a C compiler directive spanning multiple lines?

In my \lstset{...} I have morecomment=[l][{\color[rgb]{0.1, 0.2, 0.8}}]{\#}, which I've seen used to give preprocessor commands colour. This works just fine but I'd like to get multi-line macros to be ...
3
votes
1answer
77 views

Code listing in subfigure using lstlisting

I am trying to use the subfigure package of LaTeX to display a piece of SQL code. The purpose is similar to Code listing in subfigure, but I'd like syntax highlighting using lstlisting environment ...
2
votes
0answers
37 views

penalize page breaks in \lstlistings

I have a document with some rather lengthy \lstlisting's (source code snippets). It looks really bad if there is a page break within a listing/snippet. Thus I tried to avoid page breaks in listings by ...
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. ...
2
votes
1answer
91 views

Rendering VHDL in latex

I have a VHDL code which I want to insert into my latex document. I need a package that takes care of syntax highlighting, indentation etc. Is there a package which serves this purpose?
0
votes
1answer
134 views

including python code in beamer? [closed]

Suppose I have a python file. How can I include in beamer presentation in one of the slides? \insertcode{"Scripts/mc.py"}{Python} does not work with \usepackage{listings} , which otherwise work in ...
8
votes
3answers
199 views

Listing background broken by \colorbox and \framebox

I am using listing environment (listings package) with the background parameter. I want to highlight some lines of code and I am using the \colorbox, \makebox and \framebox to achieve this. However, a ...
3
votes
1answer
209 views

Package hyperref Warning: Token not allowed in a PDF string [duplicate]

My document contains section titles that are formatted by the listings package. (The section names are names of configure script switches.) ...
8
votes
1answer
119 views

Different colors for default and language-specific listings

I'm generating pdf documents using knitr and pandoc. The conversion is mostly automated from R markdown -> markdown -> latex -> pdf. However, my documents combine R source code and its output, and I ...
9
votes
2answers
188 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 ...
8
votes
1answer
170 views

How can I automatically highlight SuperCollider symbols and environment variables?

I've been poring over the listings manual, trying to figure out how to get some very specific types of formatting for the SuperCollider language. I need to highlight words where the opening delimiter ...
6
votes
1answer
91 views

How can I test the first character on each line of a listing?

The listings package defines a hook called EveryLine to allow users to execute TeX code at the beginning of each line of a listing; the following is taken directly from the listings source code ...
2
votes
1answer
41 views

Listings on multiple pages - keep number like Continuedfloat

I have the following code: { \lstset{language=C, basicstyle=\tiny, tabsize=3, frame=lines, breaklines=true, breakatwhitespace=true} ...
5
votes
1answer
77 views

What's up with the tag key?

Subsection 4.18 of the current listings documentation (2013/08/26 Version 1.5b) describes a key called tag. That key is used in lstdrvrs.dtx, which is a file that ships with listings and takes care of ...