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

Keep keywords in comments - listing - LateX

Is it possible to keep the keywords highlighted in comments in the listing package of LateX? I want to be able to define two types of comments: one for normal comments and the other one for ...
3
votes
1answer
82 views

Underline in lstlisting environment

I would like to get the same result I get with \underline in a lstlisting environment. I was almost sure I got it in this way: \documentclass{article} \usepackage{listings} \usepackage{upquote} ...
2
votes
1answer
39 views

Bash script between report lines - Line Breaking

I'm using the following commands to introduce bash script text in the middle of a report: \newcommand{\shellcmd}[1]{\\\indent\indent\texttt{\footnotesize\# #1}\\} \begin{document} \noindent ...
3
votes
1answer
194 views

How to change verbatim text to Consolas?

How to change the verbatim text so that a zero shows up with a slash across it? I would like to know if the verbatim text can be changed to say Consolas? Here is my code: \documentclass{article} ...
1
vote
1answer
28 views

Re-position of contents after uncover of other contents

Updated: Considering the following latex document: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[t,fragile] \frametitle{Implementing FA} ...
2
votes
1answer
97 views

Uncover lstlisting on a particular slide using \onslide or \uncover

Updated: How can I uncover a certain lstlisting environment on a particular slide using \onslide or \uncover? For example: \documentclass{beamer} \usepackage{listings} \begin{document} ...
3
votes
2answers
162 views

lstlisting: how to underline a keyword?

In the following, I am trying to underline the keyword 'true' in a C++ code listing. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage[lighttt]{lmodern} % bold and italic ttfamily ...
1
vote
1answer
66 views

Multipage listings with minted and captions

I have source long listings (2+ pages) that I highlight using minited via \inputminted. I wish to have have a caption and a reference label for the listing in \listoflistings and in my text when I ...
3
votes
1answer
41 views

force at least two lines on a page in using lstlisting

I use the lstlisting package a lot in my theses. Unfortunately, it sometimes renders the caption (at bottom of the listing) on the next page or starts the listing at the end of a page, renders no line ...
2
votes
1answer
48 views

Large table in “programming” type font

In my code below, the table appears in a "programming" type font. If I have a larger table (like say in a text file), how can I import that table into my document without having to typing the whole ...
2
votes
1answer
51 views

Listings - Only highlight between delimiters

