{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

4
votes
2answers
585 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: ...
11
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]{>}{<}, ...
4
votes
1answer
47 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 ...
17
votes
1answer
548 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 ...
3
votes
1answer
42 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
27 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
318 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
74 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
34 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
23 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 ...
2
votes
1answer
32 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, ...
4
votes
1answer
48 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
22 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
32 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
24 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 ...
2
votes
1answer
30 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} ...
3
votes
0answers
37 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 ...
2
votes
1answer
31 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 ...
6
votes
1answer
98 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
12k 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} { ...
2
votes
0answers
35 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
104 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 ...
1
vote
1answer
28 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 ...
5
votes
1answer
34 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(); /* ...
6
votes
0answers
50 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 ...
5
votes
1answer
33 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 ...
2
votes
1answer
114 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, ...
4
votes
1answer
34 views

Textcase, Listings, and Tilde

Consider the following MWE: \documentclass{scrreprt} \usepackage{textcase} \RequirePackage{listings} \usepackage[american]{babel} \begin{document} \MakeTextLowercase{A~B} \end{document} ...
1
vote
1answer
25 views

change caption of multiple listing styles

I want to have different listing environments, each with an own caption. My try was this (vorlage.tex): \documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch ...
3
votes
1answer
53 views

Conflict with unicode-math and listings

\documentclass{article} \usepackage{unicode-math} \usepackage{listings} \usepackage{fancyvrb} \begin{document} \lstset{fancyvrb} \begin{Verbatim}[commandchars=\\\{\}] \pm \end{Verbatim} ...
2
votes
2answers
48 views

Universal numbering for figures and lstlistings [duplicate]

I use ShareLaTeX for my thesis and I am facing a problem. I have used the following code to change figures' name to "Εικόνα" and lstlistings' name to "Εικόνα" too. ...
4
votes
0answers
43 views

Using the same line numbers in lstlisting on repeated beamer slide

In the following example, the line numbers on the second occurrence of the slide start from "3". But the references in the itemize item of the second occurrence of the slide show as "1" and "2" (i.e. ...
0
votes
1answer
28 views

custom listof not in content

This is the initial part of my thesis: \documentclass[12pt, a4paper, openright]{report} \usepackage{amsmath,amssymb,amsthm} \usepackage{graphicx} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} ...
0
votes
0answers
29 views

matlab-prettifier with fancyvrb-style of label / frame

I wonder how to make the frame line around caption of listing not being printed (top line being broken into two by caption in the middle) when matlab-prettifier (or listings package) are being used, ...
2
votes
1answer
23 views

listings breaking line despite breaklines=false

For some reason the listings package is breaking lines in the minimal working example below despite the fact that the breaklines=false option is set. \documentclass{article} \usepackage{listings} ...
0
votes
1answer
15 views

Excessive space in lstinline after using Reactivatenumber

I'm using the code presented by this answer (which itself is based on this) to suppress line numbers on some lines in lstlisting. This works, but after I use it, the spacing in lstinline is messed up: ...
10
votes
1answer
1k views

Is there an equivalent to \graphicspath for listings?

How can I make the \lstinputlisting to search for files in a given directory? I'm thinking of a solution along the lines of the solution to this question. I would like to have a solution like ...
4
votes
1answer
66 views

Listings & unicode characters

I want to write some unicode characters to lstlisting environment but they are displayed inline in the output which isn't what I am expecting. How can I make it work like standard characters? Thanks. ...
3
votes
1answer
61 views

listing background color not exactly the same

I like SO code section colors. so I wish to use it as code listings box background color. I use a screen capture tool to capture the code background color to png, then use GIMP tool to check the RGB ...
15
votes
1answer
1k views

Source Code Margin Comments

In the paper "Beautiful Code Compelling Evidence", by J.R. Heard -- Code is formated in a particular way which includes margin comments. I am looking for a way to do this as I think it is a very clear ...
0
votes
1answer
105 views

Any new packages for code listings

There are many questions (and answers) on this site about packages for showing listings of source code. But all the answers I have found are at least five years old, and I was wondering if any newer ...
3
votes
1answer
41 views

Using lstlisting with T2A

I would like to display a code listing using the package listings. It all work nice, except if I had the fontenc T2A. When I do, the listing stop being displayed using \ttfamily font and is shown ...
2
votes
2answers
139 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 ...
3
votes
1answer
3k views

“Wrong” numbers while referencing lstlistings in text

I'm using the lstlisting package to put sourcecode in my pdf file: \documentclass{scrbook} \usepackage{listings} \lstset{ % language=xml, basicstyle=\footnotesize, % the size of the fonts that ...
1
vote
0answers
50 views

XeLaTeX - special unicode characters

I found that work with unicode characters is a lot easier using xelatex than pdflatex, therefore I'd like to use it. Most of the content is displayed correctly but I have a problem with some special ...
2
votes
0answers
54 views

How to prevent parts of source from being automatically indented? [closed]

EDIT Rephrased question to be more abstract and less specific to only fragile-frames. Context: While recompiling a presentation, the process halted with err-msg file ended while scanning use of ...
7
votes
1answer
66 views

bold just one line inside of lstlisting

How can i bold just one line in this code? \begin{lstlisting} //Algoritmo 2 int f2 ( n ): local i , j , r =0; para i = 1 a n -1 para j = i +1 a n r = r + 2; ...
0
votes
0answers
25 views

Listings package does not break with my own class

I have created a class based on the article class so: \NeedsTeXFormat{LaTeX2e} \LoadClass{article} \RequirePackage{../../mypackage.sty} According to that, I have done following example document: ...