{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

7
votes
1answer
122 views

How can I color braces in showexpl?

I want to use showexpl and have the LaTeX code printed with colored braces. I can do this within a lstlisting environment by adding a literate option like in the example below, but not within a ...
3
votes
1answer
83 views

How can I automatically include all source code files located in a given directory?

Is there a way to include all files in a directory and all sub directories in a report as a code appendix using the listings package? I know I can include each individual file using the listings ...
1
vote
1answer
55 views

Optional caption in listings (for listoflistings)

I have some cites in my captions. But I do not want to appear them in the table of figures or listings. With figures I managed to display an different caption like this: \begin{figure} \centering ...
4
votes
1answer
46 views

lstlisting directly after section start removes margin before next section

If I place an lstlisting directly after the start of a (sub)section, the margin before the following (sub)section (title) disappears. Here is a an example document showing the issue: ...
4
votes
2answers
116 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 ...
6
votes
1answer
87 views

Problem with listings when using line numbers, `name`, and `beamer` overlays

It's is well known that to ensure that a certain <counter> is automatically reset on subsequent slides of a same frame one has to use either \resetcounteronoverlays{<counter>} (for LaTeX ...
3
votes
0answers
64 views

Unicode and listings - still no luck

Although there are already some discussions on this issue, I can't get any of the proposed solutions to work for me. Take this document and compile it with xelatex: ...
2
votes
1answer
82 views

How can I highlight a freestanding regexp in string style?

I'm using listings to format a piece of JavaScript code, and I met a problem for the following code: ... regex = /abc/; ... ratio = 1.0/2.0; ... I want the regex is highlighted as a string, but if ...
4
votes
1answer
172 views

tikzmark, listings and beamer's onlyenv

I found this limitation in the current tikzmark solution for highlighting lines of listings code in beamer. When I put the whole lot in an onlyenv environment, it seems the marks are not set, or ...
1
vote
1answer
108 views

How can I nicely typeset this MySql query with the listings package?

I am trying to show output of MySql explain in my LaTeX document. I am using listings package to make listings. Sample LaTeX code: \begin{lstlisting}[language=SQL,caption={SQL query explained}] ...
18
votes
2answers
329 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 ...
2
votes
1answer
531 views

Lstlisting in beamer presentation

I would like to insert a source code listing into my beamer presentation. I learnt that we cannot use lstlisting directly in the frame environment, so I am using the following trick: ...
4
votes
3answers
223 views

How to get listings 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
113 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
58 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
51 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
49 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
70 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
104 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
26 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
75 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
35 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
231 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
140 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
25 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
69 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
111 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
106 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
22 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
0answers
93 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
120 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
176 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
63 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
89 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
214 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
37 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
337 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
77 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
83 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 ...
7
votes
1answer
210 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
53 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
218 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
93 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
110 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
211 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
163 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
128 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
157 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
175 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
124 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 ...