{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

0
votes
0answers
23 views

Force page break within lstlisting

How to force a page break within lstlisting? My listing contains two code examples and LaTeX added the page break immediately after the first line of the second code example, however, I want it to ...
4
votes
0answers
29 views

How can I move floats that aren't tables or figures to the end of a document (endfloat for listings)?

I use endfloat to move all figures and tables to the end of my document. I want to apply the same to other floats that I have in my document, for example listing environments. Is there some hack that ...
2
votes
1answer
41 views

Coloring ) in listing [duplicate]

I'm trying to create a style using for coloring \ and brackets in code sample (PStricks) using the listings package; I tried using the answer given by Marco Daniel in this question using literate for ...
5
votes
1answer
53 views

Why are my custom settings for listings not taken into account?

I would like some help to get my source code to look correct. The code is supposed to look like this: As you can see, some words should be purple and bold, some should just be bold, some should be ...
2
votes
1answer
34 views

Cannot use a different directory for lstinputlisting

I'm having a bit of a problem. I'm trying to include source code in an appendix in latex. I use the following line in order to add the source code: ...
11
votes
2answers
139 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 ...
2
votes
1answer
72 views

How can I change the syntax of showexpl's graphic key?

I'm trying to rewrite the option graphic from showexpl package, I have reviewed the source code showexpl.sty but, fail to find the modification, the package use keyval (or xkeyval) and listings for ...
1
vote
0answers
31 views

how to insert comment in lstlisting [duplicate]

I have a problem with inserting a comment in lstlisting environment. LaTeX says: ! Package inputenc Error: Unicode char \u8:�\expandafter not set up for use with LaTeX. See the inputenc ...
2
votes
1answer
50 views

How can I define a custom class of keywords in listings?

How can I define a custom class of keywords in listings? In the C# listing below, keywords, such as using, namespace, etc., get highlighted as desired. However, I would like to define a custom class ...
8
votes
2answers
89 views

Bottom frame of listing appears on top of the next page

As the title says. I use, among other things, the following in my lstset: framerule=1pt, frame=tblr Some places a page break happens in the middle of my \lstlisting. Fine. But sometimes the whole ...
5
votes
0answers
29 views

How can I replicate verbatim's letter spacing in listings? [duplicate]

I was trying to imitate the code listings in the book Mathematical Recipes in C, I understand that it uses the CM TT font. What I am interested is in the proportion between the text and the code, and ...
3
votes
2answers
55 views

Inline listings crash when argument ends in “Error” under the Python language

Well, this is honestly the strangest thing I've ever seen concerning LaTeX. A friend of mine encountered what I can only describe as a bug in listings; can it be resolved? See the minimal example ...
3
votes
1answer
32 views

Color of comments affects frame color in listings [duplicate]

I use listings package with single frame around it, when i place long comments in my code color of comments affects frame color. Frame around lines with comments are green. I want frame to be black, ...
3
votes
1answer
40 views

tabular and lstlistings - When importing code in column 2, paragraph in column 1 moves down

A problem surfaces when formatting my ten-page long document and I'm going to try to post all the code that relates to the issue, but know that I'm fairly new to LaTeX so I may not realise some parts ...
6
votes
2answers
196 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?
4
votes
1answer
41 views

Restatable example containing code listing

I am creating a beamer presentation, and I'm using the packages thmtools, thm-restate and listings. Inside one of my \frames, I want to create an example block containing a code listing. Later, I want ...
6
votes
1answer
52 views

Can listings automatically indent code? [duplicate]

\documentclass[11pt,a4paper] {article} %\usepackage{fontspec} \usepackage{listings} \usepackage{xcolor} %\setmainfont[BoldFont=黑体]{宋体} %\XeTeXlinebreaklocale "zh" %\XeTeXlinebreakskip = 0pt plus 1pt ...
3
votes
1answer
45 views

Problems with spacing in lstlisting with escaped code

Consider the following code: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[fragile]{title} \begin{lstlisting}[escapeinside={!*}{*!},] int add int !*\color{red}add*! ...
4
votes
1answer
45 views

How can I fix AucTeX's syntax highlighting for the lstlisting environment when using optional arguments?

The title really says it all, so I'll provide an example and a screenshot: \documentclass{article} \usepackage{listings} \begin{document} For example, if we wished to create a predicate to ...
2
votes
2answers
46 views

XeTeX \color runaway argument

\documentclass[11pt,a4paper] {article} %\usepackage{fontspec} \usepackage{listings} \usepackage{xcolor} %\setmainfont[BoldFont=黑体]{宋体} %\XeTeXlinebreaklocale "zh" %\XeTeXlinebreakskip = 0pt plus 1pt ...
4
votes
2answers
50 views

Intersection of equation with code frame in listings package

I used the listings package with single frame and I had an equation before my code. The problem is that the frame intersects a little with the equation and the output is ugly. This happens both when I ...
3
votes
1answer
44 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 ...
10
votes
2answers
179 views

Lua syntax for the listings package

I'm preparing some slides with Beamer and I've just discovered that the listings package, which otherwise does exactly what I want, is missing the syntax for the Lua language. How can I configure ...
2
votes
1answer
45 views

