{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
22 views

Error in listings demo code [on hold]

I copy and paste code from https://www.sharelatex.com/learn/Code_listing \begin{lstlisting} import numpy as np def incmatrix(genl1,genl2): m = len(genl1) n = len(genl2) M = None #to ...
0
votes
0answers
24 views

Define listings language with multiple keyword groups

I wanted to used syntax highlighting for a language unsupported by the listings package. Right now I have it almost working, but not completely. This is the MWE: \documentclass{article} ...
2
votes
0answers
24 views

Warning: uncodable character in LyX lstlisting

The problem I'm trying to insert the output of the tree command into a Program Listing field of LyX. The text is the following: exampleFolder/ ├── 01.mp4 ├── 02.avi ├── 03.mov └── 04.mpg If this ...
2
votes
1answer
59 views

listings package: last whitespace removed before the newline character. How to keep it?

I've some sort of template/examples of bash scripts on my computer (.sh files on my hd) in which I put commands and commented outputs. This is my example.sh file: echo this is wide ...
1
vote
1answer
78 views

Margin notes in listing with float environment – 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 ...
5
votes
1answer
3k views

lstlisting in a tabular environment

I am following Adding C++ code in Latex for adding C++ code to the document. What I have is a table with the following format: \documentclass[12pt,a4paper,final]{report} \usepackage[utf8]{inputenc} ...
1
vote
1answer
218 views

Combine listings package with my own environment [duplicate]

Possible Duplicate: How to use different lstset settings for listings? I have defined my own environment as: \newenvironment{codegui}[3]{% \def\tmplanguage{#1}\relax ...
4
votes
1answer
197 views

breaking lines in listings environment

I am trying to make listing environment brake lines. Unfortunately breaklines=true does not work for me. Here is my code: \usepackage{listings} \begin{document} ...
2
votes
2answers
38 views

List of listings similar to list of figures

After learning on the net I managed to get this type of list of figures : And I want exactly the same with the list of listings, but here is what I get : My code is this one : ...
2
votes
1answer
33 views

Make listing a floating image

I have used the listings package for including a program into a LaTeX document. But the program splits into two when a page is finished. I want to make the listing behaved like an image, so that it ...
0
votes
0answers
15 views

\end tag ignored in frame [duplicate]

I have the following slide in a document of class beamer. \begin{frame}{Modular Design} \begin{lstlisting} <code> \end{lstlisting} \end{frame} This however returns these ...
3
votes
1answer
100 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; ...
1
vote
0answers
27 views

Do not apply literate option in comments

I defined my own programming language using listings and, to do so, I had to use the literate option a lot in my definition. For example, to make parentheses bold and green, I did this: ...
0
votes
0answers
19 views

Keep lstlisting together with preceding paragraph (like formulas)

I have several listings that are only 2-4 lines long. They should be kept together with the preceding paragraph, like it is the default for formulas. For example, lets assume the following code and a ...
3
votes
1answer
12 views

Reference to \lstnewenvironment

\documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch \usepackage{color} \definecolor{codecolor}{rgb}{0.8,0.9,0.9} \definecolor{chatcolor}{rgb}{0.9,0.9,0.8} ...
2
votes
1answer
14 views

lstnewenvironment argument across multiple lines

Hey I am using code bellow to create custom lstnewenvironment, it all works fine if I have \begin{test}{caption}{lst:label} on one line. If I break it in any way for example \begin{test}{Some ...
2
votes
1answer
24 views

Changing the line number in code listing

Below is how the code listing looks like now: I want to change line number 8 to blank, and line number 9 to 10. Reason is that they are actually two lines at ... (at line 8), how should I do that? ...
4
votes
2answers
570 views

Strange spacing in inline listings (listings package)

I am using the listings package to typeset some code. I've defined a lstlisting environment, based upon the standard Haskell environment, and added a number of literate replacements, including: ...
10
votes
2answers
5k views

XML highlighting - different style for attributes

I need to highlight syntax in my LaTeX presentation, so I've found this answer: XML syntax highlighting \lstdefinelanguage{XML} { morestring=[b]", morestring=[s]{>}{<}, ...
2
votes
1answer
52 views

Using an overlay on lstinputlistings in latex

I want to have to multiple overlayed lstinputlistings on one slide in a presentation, created with latex and documentclass beamer. The only solutions I find are for lstlistings, but those don't work ...
3
votes
1answer
26 views

Adding a caption to a tcolorbox \tcblisting

I'm new to the whole TeX world and have finally managed creating my own tcolorbox code box: Now I would like to caption my code boxes like regular listings. It should say something like ...
2
votes
1answer
37 views

Adding a special keyword that is ignored in lstinputlisting

I would like to know how to add a special keyword to be ignored in \lstinputlisting that is used in the listings package. The screen shot shows my problem. I am writing a tutorial document of the ...
17
votes
1answer
539 views

How to display LaTeX code and the typeset version next to each other without repeating myself?

I would like to write some LaTeX code, and without repeating myself, I would like that to be used for displaying that particular piece of code as-is and its typeset version, next to each other. The ...
2
votes
1answer
31 views

Why does using a lstset option in usepackage command make pdflatex not terminate?

Question Why does passing a wrong (as in non-existing) option to listings upon package loading result in a non-terminating pdflatex run, instead of - say - a simple error message? Background ...
0
votes
0answers
24 views

How to type set with the same font in code listing?

In text I have use \emph{chkFlag}, and it looks like this I hope to typeset chkFlag with the same font in code listing as follows: What is the correct command should I use?
7
votes
2answers
309 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 ...
4
votes
3answers
68 views

Listings: Define new language from Emacs highlighting

In my document, I need to include code written in Macaulay2, which is not a predefined language in listings. To define it myself, I started looking for a list of keywords, and found the variable ...
2
votes
0answers
32 views

Automatically colour previously defined strings of text (for strings with spaces &/or punctuations) [duplicate]

Main question Answers to the question Automatically colour previously defined strings of text show how to colour pre-defined strings of text, but all those pre-defined strings are without spaces and ...
1
vote
0answers
18 views

line breaks and word wraps for unpredictable character strings

I am writing python to parse and process lots n lots of files to build a final report of results from information in the files. I am using python to write the latex file, then converting the latex ...
1
vote
1answer
26 views

Different Style of captions

I am writing a document where I have different types of figures like tables and listings. To get the captions the way I want I wrote the following in the preamble: \usepackage[font=small, ...
3
votes
1answer
34 views

Higher Asterisks in lstlisting environment

The project I'm working on right now is a general template for documents that will contain code from an arbitrary programming language. Specifically, I'm trying to make a nice layout for code in the ...
1
vote
1answer
19 views

How can Listings ignore (some) indentations?

I am trying to explore writing a .tex in a 'indentation' style, like this: \documentclass{article} \usepackage{listings} \begin{document} Hello latex! \begin{lstlisting}[language=python, ...
2
votes
1answer
31 views

enclosing a lstlisting environment inside my own environment using matlab-prettifier

I've just started using matlab-prettifier. Since the line \begin{lstlisting}[style=Matlab-editor] is a lot to type, I created my own environment: \newenvironment{myMP} ...
1
vote
1answer
20 views

listings - How to format words of a external code file under a condition

I'm using listings to put a external code file in my document. I'm trying to customize its appearance to identify when the first character of a word is a digit and then change the color of this ...
1
vote
1answer
21 views

Cannot include courier into latex beamer listings

I have the following set up for my listings: \documentclass[russian,pdf]{beamer} \mode<presentation>{} \usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[russian]{babel} ...
2
votes
0answers
31 views

How to justify escaped proportional text inside monospaced/fixed listing?

I have a fixed column listing on which I have escapped to LaTeX to write a proportional bit of text. The following pic illustrates what I have: On the green box, the proportional text have ...
1
vote
1answer
25 views

Cannot emphasize underscored words in listings

I declared an emphasis mode that underlines and colors words in red, as follows: \lstset{columns=fullflexible,basicstyle=\vttfamily,emph={\color{red}\underline}} However, when using it in a ...
9
votes
1answer
2k 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)?
1
vote
0answers
39 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 ...
5
votes
1answer
61 views

make all values of the JSON format red

I am using the latex beamer and trying to get the true value of the flag key in the JSON format red too but I am just getting it black as shown in the screen shot below. How can I get it red too? ...
14
votes
1answer
11k views

How to improve listings display of JSON files?

I was wondering if there is a good way for JSON files to be listed with the listings package. The only language definition I could come up with, is this: \lstdefinelanguage{json} { ...
1
vote
1answer
28 views

Give side by side minipages one (shared) caption instead of two

I have two lstlisting areas that are shown side by side by using two minipages: \noindent\begin{minipage}[t]{.43\textwidth} \begin{lstlisting}[...]{part1} // Code \end{lstlisting} ...
2
votes
0answers
29 views

How to put the caption below the listing? [closed]

When I use a simple caption, tex puts it above the listing \begin{lstlisting}[caption={My Caption}] \end{lstlisting} If I use \captionof, caption goes below the listing, but paragraph for next ...
3
votes
1answer
100 views

Getting WinEdt to ignore lstlisting

WinEdt 9.0 gives me incorrect TOC in its side panel when I use listings package to illustrate a piece of LaTeX code: How can I get WinEdt to ignore \begin{lstlisting} ...\end{lstlisting} (and ...
19
votes
1answer
232 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 ...
0
votes
1answer
21 views

Determine if inside \lstinline or ordinary lstlisting environment

My editor requires me to have a non-white background in my code listings. In order to make my code listings look nicer, I use the literate setting of listings to change underscores (which are very ...
4
votes
1answer
26 views

Lstlisting duplicate caption

I've been trying to insert the code to my LaTeX document. I used this piece of code: \begin{lstlisting}[label={lst:rws}, captionpos={bottom}, caption={Pseudo-code of RWS Selection}] r = Random(); /* ...
4
votes
0answers
39 views

Exception from code syntax highlighting in listings

EDIT: The question is not really relevant for me any more, I decided to instead use the highlight package in R to export Code as LaTeX output. This still requires manual modifications, but at least I ...
4
votes
1answer
30 views

How to force \lstinline to add a line break

I have an inline piece of code in my main LaTeX document that I have included using the \lstinline command: \lstinline{template<class UIntType, UIntType a, UIntType c, UIntType m> class ...
1
vote
1answer
95 views

How to prevent page break between listing caption and code?

How to prevent page break between listing caption and code (see the picture)? Minimal example illustrating issue: \documentclass[a4paper, 12pt, oneside]{report} \usepackage[a4paper, left=3.5cm, ...