{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

3
votes
1answer
74 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
90 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
71 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
81 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
75 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
342 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
96 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
79 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
177 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
859 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
135 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
84 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
88 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
64 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
81 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
73 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
62 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
56 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
114 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
70 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
265 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
60 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
96 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
27 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 ...
3
votes
1answer
279 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
291 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
196 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
57 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
134 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
102 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
67 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
55 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
139 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
103 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 ...
4
votes
0answers
71 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
96 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
205 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
130 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
350 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
976 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
240 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
127 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
67 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
52 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
59 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} ...
1
vote
1answer
100 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
120 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 ...
3
votes
1answer
55 views

Line breaks inside inline code break syntax highlighting. Any workaround?

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
88 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
47 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, } ...