I want to implement a function name color highlighting and I use the listings package. My 'regex' for this is def %s( where def (including space) is the first delimiter %s is the function name and ( ...
2
votes
1answer
90 views

How to properly number between lstlisting and listing the same latex file?

I'm having trouble with the legend of the lstlisting and listing the latex file when I reference them both are appearing as listing 1. How do I display the number of correctly caption for listing 1 ...
1
vote
1answer
108 views

Fitting codes in a Latex Code block

\usepackage{listings} \begin{document} \lstset{language=Java} \begin{lstlisting}[frame=single] PDDocument doc = PDDocument.load(file); String ...
2
votes
1answer
118 views

how can I explain a MATLAB code in my document like picture?

I have a matlab code and I want explain part of them like picture. or any other idea can do better. \documentclass{article} \usepackage{listings} \usepackage{color} %red, green, blue, yellow, ...
7
votes
1answer
76 views

Listing creation fails with “dimension too large” given a large block of characters

When creating a code listing, we recently ran into a strange error from the listings package. Specifically, listings bails out on a large block of text. Here's a minimal working example: ...
2
votes
0answers
60 views

lstlisting with sublistings and captions and floating environment

I try to create a floating environment with a layout similar to this: _____________________ ___________________ | | | | | | | | ...
3
votes
1answer
122 views

Packages used in this image?

Does somebody know which packages were used to create the following homework assignment? I would like to insert Java source code in exactly the same way in my .tex files
3
votes
1answer
71 views

mixing minted with lstlisting

I have a List of Listings that looks like this: The first listing, which is correct, uses lstlisting. 3.1 is the correct chapter. The second listing uses minted. Somehow it shows 1 as chapter, ...
0
votes
0answers
40 views

How to fix comment indentation of code using the listings package?

My problem is that the code itself is indented correctly, but the comments (e.g. //comment) are not. In my source file, I aligned comments in one column by using tabs. In the pdf produced by LaTeX, ...
2
votes
1answer
47 views

How to prevent \settocdepth{chapter} lead to an empty list of listings

Why does uncommenting the (IMHO innocent) call to \settocdepth{chapter} in the following MWE make the list of listings become blank? Or rather: what can I do to both preserve a chapter-only TOC for ...
1
vote
0answers
27 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
2
votes
2answers
100 views

Colored background in listings environnement

I would like to make my listings environnements more readable by coloring the background of some keywords with a specific color. Like this : I thought using the \colorbox function from xcolor ...
7
votes
3answers
196 views

lstlisting: color LaTeX commands like `\\` or `\!`

How can I achieve it with lstlisting, that LaTeX commands like \\ or \! are properly highlighted as syntax? Adding those commands (with or without backslash) to moretexcs does not deliver the indented ...
1
vote
2answers
34 views

Latex listings - breaklines divides parenthesis, wrong space near parenthesis

When using listings package, there is a wrong spacing after parenthesis and, when a line breaks, the parenthesis are very often divided from what comes before. What can I do to change that? The ...
1
vote
0answers
31 views

Inserting code using listings, goes off page [duplicate]

When I use \begin{lstlistings}, the code is too long and goes off the page, will I have to go through every line and fit it onto the page ? The code is incredibly long and this will take a very long ...
1
vote
0answers
48 views

I have unwanted “stripes” using lstlisting

(First of all I apology for my bad english, french guy here) I am using LaTeX for my university and I have a bug using the package lstlisging, those grey stripes : Here's my LateX code : ...
0
votes
0answers
81 views

Line numbers in listings (lstlisting) based on actual appearence in PDF file

I'm using the listings package to insert source code into my TeX files. I also set the option \lstset{numbers = left} in order to have the line numbers next to my source code and be able to refer to ...
2
votes
0answers
32 views

Listings - Including only part of an external file between certain points

I've just started using LaTeX and am using the Listings package to include external source code. I would like though to only include certain parts of the source code. I know that certain parts of the ...
3
votes
1answer
120 views

Listings style for INI (conf) files

I'm trying to create a simple style for Windows INI files using the listings package I'd like this results: purple [sections] tags red assignment operators (= and :) gray comment lines starting ...
0
votes
0answers
27 views

Color “(,),:,;,=,+” in lstlisting [duplicate]

how do I color these characters ():;=+ in lstlisting? I've tried to use literate={(}{\textcolor{yellow}{(}}1 but it doesn't work. Greetings!
1
vote
1answer
64 views

Ignore indent of itemize for figures, lstlistings etc

I have a list of items where some of the items contain figures, listings, etc. How can I make these environments ignore the additional indent in an itemize environment? My code looks like this: ...
2
votes
1answer
45 views

Frame a line in an environnement lstlisting

I defined an environnment \lstset{...} to put some code in a beamer presentation. I would like to frame a specific line in my code, this way: How can I do that? Have I to use tikz package in ...
1
vote
0answers
32 views

Issue with lstdefinestyle{XML} and margins [duplicate]

i am having troubles inserting XML code in Latex because the code lines appear out of the margins. First at all, i have defined the style, by the following way: \documentclass[a4paper,11pt]{book} ...
1
vote
0answers
25 views

What can I use to typeset a part of MATLAB code (m file) in my document? [duplicate]

I have a .m file and call .m file with ‎\lstinputlisting{****.m}. but I want LaTeX to show lines 13 to 25. How is it possible?
4
votes
2answers
63 views

How can I avoid the use of default styles when no listings language is set?

When global listings styles have been defined identifiers are coloured differently from numbers even if no language is in effect. How can this be avoided? \documentclass{minimal} ...
2
votes
2answers
46 views

How to split 3 spaces ligature in lstlisting

Code: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{listings} \begin{document} \begin{lstlisting}[language=PHP,breaklines] $a === $b; \end{lstlisting} ...
3
votes
1answer
64 views

How to use onslide in a listing?

I need to animate single contiguous code listings by showing and hiding parts of code using \onslide. However, TeX is complaining. How can I achieve this? I tried the advice here but it didn't work. ...
2
votes
1answer
104 views

Skipping line numbers in lstlisting

Referring to Skip line numbers and resume from specific number I tried to skip several line numbers in my listings and continue with a specific number. But in my case there is a really bad side ...
0
votes
1answer
94 views

Using setmonofont with Bera Sans Mono in Beamer produces garbled output

I am using Bera Sans Mono as the monospaced font for typesetting code listings using the listings package. This is done for slides which are produced using beamer and XeLaTeX. My preamble includes the ...
5
votes
1answer
91 views

Can't escape curly braces in \lstinline

Upon trying to typeset the following TeX I get the error: Too many }'s. ...handleClick } >Button component} TeX: \lstinline{<Button onClick=\{this.handleClick\}>Button ...
2
votes
2answers
113 views

Highlight asterisk in lstlisting

I would like to emphasise the asterisk used in \begin{equation*} in lstlisting. I have tried using emph, also including the alsoletter macro, but it doesn't work. Why not? \documentclass{article} ...
0
votes
0answers
17 views

How to get Unicode in code listings? [duplicate]

I want to use Unicode text (a mixture of cyrillic and japanese characters) in a code listing that uses default LaTeX fonts (in other words, source code fonts are left to default). However, for all ...
0
votes
0answers
8 views

lstlisting indentation versus editor-formatting [duplicate]

Whenever I use the listings package to typeset code, I encounter the problem that the way lstlistings work collides with the formatting my editor likes (I use vim). For instance, see this code: ...
2
votes
0answers
72 views

Problems with PHP tags (and code) in listings with HTML

I want to highlight PHP and HTML in the same code. In my attempts I experience three challenges: Seems like listings treats <?php and ?> as one large HTML tag. How to tell listings that the ...
3
votes
1answer
69 views

lstlistoflistings is unformatted

I habe a problem to get a list of listings that looks like the normale table of figures or basically like any other list of anything. As I am not a tex or latex pro, i tried several packages and ...
3
votes
1answer
63 views

How to set the label for listings?

Hi I'm new in Latex and I'm using this code from the Board everything is working, but I don't know how to set the label for the listing with this code \usepackage[many,minted]{tcolorbox} ...
1
vote
1answer
58 views

How to lstinput a text file path and get content of ext file into pdf

I tried to insert some data using listings package labels(lstset) into pdf which was successful but if the same data is put into a text file ans lstinput it as follows is not successful .Can some one ...
1
vote
1answer
71 views

Listings and verbatim-like environments in a tikz node using newcommand

I have seen answers to this question floating around but none of them appeared to solve the problem. I want to be able to throw a code block into an already defined tikzpicture. So I attempted to ...
0
votes
1answer
43 views

Font size of inline code-listings too small

I'm using the listings package and am satisfied with how my code listings look. The font in my inline-listings however is too small compared to the rest of the text. How can I only increase the font ...
3
votes
2answers
70 views

Setting lineskip affects the caption in listings

If I specify a lineskip in lstlisting, it affects the caption too. How can I prevent it? Example: \documentclass[a5paper]{article} \usepackage{listings} \begin{document} \begin{lstlisting}[float, ...