{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
0answers
102 views

Extra space in \lstinline

When using the \lstinline macro from listings, like \lstinline|subl| some extra whitespace is added to the intended text. It is especially painful at the end of the line: it behaves as if it were ...
1
vote
1answer
68 views

Unwanted line spacing inside lstlisting, inside enumerate

I want to place some code inside of an enumerate whose labels are encircled letters. I'm following this question to get the encircled letter labels, but I'm having a spacing issue: ...
7
votes
1answer
279 views

IPython Notebook cells with listings

I would like to include in my document some code examples that look like the IPython Notebook cells in this image: I have produced something that looks a bit like it with the code below: ...
3
votes
0answers
248 views

fancyvrb + listings inside a list

I'm trying to put Verbatim environment from fancyvrb package, with activated interface to listings package, inside enumerate environment. When Verbatim environment is first element in \item, item's ...
1
vote
2answers
95 views

Add custom entry to \lstlistoflistings

I am using the listings package for code listings. I am using \lstlistoflistings to generate a list of code listings. I have one code 'pretend' listing which is actually plain latex code, however, ...
2
votes
1answer
172 views

Curly braces in my Java lstlisting are not shown

I'm writing my thesis with ShareLatex online tool (pdfLaTeX compiler) based on template; METU Thesis Template on ShareLatex. When I try to add a lstlisting or lstinputlisting to my document, curly ...
3
votes
1answer
129 views

Greek Text (babel) and English Code Text (listings): Problem

I use the babel package in order to write in greek with font "kerkis". I want to add code in english ("courier new" font) to my latex document but I get some difficulties. Can anybody help me, ...
4
votes
1answer
96 views

How can I apply two styles using moredelim?

I'm using lstlisting with moredelim to color sections of the listing. Now, I'd like to also underline the same sections. I found that I cannot simply add \underbar. \lstdefinestyle{foo}{ ...
1
vote
0answers
55 views

Listing caption numbers are reverse in the list of listings [closed]

Consider the following code: \documentclass[a4paper,10pt]{book} \usepackage{listings} \usepackage{xepersian} \settextfont{FreeFarsi}% http://sourceforge.net/projects/fpf/ \DefaultMathsDigits ...
4
votes
1answer
60 views

Shorthand for \lstinline{ … }?

I'm finding that I need to use \lstinline{...} a lot. I rather like the way that SX does inline code. Just enclose in back-ticks. Is this functionality available in LaTeX, or is it possible for ...
1
vote
1answer
138 views

Duplicate entry on toc when using lstlistoflistings [closed]

Hi i am making my thesis on latex and i have write some code examples using the lstlisting package. Then i have used the command \lstlistoflistings to add all the example at the beginning of my ...
2
votes
2answers
86 views

Insert a lstlisting inside an algorithm2e

I would like to be able to present a C++ code snippet. I would like for this snippet to be captioned, referenced, and included in the Table of Algorithms generated by the algorithm2e package. This is ...
5
votes
1answer
148 views

lstlisting caption problem with xepersian

I am using the xepersian and lstlisting packages and I am having some trouble with the captions. Here is the code: \documentclass[a4paper,10pt]{article} \usepackage{listings} ...
1
vote
1answer
57 views

How can I use a specific font in a program listing in Lyx?

I would like to know how to use a specific font (Arial, for example) in a program listing. The idea is to insert in my document a part of code in a 'program listing'. I found a way to insert some ...
7
votes
1answer
65 views

Automatically link identifiers in a code listing

I have some code listings (using the listings environment or the lstinline macro from the listings package) where I'd like to link all the identifiers defined in the present document to their ...
2
votes
1answer
161 views

TikZ annotation inside listing inside TikZ node

In the below code, on the first frame I typeset a code snippet with verbatim, and all is well. On the second frame I want to add a TikZ annotation to the code snippet, but I have to switch back to ...
2
votes
1answer
51 views

The comment is cut from a point [duplicate]

I am writing an algorithm in LATEX un=sing sharelatex.com. I have written a long comment and it is cut from a point. I have written this: %This is a LaTeX template for homework assignments ...
2
votes
0answers
105 views

Use dollar sign in verbatim environment within auctex

I am using something similar to the following, \documentclass{article} \usepackage{listings} \lstnewenvironment{shellsession}[1][] {\lstset{language=bash basicstyle=\small\ttfamily, ...
4
votes
2answers
109 views

Reset counter automatically after lstlinputlisting or lstlisting

I have a number of code examples annotated with a number set by a counter, lstNoteCounter and referred to in the text below the code: My markup works, but it isn't convenient for a large document: ...
1
vote
0answers
62 views

Turn off colors using listings package in Beamer [closed]

I am using different languages in my Beamer presentation: C++, Assembler. For terminal output I have defined: \lstdefinestyle{bash-output-style}{ ...
5
votes
1answer
168 views

How can I automatically prepend a prompt (e.g. $) to each line of a listing?

I have something that looks as follows: \documentclass{article} \usepackage{listings} \lstnewenvironment{shellsession}[1][] {\lstset{language=bash, basicstyle=\small\ttfamily, numbers=none, ...
1
vote
1answer
78 views

Center caption in boxed listings object

I have put some pseudocode in a listings object, with a caption and box around it. I have used the fancybox solution to listings objects suggested here: How to center a lstlisting Everything is fine, ...
3
votes
1answer
119 views

There is something wrong when I use scalebox to decrease the size of listings code to fit in one frame

I want to the source code to fit in one frame because parts of it are out of the frame. But when I remove the comment in the following source code to use scalebox, I get something wrong. Here is my ...
5
votes
1answer
85 views

Possible Lualatex problem with documentation library from tcolorbox

I am developping a package which uses some lualatex features. In order to show examples in the documentation, I have to use lualatex for the compilation as well. I decided to use the documentation ...
2
votes
1answer
57 views

Why is the source code between listings indented and numbered wrong?

Here is my code and output. We can see that the number and indent of the inner loop is wrong. \documentclass{beamer} \mode<presentation> { \usetheme{CambridgeUS} \usecolortheme{dolphin} ...
2
votes
1answer
95 views

How can I add source code like the following image in the beamer frame?

I have tried the listings package, but the question is that I can not type math equation in it. (The line number on the left start from the first line, i.e. type val is also OK for me.)
3
votes
2answers
230 views

Frame for lstinputlisting but not lstlisting

I'm using listings for a document which contains code examples within the TeX file and also inputed from external files. I'd like horizontal lines above and below the latter but not the former, but ...
5
votes
1answer
77 views

Custom marker at pagebreak within lstlisting

Does anyone knows a solution about how to make place custom markers at pagebreaks into lstlistings ? What I want is to put a cissors icon before and after the pagebreak but I didn't find a way to ...
4
votes
2answers
137 views

Highlight / emphasize a string in tcblisting

How can I emphasize a string in a tcblisting like it is possible with the "moredelim" option in a lstlisting environment? The goal ist to be able to situational epmhasize arbitrary strings in a ...
2
votes
0answers
98 views

Different display of listing's background (Texmaker internal PDF viewer & Adobe Reader)

I have following code: \documentclass[10pt,a4paper]{article} \usepackage{color, eso-pic, tikz} % Create commutative diagrams \usepackage{listings} \definecolor{light-gray}{rgb}{0.95,0.95,0.95} ...
3
votes
0answers
72 views

Listing sourcecode - two columns, associations with colored background

I stumbeled over a way of formatting sourcecode in a book I am currently reading. It looks like this: So basically we have a following structure: There are two columns. Left column contains the ...
4
votes
1answer
35 views

listings package: auto indexing

I studied the documentation but was not clever enough to understand how to automatically index multiple kinds of keywords. I give a MWE below. When I run the document, only class [1] keywords appear ...
5
votes
1answer
97 views

Highlighting a backslash with showexpl or listings

Is there a way to highlight a single backslash (\) within LaTeX code with listings or showexpl? In the following example, \LaTeX is correctly highlighted, but not the following backslash. ...
1
vote
1answer
93 views

Turkish (İ) character inside code listings

I'm using listings package to put java code in my tex files. There are some Turkish characters in the code. So, I'm using the literate directive for them to appear correctly. Everything works fine ...
2
votes
1answer
116 views

Avoid insertion of space below section title with aboveskip, belowskip in listings environment

I was using the listings package to place source code in my document and I noticed that the space between the text and the lstlisting environment was to little. So I changed the \aboveskip and ...
4
votes
1answer
225 views

lstlisting R keywords

I want to write R source code in my latex file so I'm using the listings package. The problem is that I want R keywords to appear in blue but for instance a variable named abc.log.de appears with log ...
0
votes
1answer
165 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 ...
3
votes
1answer
82 views

Typeset listings with preamble (Preferable using the listings package)

At the moment I use the listings package to typeset my listing. The listings are floats, use line numbers and have a top and bottom rule in order to be set apart from the surrounding text. What I ...
2
votes
0answers
86 views

Listings: color numbers only out of keywords

With the listings package, I would like to color the integers out of strings and comments and out of keywords too. The question for coloring numbers has been asked several times. Some answer handle ...
5
votes
3answers
132 views

numbering tcolorbox toc

I'm writing a quite large document and would like to make a toc of used boxes. I'm using the tcolorbox package because i like the way it gives you freedom to modify the appearance of the boxes. While ...
6
votes
1answer
224 views

Using the sourcecodepro font with Beamer listings

I would like to use the sourcecodepro package to typeset source code in Beamer. The following code gives the same fonts, regardless whether sourcecodepro is loaded or not. I would like to stick to ...
2
votes
2answers
63 views

Problem with package Listings with Czech letters compiled by XELATEX engine

When I try to use czech letters defined like this {Ř}{{\v{R}}}1, I'v got this: My problem is that that letters with hook are not have the right position in the word. When I try compiling MNWE with ...
3
votes
1answer
96 views

Cannot see colors in LaTeX output - lstlistings

Can you give me some help? In the following I only see black text, although I set lots of things with different colors... Why isn't this working? \documentclass[10pt,twoside,a4paper]{article} ...
3
votes
1answer
224 views

Skip line numbers and resume from specific number

I'm a total latex noob, I would like to accomplish something similar to what has been asked here, but rather than resuming numbering from where it was left off, I'd like to pass the new line number as ...
3
votes
1answer
118 views

Highlight variables prefixed with % and $ lstlisting

I'm trying to get syntaxhighlighting comparable to this: (with $-prefixed variables as well) But I'm having issues with the %-prefixed identifiers. I tried doing it with ...
3
votes
1answer
78 views

UTF characters in listings

I use lstlistings for code and a lot of special characters can be displayed with literate. See my MWE \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} ...
3
votes
0answers
174 views

listings: How can I highlight Makefiles?

I am trying to typeset a makefile using listings. Now I would like some differential highlighting, e.g. for variables and ordinary commands in the target body. In this snippet, want to have different ...
6
votes
1answer
157 views

What is the difference between \usepackage{mcode} and \usepackage{listings} for MATLAB codes?

I know there is available in the MATLAB Central File Exchange site the mcode.sty package, which allows to put MATLAB codes into TeX files. ...
0
votes
1answer
110 views

I have some weird output instead of “blank space ” it appears unknown symbol in LaTeX [duplicate]

I'm writing code c++ in LaTeX using listing...but I have some weird output instead of "blank space " it appears unknown symbol, here is the code of the list: \defverbatim[colored]\lstI{ ...
1
vote
0answers
38 views

How can I typeset JSON code with the listings package? [duplicate]

I got this error with the listings package (v 1.5c). Should I install the language manually? ! Package Listings Error: Couldn't load requested language. See the Listings package documentation for ...