{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
2answers
588 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
110 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
61 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
80 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
62 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
78 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
63 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
61 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
48 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
104 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
67 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
226 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
53 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
84 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 ...
3
votes
1answer
190 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
271 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
189 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
56 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
127 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
90 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
61 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
48 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
121 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
89 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
65 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
86 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
177 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
113 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
334 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
605 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
225 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
119 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
61 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
51 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
73 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
107 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
76 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
36 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
245 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
159 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
73 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
117 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
109 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
130 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 ...