{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

1
vote
1answer
47 views

How to avoid Greek letter symbols in lstlisting

I am using the lstlisting package, but I don't want it to show Greek letters by its symbol. For example: \begin{lstlisting} Parameter.delta_x = 0.002e-6; \end{lstlisting} I want that line ...
1
vote
1answer
50 views

How can I prevent page breaks from occuring inside the body of a function?

Is it possible to tell the listings package not to insert page breaks inside the body of a function? For instance, void foo() { // Do not insert page break here } //But here is fine An ...
4
votes
2answers
109 views

How can I automatically replace subscripts and highlight GoTo labels?

I have to show a lot of autogenerated code throughout my document. The generated code represents loops with explicit block labels and gotos. The following code applies function f to each element of ...
1
vote
0answers
26 views

keyval error for listings/color? [closed]

When I try to compile this in my code, the compiler tells me Package keyval Error: backgroudcolor undefined. I really don't understand why it is telling me that when I know the package is installed. I ...
3
votes
2answers
64 views

Bad Character code (256)/ \select@language{greek}

I was trying to install minted package in TeXLive. I installed it and then run sudo tlmgr update --all. It was running slow so I stopped it using Ctrl+Z in an ubuntu terminal and then I run sudo tlmgr ...
3
votes
1answer
82 views

How can I replicate the syntax-highlighting style of the Kate editor?

I am trying to add a java and c++ code in a LaTeX document. I am using listings package and I will define a different style for each language using \lstdefinestyle{myStyle}{<options>}. What I am ...
3
votes
1answer
33 views

How can I reduce the line spacing in a listing?

I have some listings in my beamer presentation. Sometimes, the last line of the code I want to explain doesn't fit on the slide. I've already configured the font size to scale .7: ...
15
votes
1answer
371 views

Is there a good reason for lstlistings code to look so ugly by default?

I thought, the purpose of LaTeX was to make it easy to create beautiful documents. Yet every time I see one of those lstlistings I can't help but wince at the mutilated kerning. Take for example this ...
3
votes
2answers
190 views

Read integers from external data file to document programming code in LaTeX

I am attempting to document my MATLAB programming code in LaTeX. For this, I use the mcode package, which defines the MATLAB lstlisting environment. With the commands ...
5
votes
2answers
77 views

Remove margin from listings in beamer

I am including some code in my beamer document. I would like to get rid of all margins, so I can include as much code as possible. This is the code I am trying: \documentclass[]{beamer} ...
0
votes
1answer
128 views
+50

How to place the caption of a lstlisting in the margin? (scrreprt, floatrow)

In the following mwe I am using the floatrow package to place the figure captions in the margin. How can I do the same for listings? Update: Some listings are spread over two pages. ...
1
vote
1answer
32 views

Package “listings” command “morekeywords” doesn't work

I'm currently using the listings package to display my matlab code in Latex. However, when trying to add new keywords to the package, nothing happens. Here's a MWE: ...
4
votes
2answers
80 views

Issues when including matlab code in Latex

I am currently trying to implement my Matlab-Code into TeX. Weird enough, when programming a minimum working example, everything works pretty fine. However, when I use my real document, I only get ...
1
vote
0answers
32 views

Underscore not showing up in lstlisting [closed]

I have the following code: \begin{lstlisting} path/usearch -cluster_otus inp.fasta -otu_radius_pct distInPercent -otus outGroups.fasta -fastaout outpUSEARCH.fasta \end{lstlisting} The ...
0
votes
0answers
36 views

listings package cannot load any language [on hold]

My MWE cannot load any language. OS: Ubuntu 14.04 64 bit. TexWorks Version 0.5 r.1350 (Debian) Here is the code: \documentclass[11pt]{article} \usepackage{amsmath} \usepackage{amssymb} ...
1
vote
1answer
19 views

Have tableofcontents as PDF bookmark, but not lstlistoflistings

I want to have the "Contents" section appear as a PDF bookmark. I have found this question, and the following generally works: \makeatletter \usepackage{etoolbox} \pretocmd{\tableofcontents}{% ...
3
votes
1answer
35 views

Problem with listings package for Python syntax coloring

I am implementing the method I learned here for putting Python code in Latex. Everything works great except that I have problems with comments. Here's the code from the link I mentioned: ...
3
votes
1answer
45 views

Problems with XML Syntax Highlighting

I want to highlight syntax in XML files. I found a nice definition from krlmlr which I changed to my needs. It works fine for Android's xml files: But the result of a xml file with values in ...
6
votes
1answer
53 views

listings line numbers work with one lstlisting but not another

The first listing has its line numbers ignoring the stepnumber while the second is just fine. Guess it might have to do with using math mode but mathescape applies to both, so if that is the case it ...
2
votes
1answer
32 views

Overlaying a tabular on a lstlisting in a book

I am relatively new to LaTeX and am trying to move a tabular up by about 2cm to overlay a lstlisting. The \hspace command works as expected; the \vspace command however moves the text following the ...
3
votes
1answer
24 views

Change font size of lstlistoflistings heading

How can I change font size of lstlistoflistings heading? Currently it is smaller than normal chapter heading title. Any ideas? Unfortunately I need to use document class from my university, my MWE: ...
0
votes
1answer
54 views

Proper way to indicate code change in lstlisting

[Since the question was not clear] I have a piece of program code I would like to describe in my thesis. My problem is that the part I would like to explain is surrounded by simple code pieces not ...
1
vote
0answers
40 views

Using listings to display regexes [closed]

Is there any way to use the listings package (which I already use for Python) to highlight regexes? I.e. the regex appears in the document as if it were source code, but with some form of ...
4
votes
1answer
69 views

lstlistings does not work in a slide

I am writing a slide. I want to use lstlisting \documentclass[10pt]{beamer} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage[T1]{fontenc} \usepackage{lmodern} ...
4
votes
1answer
66 views

Listings with keywords that contain both letters and numbers

I have a listing which needs to highlight keywords with both letters and numbers. Following the advice in this question I've used the otherkeywords to define the keywords which contain numbers. This ...
2
votes
1answer
28 views

listings 'escapeinside'-option is not working for me

this is my first question here. I'm not exaclty new to LaTeX, but to be honest I've never really gotten too much into it. So here's my problem: I have this minimal example: \documentclass{scrreprt} ...
1
vote
0answers
36 views

Aligning listing frame width between two listings

I'm trying to get two listings side by side. One is shorter than the other, but I would like to have them aligned, meaning that the frame height of the short one should be longer to reach the baseline ...
2
votes
2answers
65 views

Counters for Chapter and Section environments when using tcolorbox for listings

This is a followup question of this question. With my MWE I'm getting wrong Listing numbers, wrong toc (including Chapter and Section environments from listings) and wrong bookmarks in pdf toc. Any ...
0
votes
0answers
26 views

Using listing to include only some lines of a file [duplicate]

How can I use listings in order to include some lines from a file keeping the numeration right, that is, if I include lines 1-3,8,11-14 they should keep that numeration rather than 1,2,3... Is this ...
2
votes
1answer
70 views

Reading code from external file in tcolorbox and getting pdflatex> ! paragraph ended before \tcb@set@label was complete

I want to read code from external file in tcolorbox in new defined \texexptitled environment but could not succeeded (See MWE). Without this my MWE also throws two other errors pdflatex> ! ...
3
votes
1answer
73 views

listings using tcolorbox for beamer documentclass

I'm trying to get listings using tcolorbox for beamer documentclass. My MWE is given below but could not get it working. Any help will be highly appreciated. Thanks MWE \documentclass{article} ...
3
votes
1answer
61 views

listings using tcolorbox package without Chapter and Section environment effects

I want to get listings using tcolorbox package but without counting Chapter and Section environments. See in MWE, I used section environment withing listings which effects the counter for following ...
5
votes
1answer
52 views

Apostrophe breaks comments in lstlisting

I defined a command to simplify the writing of code listings of (pseudo-) C code: \lstdefinestyle{c}{ language=C, basicstyle=\small\sffamily, numbers=left, numberstyle=\tiny, frame=L, ...
7
votes
2answers
167 views

Using listings with output

I wonder how to get the output of listings with code. Here is my MWE with output. Now I want to output of this listings too. Any help will be highly appreciated. Thanks Code ...
3
votes
1answer
55 views

lstlisting in landscape and heading in portrait

I am trying to include some code files in landscape mode into my document which is in portrait mode. I do this using the \usepackage{lscape} and \usepackage{listings} So far so good. The ...
1
vote
0answers
44 views

How can insert a full-width listing in a two-column document? [duplicate]

I'm new to LaTeX; I'm using IEEE format. How can I effectively add Java code snippets in one full-width column?
4
votes
1answer
61 views

Lstlisting: width of background box

I'm trying to modify my listing environment in a way that the background color for the listing is expanded over the whole width of the page. So no white border left. Is this possible? I tried doing ...
7
votes
0answers
44 views

Adding color package destroys listing centering

I am using @egreg's answer to make listings centered: \documentclass[a4paper]{book} \usepackage[T1]{fontenc} \usepackage[ hang, small, it, hypcap=true ]{caption} \usepackage{fancyvrb} ...
0
votes
1answer
51 views

Listings Character problem

Hi I want to define a string in Listings but I can not do it in Turkish. I want to write: int[] sayılar= new int[5];' but the output is int[] saylar= new int[5]; How can I write Ç,ç,ı,ö,ü,ğ?
1
vote
1answer
75 views

Listing linebreaking not working

got a listing where the code include a very long sequence of characters (letters, numbers & other). With linebreak=true, the sequence gets broken at non-letter characters. However I still got a ...
3
votes
1answer
44 views

Why don't those non-alphanumeric chars (*/_) get colored in blue, here?

Consider the following example: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{language=R, morecomment=[l]{>}, commentstyle=\color{blue}, alsoletter={*} ...
4
votes
1answer
91 views

What can I do if a listing is too wide to fit in my two-column document?

I am writing a IEEE document with a LaTeX template I downloaded from the IEEE webpage. I inserted some MATLAB code into the document through the mcode package. It looks something like this: ...
3
votes
1answer
74 views

How to copy/paste multiple spaces from lstlistings?

This is a continuation of a question that I asked already: How to copy/paste from lstlistings?. The solution presented there does not work if the text within the lstlistings environment contains ...
4
votes
1answer
74 views

How can I highlight JSON string values but not attributes?

example { "name" : "alan", "alias" : "nala" } If I use morecomment=[s][\color{red}]{"}{"}, How can I highlight JSON string values (on the right side) but not the attributes (left side)?
5
votes
1answer
76 views

Correctly highlighting custom html tags in listings

Problem statement I have several code listings containing HTML markup in my latex files. These listings contain multiple custom html tags (created in combination with corresponding AngularJS ...
0
votes
0answers
70 views

Pandoc: Markdown to PDF: select code without select number into code block

i want to generate the code block and i try example and it work. but when i try to select the code from the pdf, the number also get selected. how to generate code block that when select the code w/o ...
6
votes
1answer
63 views

How can I apply different styles to different classes of identifiers?

I am creating a custom style for the lstlisting package, with some custom colors for certain words. I am trying to define different "classes" of words, where each class has a certain property, like ...
4
votes
1answer
33 views

Color behind numbers in lstlisting

Currently, my listings use this style : \definecolor{lstgrey}{RGB}{217, 217, 217} \definecolor{lstback}{RGB}{246, 246, 246} \newlength{\numberlengthnormal} ...
3
votes
3answers
101 views

\lstlistoflistings title says “Table of Contents”

When I tried \lstlistoflistings to print the list of all my listing, the title says "Table of contents", and then it says chapter. Like if it was part of the TOC. I'm trying to get a list, like the ...
10
votes
2answers
240 views

How can I hide (or blur) some code in a listing?

I have a code listing to write in a report, but I'd like to blur or hide some code parts with a colored box (of same length as the hidden text), so that readers cannot see the hidden parts. (Another ...