{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

2
votes
0answers
47 views

Listings Keyword Part of Comment [closed]

I made a homebrewed language for structured text (because I expected no language like this to be available). Now there is a comment that starts with /* and ends with */ and a line comment that starts ...
3
votes
1answer
73 views

Beamer overlay and listing conundrum

When I try to overlay the lstlisting C code with escape character (so that I can insert a \colorbox), I get the following error: ! Missing number, treated as zero. <to be read again> ...
3
votes
2answers
80 views

Listings problem with quotes in a string

A single quote occuring inside a listings string seems to be interpreted as ending the string. Is there a way to avoid this from happening? \documentclass[12pt]{article} \usepackage[top=0.3in, ...
4
votes
1answer
58 views

Pathological listings problem: tilde in \lstinline in a footnote [duplicate]

I seem to be unable to write a tilde in a \lstinline in a footnote. If you uncomment the only commented line in my minimal working example, you'll see what I mean: \documentclass{article} ...
4
votes
1answer
102 views

What, in the custom class I use, prevents line breaking in listings?

I have found how to wrap code inside lstlisting block. When my document has article class, everything works as expected. However, when I change the document's class to one I need in my work, lines do ...
2
votes
1answer
59 views

Define new language listing with comments ONLY in the beginning of a line

I am trying to create listing for a home-brew language (using \lstdefinelanguage). The problem is that the comments in the language are somewhat ambiguous. For example, the following code is valid: * ...
0
votes
1answer
71 views

Latex Listing Source shift right side?

I am using Latex listings package to add the source code in my document, but the problem is on the left side some character is missing as showing in the picture. \usepackage{listings} Source ...
4
votes
1answer
97 views

Help about tcboutputlisting and tcblisting (tcolorbox package}

When using the tcolorbox package and creating latex exercises with solutions, I have a problem of inserting tcblisting in tcboutputlisting (solution). The listing which appeared in the solution is ...
0
votes
0answers
18 views

How to get listings right with lmodern and MnSymbol? [duplicate]

How do I have to setup listings so that code can be copied with indentation and everything looks good in the pdf? I found a lot of partial answers but I wasn't able to put it all together. I manged ...
2
votes
1answer
93 views

How can I insert a thin space (\,) in a listing?

Is it possible to create small space in listing? I tried / and \, but it doesn't work in listing environment \begin{lstlisting}[caption={Inicializace ELM327.}, label={lst:initELM},captionpos=b] ...
0
votes
1answer
42 views

Strange spacing when using lstlisting

I am trying to use the lstlisting package in order to show some code in my document. However, it aligns it to the right of the page, as opposed to left as expected. \begin{lstlisting}[frame=single] ...
2
votes
0answers
62 views

\usepackage]{listings} - Overfull \box problem - Smaller characters/font?

I am using this LaTeX code to implement some Python code in my LaTeX generated pdf document. I am using \lstdefinestyle because I have multiple styles for different code that I want to implement in ...
2
votes
1answer
52 views

Listings package: including punctuation in “emph” list

I'm typesetting some examples of a system which has this sort of look: In: 2+2 Out: 4 and I'd like to emphasis the "In:" and "Out": This works: ...
4
votes
2answers
118 views

What is the least invasive way to set the font for listings?

As has been asked often enough, to get bold keywords in lstlisting environments, one has to use a different typewriter font. Most answers suggest to include this or that package. If just including a ...
4
votes
1answer
54 views

How can I mimic the output of syntax macros (\marg, \oarg, etc.) without using the ltxdoc class?

I have come to realize that the pleasant style (argument in italics, enclosed by angle brackets) of macro descriptions in numerous package documentations is actually produced by a number of special ...
0
votes
0answers
19 views

Listing causes strange vertical spaces when put it on the next page [duplicate]

I have simple document: \subsubsection{Dodanie testu} \begin{lstlisting}[caption={ComplexTest},label={lst:complex-test}] public class ComplexTest{ public testComplexAddition(){ ...
5
votes
2answers
81 views

Problem with spaces in listings package and hyphenation

I use the listings package and there is a space that is inserted when the line breaks and the code goes to that new line. Why is this space inserted in the new line? How can I remove it? ...
1
vote
1answer
47 views

Code not wrapping in listings even though breaklines=true [closed]

I read that enabling breaklines in listings will make the included code wrap, but it does not in my case. Maybe something is interfering with this function? Full code is shown below: ...
7
votes
3answers
102 views

Only get filename and extension of listing, not whole path

I am trying to add the file name as caption. I was able to do this setting caption=\lstname but this shows the full path. I am now trying to get the name of the file and extension to show only. I ...
3
votes
0answers
86 views

How do you best differentiate listings in different programming languages? [closed]

I am currently producing a new edition of an old book of mine; this new book will incorporate code samples from several different computing environments. I can using the listings package quite ...
5
votes
2answers
100 views

Compile error “Missing \endcsname inserted.” with code and tcolorbox

I get this error when trying to compile into pdf my document. It is important to know that my project did compile a month ago without errors: I opened it today and it fails without being modified at ...
1
vote
0answers
32 views

Problems using listings package and beamer [duplicate]

I'm having problems using listings package in a beamer documentclass. "! Paragraph ended before \lst@next was complete." my code: \documentclass[compress]{beamer} ... \usepackage{listings} ... ...
3
votes
1answer
36 views

Append characters after line numbers when using the `listings` package?

Is it possible to add some characters, like colons, to the line numbers when these are displayed in the listings package? There is the numberstyle option, but that only seems to affect stuff before ...
4
votes
1answer
64 views

Distorted caption in listings

The following code produces strange results. Everything looks fine, if I don't include the subfig package or don't use the xleftmargin parameter. It also works if I use captionpos=t. Is there a ...
7
votes
1answer
95 views

Hyphenation in listings captions doesn't work correctly

I have the problem that automatic hyphenation in listings caption doesn't work if automatic linebreaking is activated. It works if I set breaklines=false or captionpos=t, which is weird. Is there a ...
2
votes
2answers
79 views

Showstringspaces in inline listing not showing

I'm having trouble with showstringspaces in the listings package, setting the option to true seems to be being completely ignored. My objective is to highlight the spaces in the strings using ...
0
votes
0answers
57 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 ...
11
votes
2answers
177 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
74 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
79 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
73 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
226 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
113 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
33 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 ...
4
votes
1answer
87 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
144 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
31 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
71 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
58 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
70 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 ...
7
votes
3answers
229 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
57 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
59 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
68 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
83 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
63 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
72 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
67 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
301 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
67 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 ...