Listings float with sublistings

I want to have 2 listings side-by-side in a float environment with its own name (i.e. Listing 1 instead of Figure 1) and counter (so that I can have a separate listoflistings besides listoffigures). I ...
2
votes
1answer
51 views

Getting error while using top, and right braces in a listing

I am showing right and top braces, whereas while attempting to add overbraces using a new function called 'AddNoteOver', I am getting this error: "Package tikz Error: + or - expected ...
4
votes
2answers
113 views

Making an unfilled circle including a number in a table

I wonder is it possible to highlight a number enclosing with an unfilled circle next to a line in a listing or table like the image below? \documentclass[english,a4paper,12pt]{report} ...
4
votes
2answers
99 views

Missing \endgroup inserted error in a table

I am getting 'Missing \endgroup inserted morekeywords={class,run}]' on line 16 while running the tex. I am using TexStudio. How can I solve that problem? \documentclass{article} ...
4
votes
2answers
76 views

Showing two listings in a table side-by-side [duplicate]

I wonder is there any possibility to show two different listings in one table side by side? Here is my code that only show one listening but how can I embed it in a table and another one? EDIT: Even ...
6
votes
1answer
33 views

Broken line between line numbers and code in lstinputlisting with setstretch<1

If I use \setspace{0.8} to tighten up my listings* I get a broken line between the line numbers and the code. \documentclass{article} \usepackage{listings} \usepackage{setspace} ...
5
votes
1answer
67 views

Problem with hyphens in listings

The problem is that in the inline listing "ABC-ABC" the hyphen disappears. It works if I remove the literate=... parameter but I need it because I want to wrap around long inline code by specifying ...
6
votes
1answer
60 views

How can I use the lstsample environment (lstdoc package) in article?

I would like to try the lstsample environment from the lstdoc package, distributed with the listings package. For that I have written the following document: \documentclass{article} ...
2
votes
0answers
59 views

How can I apply different custom caption styles to different listings?

In the MWE below, is it possible to define different caption formats for the two listings? In the example the first listing should use a blue caption background (like it is now) while the second ...
1
vote
1answer
48 views

Listings: increase internal margin between caption (top) and listing?

With the MWE below (adapted from here), how do I increase the internal margin in the listing so that instead of looking like this: It looks like this (note the gray background has been "stretched" ...
2
votes
1answer
46 views

Source code customization for specific words?

I'd like to highlight some specific words for HTML5 code manually in LaTeX. In other words, I don't want to define an exact structure for highlighting the language, but do the highlights only for the ...
1
vote
1answer
35 views

Horizontal and vertical alignment of an element to the centre of a whole page

I am trying to place a code frame generated with listings package in the middle of a page both horizontal and vertical. How can I do it? Edit I: My code is this: \documentclass[12pt]{article} ...
8
votes
1answer
78 views

Is there an equivalent to \graphicspath for listings?

How can I make the \lstinputlisting to search for files in a given directory? I'm thinking of a solution along the lines of the solution to this question. I would like to have a solution like ...
1
vote
1answer
50 views

code-like strings with background color, and using tabular environment

I am going to create the following code-like strings with latex, with same background (gray), font, etc. How can I do this? I used listings package but inside \begin{lstlisting}...\end{lstlisting} ...
9
votes
1answer
135 views

How do I get rid of the extra blank line at the end of my listing?

I have the problem that I use a lstlisting inside an itemize. This leads to the problem of an extra line in my source code block which I'm not able to delete. I already tried nearly every parameter ...
1
vote
1answer
41 views

insert Maple code in comment with mathmode create with tcolorbox package

see this code: \documentclass[svgnames,12pt]{report} \usepackage{amsmath,amsfonts,amssymb,amsthm} \usepackage{tcolorbox} \tcbuselibrary{listings,skins,theorems} \lstdefinelanguage{Maple}% ...
5
votes
2answers
50 views

Back accent or grave accent in listings

I'm using listings to display a bash script like for instance $ export MY_ENV=`pwd` How can I make listing display the correct character for `. Right now it is displaying ' MWE: ...
4
votes
0answers
24 views

Listings: highlighting key-value file? [duplicate]

Say I have the following key-value file I want to highlight using the listings package: some.key=Some value I want the key to be red, the equal sign to be black and the value to be blue. How do I ...
2
votes
1answer
34 views

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about ...
14
votes
1answer
247 views

Can the listings package automatically indent source code?

The listings package automatically highlights keywords in source code and makes it look nice. Is it possible to automatically indent the program? For example, in listings, if the following code is ...
13
votes
1answer
143 views

Tabs vs spaces in listings: what's the difference and should I care?

This is a follow-up question to Problem with Listings package concerning line breaking and wrong alignment. Why do I experience problems when I copy and paste code inside the lstlisting environment? ...
2
votes
0answers
55 views

Problem with Listings package concerning line breaking and wrong alignment [duplicate]

Hello I have the following code: \documentclass[12pt]{article} \usepackage[top=0.3in, bottom=1.5in, left=0.8in, right=0.8in]{geometry} \usepackage[utf8]{inputenc} \usepackage{setspace} ...
7
votes
1answer
100 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
62 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
42 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
31 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
79 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 ...