{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
1answer
13 views

Allowing line break at C++ operators ('::', '->', …) in \lstinline

The following picture shows my problem: How can I tell \lstinline to break lines at specific C++ operators? For example: FooFactory::instance()->createFoo() should be broken as follows: ... ...
3
votes
0answers
35 views

How to add my listings to the table of contents?

I am using the thesul class. I would like to add my listings to the table of contents. I found a way to do that by using the \addcontentsline{toc}{spsection}{Listings} command: \tableofcontents ...
5
votes
1answer
34 views

beamer + lstlistings + overlay -> wrong numbering in caption

In my tex file I have the following code. It results in the Listing being numbered with an increasing index. Is there a way to prevent this from happening? (see screenshot: the second slide should say ...
5
votes
1answer
26 views

How to include Matlab code into LaTeX in colour? [duplicate]

I need Matlab code, e.g. the one here, in LaTeX and in colour (the comment is green, for/if/else/end is blue). % super cooles Programm i = 1 for i = 1:10 if i > 3 i=i+2 else ...
2
votes
1answer
36 views

Latex, two-column listing in an array

I am trying to display to codes side-by-side, using this: \begin{center} \begin{tabular}{c|c} \begin{lstlisting} while (x > 0) do x++; \end{lstlisting} & \begin{lstlisting} x = 0; ...
3
votes
1answer
65 views

Getting Swedish letters to work in LaTex

Problem: Issue 1 (solved): The Swedish letters ÅÄÖ/åäö do not print out correctly when used with listings package. Issue 2: How can it be solved so that the Swedish letters also get orange color ...
3
votes
1answer
26 views

Quoted code changes color when imported from source

I wrote a simple code to highlight syntax when I quote some C++ in latex. However, when the code is directly imported from a source file, the headers are in blue instead of green, this being the only ...
5
votes
2answers
581 views

Stop listings going over page breaks

I am using Pandoc to generate Tex from Markdown. It automatically generates listings when it comes across the appropriate Markdown (code indented four spaces). It then uses the listings package to ...
2
votes
1answer
37 views

NewEnviron, \BODY and lstlisting [duplicate]

I was trying to understand egreg's answer to Hide content to show later, and I noticed that there were some problems when using lstlisting or tcblisting environments inside the solution environment ...
2
votes
2answers
70 views

Listings: add vertical padding without abusing frame

I have the following setup for my displayed listings: \documentclass[a4paper]{article} \pagestyle{empty} \usepackage{listings,xcolor,lipsum} \lstset{ backgroundcolor = \color{yellow}, ...
25
votes
2answers
20k views

How to format an inline source code

I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options ...
2
votes
2answers
761 views

Code listing spanning multiple pages with captions at top

Is it possible to span a lstlisting environment or lstlistinginput on multiple pages, such that the caption is repeated on each page (the listing counter stays the same), as well as being able to ...
7
votes
1answer
2k views

Listing with line numbers inside a table

I typeset a lot of listings (using the listings package) inside (array-based) tabular environments. This works like a charm, however, breaks when I pass the numbers= option to the listing: ...
2
votes
1answer
27 views

How should multiline pieces of code be put into a table?

I have the following two pieces of information that I would like to present side-by-side in a Beamer slide. I think I'd like these two things in two cells of a two-column table. Is there a good way to ...
8
votes
3answers
91 views

Include a footnote in verbatim text

I have seen how to add verbatim text to a footnote: How to obtain verbatim text in a footnote? What I would like to do is the opposite, include a footnote in a verbatim section. I am using the memoir ...
1
vote
1answer
28 views

Margin notes in listing with float enviroment – Error: Float(s) lost

Based on this question: Margin notes in listing with float enviroment - Error: Float(s) lost I have now other question. The solution is working fine. But I want to use floats for listings, to prevent ...
1
vote
1answer
37 views

How to prevent line breaks in code listings?

I am adding a big Linux terminal output as a listing and would like to prevent these line breaks from happening: e.g. user@pc ~ $ top PID USER PR NI VIRT RES SHR S %CPU %MEM ...
0
votes
1answer
27 views

Handling 'underscores' and special characters in latex listing package [duplicate]

How to handle the 'underscore' and the special character in latex listing. I am working on a simple prolog style code \begin{lstlisting}[label=LE, name=R_E] $\alpha_{1}$ = *M1* °h1°(^A^, ^B^) ...
1
vote
2answers
206 views

listings - highlighting additional keywords inside own delimiters (like Doxygen annotations)

According to listings - use different style for normal comments /* and doxygen comments /** I used listings package to set style for /** Doxygen comments */ as user defined delimiter moredelim = ...
9
votes
3answers
4k views

Typesetting UTF8 listings with German Umlaute

I'm having some issues with listings that include German Umlaute. The following example code generates a completely messed up PDF. \documentclass{article} \usepackage[utf8]{inputenc} ...
5
votes
1answer
51 views

Rewrite \begin{foo}\end{foo} to \begin{bar}{opts}\end{bar}?

I know this is likely a simple Latex macro question. I've got a large document with a ton of lstlisting blocks, and I'd like to use minted instead. That means turning blocks that look like this: ...
1
vote
0answers
13 views

Is it possible to include a lstlisting code block inside an lstlisting? [duplicate]

I am trying to include a LaTeX code within an lstlisting. But the problem is that the LaTeX code includes an lstlisting, so the \end{lstlisting} within the included code is terminating the actual ...
3
votes
1answer
36 views

Reproduce lhs2tex’s code indentation in LaTeX

The preprocessor lhs2tex has a very neat way of aligning code. Consider this snippet: let t1 = foo x in let g x = if x > 10 then t1 else let t2 = bar x ...
5
votes
3answers
66 views

Centered line code with numbering

How I can center a line code and numbering it like in the picture? Is there a command that works inside a lstlisting environment? Really thanks in advance
2
votes
3answers
90 views

How to use the degree symbol in programming listing?

I'm using lyx and get the error message, that the ° symbol got excluded, when I'm trying the following example: \usepackage{listings} \begin{lstlisting} 10°C \end{lstlisting} EDIT: as asked, here ...
0
votes
1answer
26 views

referencing listing with custom caption using autoref

I'm trying to use the listings package to show some pseudocode. For that I want to add some keywords and a special environment which is used for all pseudocode listings. Additionally the referencing ...
0
votes
0answers
25 views

Listing package making one long dash from multiple dashes (also breaks margins)

----------------------------------------------------------------------------- -- -- Version 1.0 -- ----------------------------------------------------------------------------- Code like the above ...
1
vote
0answers
40 views

How can I highlight something inside a listing? [closed]

I need to call attention to parts of code that don't get highlighted as keywords, strings, etc. inside a listing. I've found a few relevant questions on TeX.SE I and tried to apply the solutions ...
0
votes
1answer
36 views

Float placement for lstnewenvironment

I've defined this environment: \lstnewenvironment{pddl3}[1][] { \lstset{ keywordstyle=\color{black}, commentstyle=\color{black}, language= VBScript, ...
4
votes
1answer
46 views

Length operation within a newtcblisting

Consider the following code: \documentclass[10pt,letterpaper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[french]{babel} \usepackage{calc} \usepackage{tikz} ...
1
vote
1answer
51 views

Unwanted space around punctuation in copied & pasted listing

When I compile the .tex file below into .pdf using rubber -d mwe.tex and try to copy & paste the contents of the listing, I get spaces around . characters that were not present in the original ...
8
votes
1answer
185 views

Specific color for different tags and comments using Listings package

Problem: The > symbol for HTML tags in the MWE has a different color than the < symbol. Would like to have both the same color. Minimal Working Example: \documentclass{scrreprt} \makeatletter ...
1
vote
0answers
44 views

why is the text green in my code listing? [closed]

I use \begin{lstlisting} Type readable_t, writable_t \end{lstlisting} I want the text color to be black, but instead I get green:
3
votes
1answer
36 views

beamer problem with combining columns, listings, and overlays

I am trying to come up with a beamer frame where some listing appears at the left column on overlay 1 and some other stuff appears in its place in overlay 2, while some stuff appears in the right ...
2
votes
0answers
30 views

Listings - Getting the colors right for custom language

I have lots of bookkeeping transactions that I would like to typeset in a color coded format. I am using the listings package to accomplish what I want. I tried the following code. ...
0
votes
0answers
40 views

Remove “Lst.” from list of listings

I've renewed the title of my list of listing and the caption of my code snippets with the following commands: \renewcommand{\lstlistingname}{Code} \renewcommand{\lstlistlistingname}{List Of Code} ...
1
vote
0answers
19 views

incorporating R code in latex, commentstyle not working

I have an issue with no all my R comments being colored in my latex file. I am using the listing package. My pre-amble code is \lstset{ % language=R, basicstyle=\footnotesize, ...
0
votes
1answer
164 views

File-encoding issues with \lstinputlisting

Matlab save .m file with ANSI encoding. I have a sample .m file, and want import it into LaTeX with UTF-8 encoding. How to convert ANSI file encoding to UTF-8 and input it, without changing the ...
0
votes
1answer
36 views

Listings moredelim / morestring options doesn't work with included file

I don't know how to fix the double quote character (’"’) with the listings package when the code is in a separated file. Listing get this as the beginning of a string but it is not. Many thanks to ...
3
votes
1answer
64 views

Exclude lstinputlisting

I want to save paper when I print my LaTeX file. That's why I want to hide all my code, inserted wtih lstinputlisting{} I already know how to exclude tables and images or math but the ...
2
votes
1answer
662 views

How to correctly use equal sign in keywords for listings?

I work on a listings code style for HTML5. The style looks quite good but I have a little problem with the equals sign. I defined the equals sign as a keyword: ndkeywords={=, ... } This will cause ...
1
vote
1answer
37 views

Set up [Sharp]C language for listings

Why must I use style work-around to set C# language in listings? Why \begin{lstlisting}[language=[Sharp]C] cannot be processed by LaTeX? \documentclass[a4paper,12pt]{article} ...
0
votes
1answer
40 views

lstlistings: Regexp quotation mark/apostrophe error

I am attempting to display a long Python Regexp in LaTeX lstlistings. When compiling I get the following error message though. ! Package inputenc Error: Unicode char \u8:�\lst@FillFixed@\lst@EC� not ...
1
vote
0answers
36 views

Typeset code within a simple macro?

I want to use a macro to typeset programming code with the usual characteristics (particularly lines should be obeyed - this is the most important issue; highlighting and such stuff is - for now - not ...
5
votes
1answer
48 views

Exclude caption from listing margin in IEEEtran v1.8a

I have the following setup for the listings package, including a left margin to have the line numbers stay within the column. \documentclass{article} \usepackage{color} \usepackage[final]{listings} ...
0
votes
0answers
25 views

Defining specific color for certain symbols in PHP using listings package

Problem: Trying to give certain symbols in PHP a specific color using the listings package. For instance, I want to be able to give <?php and ?> a specific color, while giving the object arrow ...
7
votes
1answer
637 views

Listings - break on whitespace+

I'm using listings for the first time, and have some rather long lines of code. I get that I can break lines automatically with breaklines=true, and I can break only on whitespace with ...
0
votes
0answers
22 views

Listings with some notes

I would add some "notes" to a listing. I mean, I have a listing and in some parts of the code (on the left side) I would add a "symbol". I'm thinking something like a circle with inside a letter ...
2
votes
0answers
57 views

Unhighlighted syntax with listings package

I have some trouble with making documents with syntax highlight. Here is the MWE: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstset{% language=[LaTeX]TeX, % I also tried ...
0
votes
0answers
21 views

Defining keywords for SQL using listings

Problem: I use listings package to highlight SQL code but for some reason, unknown to me, I can't get certain keywords in SQL to highlight in a different color. Minimal Working Example: ...