{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
2answers
203 views

highlight line numbers in listings

I would like to highlight the line numbers of the lines I refer to with lstlistings. I use escape characters to define labels in my Listing to which I refer later in my document (e.g. see Line X of ...
2
votes
1answer
152 views

How to include program listings in C# with custom font and syntax highlighting in LyX?

I'm rather new to LaTeX and use LyX editor to create my documents. There are similar questions but none of them answer how to do that in LyX. I am wondering, how to include a program listing in ...
3
votes
1answer
140 views

lstlisting `moredelim` doesn't work with comments

I'm trying to add some overlays to a piece of code, and I'm defining it using moredelim. However, when I use it on comments within the code, the moredelim stops working. What am I missing? ...
1
vote
1answer
56 views

error when using tcolorbox + listings for multipage source

I'm try to highlight source code with colored background, but I face a bit error. first image is created with listings only and that is what I need. You can see on the last image that basicstyle ...
1
vote
1answer
102 views

How can I highlight keywords with special characters or numbers in them?

In the following MWE the declared keywords te-st and 999 are not highlighted as expected: \documentclass{scrartcl} \usepackage{listings,xcolor} ...
3
votes
1answer
115 views

Problem with mdframed, lstlisting and subfig

I'm trying to understand why the following code does not compile. \documentclass[12pt]{article} \usepackage[svgnames]{xcolor} \usepackage{filecontents} \usepackage{tikz} ...
1
vote
1answer
123 views

lstlisting environment with UTF-8 encoding [duplicate]

I have a problem using lstlisting environment with utf8 encoding. I got this error Package inputenc Error: Unicode char \u8:�\expandafter not set up for use wit MWE \documentclass{article} ...
2
votes
2answers
2k views

How to change font size for specific lstlisting

I have a java lstlisting and it is too big and does not mach a single page. Is there any way to specify font for specific listing, not all listings in document?
3
votes
0answers
113 views

Object-oriented class typesetting? [closed]

I am looking for a way to beautifully typeset an OO class like : classname { properties: prop1 : integer prop2 : Node methods: someMethod() } With the look ...
3
votes
1answer
140 views

How can I highlight a keyword that contains a dash or a slash? [duplicate]

I have a Clojure listing and I want to colour certain keywords whereas I can only do for strings not including any dash ('-') or slash ('/). But I also need to consider keywords consisting of with ...
4
votes
0answers
132 views

Issues using listings package [closed]

I am using LaTeX to write my internship report (I started to learn it one month ago), and I have some issues using the package listings. I'm not sure if everything is possible: How can I add a ...
4
votes
1answer
115 views

after change \lstset, reset of normal characters can NOT display

I met one problem(maybe three, I will describe them in detail), I'm trying to add code list in latex with listings package. First with limit configuration: \usepackage{listings} ...
5
votes
1answer
96 views

Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX? ...
2
votes
1answer
93 views

Center code in a lstlisting float

Out of pure laziness, I decided to create lstlisting floats with the option offered by the package: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \begin{document} ...
2
votes
1answer
70 views

How to temporarily disable a comment delimiter when using listings [duplicate]

In the preamble of my document, I put the following command to allow strings wrapped with < and > printed as italic-styled comment: ...
4
votes
1answer
112 views

Spacing looks wrong in listings when using fixed columns

When I use columns=fixed to present my listings, the letters are spaced too far apart. Why is that? \documentclass{article} \usepackage{listings} \lstset{columns=fixed, basicstyle=\ttfamily}} ...
0
votes
0answers
27 views

Formatting Annotations in Comments [closed]

I like to format annotations that occur within comments of C source code with the listing package. Here is an example of the code: //@ ghost unsigned int no_btn_press = 0; /*@ @ behavior ...
4
votes
1answer
113 views

\lstlistoflistings causing error

my problem is, I added some listings to my Tex document. On the first run everything went fine and all was shown. After the second rerun, it does not compile anymore. Error: !Paragraph ended before ...
1
vote
0answers
7 views

Extra endlstlisting when the code include endlstling [duplicate]

I want to print the following code \usepackage{listings} \usepackage{color} \definecolor{name}{rgb}{0.5,0.5,0.5} ... \lstset{key1=value1,key2=value2} ... \begin{lstlisting} Code \end{lstlisting} ...
3
votes
0answers
36 views

Code in listing not formatted correctly [duplicate]

My preamble is as follows: \documentclass{llncs} \usepackage{xcolor} \usepackage{harvard} \usepackage{listings} \usepackage{chngcntr} \makeatletter \lst@InstallKeywords ...
3
votes
0answers
62 views

Relatives/absolute path for listing with subfiles

I have problem with path management. Let me explain you: I work with subfiles that are arranged in this way: REPORT --Main.tex --lab1 ----Matlab ------CodeLab1.m ----Report ------Report_P1_1.tex ...
6
votes
0answers
48 views

How can I make a custom environment that wraps listings?

Thanks to this answer, I know it is possible to float and wrap text around a listing. I would like to setup an environment for mini-code snippets that always floats and wraps the same way. I can ...
4
votes
3answers
179 views

Put a grey background behind code extracts in a Latex document (like this site does)

I'm using the listings user package to insert extracts of code into my document, however it isn't distinct enough from the normal text as I'd like. Is there a way to put a grey background behind the ...
4
votes
1answer
135 views

How can I highlight SPSS Syntax code with the listings package?

I'm writing my master thesis at the moment and I want to add some code listings to the appendix. The code is written in "Syntax", the programming language of SPSS Statistics. Is there a way to ...
2
votes
1answer
68 views

Listings refuses to highlight identifiers such as 'intent–filter'. Why?

I have some xml code, which I want to look fine in my latexdocument. I am doing it this way: \documentclass[12pt]{scrartcl} \usepackage[ngerman]{babel} \usepackage[utf8]{inputenc} ...
2
votes
0answers
68 views

Different colours for each argument and value in listings

This recent question (Print blue brackets in one language and black in another) made me come up with (up to) two more questions regarding the listings package: Is there an option similar to opstyle ...
4
votes
1answer
75 views

Print blue brackets in one language and black in another

In addition to that question i wonder if it is possible to have that settings for one language and default settings for another ? How to highlight operators and brackets in a C listing? ...
6
votes
1answer
65 views

Actual line numbers for listings: firstnumber=\inputlineno is off by one

I would like to have the actual line numbers next to my code listings but if I use firstnumber=\inputlineno, this gets evaluated one line too early: \documentclass{article} \usepackage{listings} ...
1
vote
1answer
55 views

How can I change the style of listing captions to “Listing. #”? [duplicate]

With the lstlistings package, is there a strait forward way of changing the label style from Listing 1 to Listing. 1 By the "label style" I mean the string used in the captions. EG. ...
6
votes
1answer
144 views

Aligning and centering a lstlisting with two columns on a page

Consider the following code taken from here to produce a fancy listing : % PACKAGES \documentclass[11pt,a4paper]{book} \usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} ...
7
votes
2answers
395 views

Change the background color of line numbers in a lstlisting?

Consider the following code which deals with a lstlisting. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{listings} \usepackage{xcolor} ...
6
votes
1answer
164 views

Listing with two columns in a single fancy frame

I am playing a little with lstlistings and I wonder whether such a thing would be achievable for all my listings: How to achieve this kind of things? Note : I am searching for a solution I can ...
2
votes
0answers
67 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 ...
5
votes
2answers
158 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
155 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
74 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
116 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
70 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
103 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
156 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
98 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
51 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] ...
1
vote
0answers
110 views

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

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
74 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
151 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
60 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
106 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
86 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: ...