{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

2
votes
1answer
2k views

Syntax highlighting for different programming languages [duplicate]

In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package: \lstset{frame=tb, language={[Visual]Basic}, aboveskip=3mm, belowskip=3mm, ...
7
votes
1answer
672 views

Strange error when combining Beamer, Animate, Tikz and Listings

I'm working on some slides where I show how code is actually executed in Java. Therefore I'm working with the animate package to generate animations. Without going into details, I've written a macro ...
7
votes
1answer
17k views

How to change fontsize in lstlisting without losing bold syntax highlighting?

If I load the listing package to set nice code and change the font size (like suggested there: Shrinking monospace style for listings package), I lose the syntax highlighting, because the font does ...
1
vote
1answer
475 views

Highlighting a Chunk of Code within a lstlisting by specifying the line number

This question in somehow related to http://stackoverflow.com/questions/1304315/highlighting-a-chunk-of-code-within-a-lstlisting but not exactly the same. I want to make some slides with animation ...
3
votes
1answer
435 views

How to suppress automatic conversion of “<=” inside lstlisting/lstinline?

I have the following LaTeX code: some text \lstinline!u <= 1! some text In my output, the two characters <= get automatically joined to form a single "less-than-or-equal" chararacter (i.e. ...
4
votes
1answer
4k views

Default value for basicstyle in lstlisting

I have most of the code in Python, which renders very nice with this simple configuration of lstlisting At a certain point I have to include an XML file, so I switched to language=XML but it renders ...
4
votes
1answer
652 views

Ignore keyword in Listings

Consider the following minimal example: \documentclass{standalone} \usepackage{listings} \begin{document} \begin{lstlisting}[keywordstyle = \textbf, language = SQL, deletekeywords = {time}] create ...
1
vote
0answers
96 views

spacing before scope resolution operator [closed]

I'm new to LaTeX and I have encountered a problem with the listings package, I have a space before the :: operator of C++ . after reading lstlisting with c++: spaces around scope resolution operator ...
3
votes
1answer
1k views

Removing small gaps between lines in LaTeX lstlisting output

Whenever I set a somewhat dark background color in a code listing it becomes obvious that there are small line separations, these of course stay white making the overall appearance not desirable. My ...
0
votes
1answer
217 views

wrap listings package - Problem with verbatim argument

I would like to define a command that wraps a lstlisting environment in some other environments (esp. a minipage). I understand that working with verbatim arguments is a difficult task. I tried the ...
2
votes
2answers
129 views

How to prevent a listing from straddling two pages

If I have a small listing that happens to be at the end of a page, how can I force LaTeX to place it on a new page so that it does not straddle two pages, which looks ugly for a small listing.
4
votes
2answers
476 views

Spaces inside Cyrillic listings

I want to include source file using listing package. In that file there are some cyrillic symbols in comments. I setup listings like: \lstset{extendedchars=\true,basicstyle=\ttfamily} And in ...
5
votes
1answer
1k views

Make lstlisting honour baselinestretch

I have to use lstlisting instead of Verbatim in a particular case, because math escape doesn't work properly with the latter. I managed to have both look the same, but lstlisting ignores my ...
3
votes
1answer
954 views

Using math mode escapes with listings enabled fancyvrb

I am trying to escape math mode within Verbatim, using this answer. This works fine, until I use the listings package with fancyvrb=true \documentclass{article} \usepackage{fancyvrb} ...
42
votes
2answers
4k views

minted vs. texments vs. verbments

Regarding the typesetting of syntax-colored source code, I know that listings is inferior because it doesn't utilize a full lexer. Instead the Python-based solution is recommended. It seems there are ...
4
votes
1answer
1k views

Subscript and superscript in lstlisting?

I need to use subscript and superscript in a lstlisting block. lstlisting can replace strings by Latex commands, but is it also possible to replace some kind of regular expression like ...
2
votes
2answers
3k views

\ttfamily is too bold for me

I use the following settings for my listings: \lstset{ %basicstyle=\ttfamily\tiny, % small basicstyle=\ttfamily\scriptsize, % middle } But the font in the listings is too bold for me. I tried a ...
6
votes
1answer
874 views

Why doesn't \lstinline work in table column?

\documentclass[14pt]{extarticle} \usepackage{xcolor} \definecolor{deepblue}{rgb}{0,0,0.5} \definecolor{deepred}{rgb}{0.6,0,0} \definecolor{deepgreen}{rgb}{0,0.5,0} \usepackage{listings} ...
4
votes
2answers
470 views

Right-align the prebreak symbol in a listings environment

I’m using the breaklines and prebreak option with listings, but I find it visually not very pleasing that the prebreak-symbols are not vertically aligned. I’d prefer if they were all on the very right ...
4
votes
0answers
82 views

lstlisting and this symbol : █ [duplicate]

I want to know how to print this symbol "█" that I have in an external file loaded with listing. Or at least how to print it with \something, cause it's not a blackbox. ...
1
vote
1answer
195 views

Displaying (source)Code in research article [duplicate]

I have this urgent need to display two pieces of code side by side for comparison in my article. Displaying a code, I've couple of requirement Should indent properly Output should be syntax ...
3
votes
1answer
204 views

Globally set the justification in a framed box

I want to show the text from a Python Interpreter in a Windows console. This should be plain text (like you see in a command line terminal). I also want to show Python code snippets with highlighting. ...
4
votes
1answer
988 views

Set font size in pt in a listing

How can I set the basicstyle option to force the use of 9pt fonts in listings regardless of the default size of the document? Using 9pt fonts is a requirement of the guidelines that I am using, so I ...
0
votes
1answer
122 views

Listings package not working properly with Exam class

When I gave my code in the exam class like \begin{parts} \part \begin{lstlisting} echo The date is $date \end{lstlisting} \part \begin{lstlisting} echo The date is $(date) \end{lstlisting} ...
6
votes
1answer
169 views

listings package and latex3 variable

I'm trying to change a custom environment from a lot of optional parameters to a ;-separated list (using this answer as a template and writing its main functionality as a latex3 macro). The macro ...
1
vote
1answer
506 views

Minted cross reference line

I used to use listings a lot but minted+pygmentize has outstanding output. However, there are a few features from listings that are hard to find in minted, like having the line numbers on the right. ...
3
votes
1answer
403 views

Moving from fancyvrb to listing – need to reconstruct my font settings

I have happily used the fancyvrb package with the Verbatim environment so far, but I want to change my figures to use the listing package with the lstlisting environment in order to have bold-faced ...
2
votes
1answer
1k views

Code in \lstlisting breaks document (compile error)

I want to show a JSON object in my document. If I do the following, it works: \begin{lstlisting} { "id": "5", "key": "discardedCard" } \end{lstlisting} But if I extend the code to the ...
3
votes
1answer
925 views

How to use multiple arguments in \lstnewenvironment

How can I have more than one optional argument to be passed to \lstnewenvironment? I only need a fixed number of options and all will be present. I want to pass the frame type and font size as ...
2
votes
1answer
831 views

How to correctly use equal sign in keywords for listings?

I work on a listings code style for HTML5. The style looks quite good but I have a little problem with the equals sign. I defined the equals sign as a keyword: ndkeywords={=, ... } This will cause ...
9
votes
2answers
640 views

Two code blocks working syncronously

I need two code blocks in my beamer frame. One will be the code and other will be the output for each line of code. I want to uncover each code line and corresponding output line. So, first it will ...
3
votes
1answer
700 views

Problem highlighting listings in beamer

I'm using listings inside beamer to typeset some Octave code. Because I want to apply overlay specifications to parts of the listing as I go through the slides (for highlighting purposes), I'm ...
5
votes
1answer
665 views

How can I create wrapper macro for lstinline?

Using \lstinline I can include inline code snippets in a paragraph. I would like to provide a macro that selects formatting, etc, for lstinline so I can just do, say, \codeinline{snippet}. I had ...
1
vote
0answers
40 views

\lstlistoflistings does not add spaces by chapter [duplicate]

I'm quite new in LaTeX and ended up with this problem: I'm using list of tables and list of lstlistings (\listoftables, \lstlistoflistings), both numbered by chapter. List of tables does add spaces ...
4
votes
1answer
118 views

listings package : highlight word composed by an alphabetic and a numeric part

I would like to highlight several keywords with an alphabetic and a numeric part with different color. My problem is the number of keywords can become huge from r0 to r191 for example. And I have ...
4
votes
1answer
1k views

Why keywordstyle is not taken into consideration no bold, no red color?

When I have this code with .sty file from here \begin{lstlisting}[language=Go, firstnumber=1, captionpos=b, caption=Golang, label=amb] // You can edit this code! // Click here and start typing. ...
5
votes
1answer
794 views

Line breaks in listings with long lines

This is a follow-up question to Line breaks in listings My MWE with a very long line demonstrate the problem: \documentclass{report} \usepackage{listings} \lstdefinelanguage{text}{} ...
2
votes
1answer
405 views

How to define HTML keywords in \listings

I'm working on the implementation of a HTML5 code style for \listings. Currently I have the problem that there are different ways to define HTML tags. In my example, I don't get /p in ...
4
votes
1answer
424 views

Command to insert filename in caption of a listing

I would like to have a command to insert listings that contain the filename in the caption. This works well as long as there is no "_" etc. in the filename. I also tried the suggestion from a ...
3
votes
1answer
1k views

minted list of listings and TOC conflict

I am using minted for source code highlighting. I want a List of Listings, and I want the List of Listings to itself have an entry in the main Table of Contents. I thought I could do this with ...
3
votes
1answer
896 views

How to use angle brackets for a keyword in \listings?

I've got a code of a HTML website that I want to show in my LaTeX document. The problem is, that the HTML code has a tag called <canvas> and the JavaScript code inside the HTML document has a ...
5
votes
1answer
1k views

How to use alsolanguage in \listings package?

I defined keywords for the JavaScript programming language and HTML. I have read that it is possible to use the keywords of both languages in a \listings code snippet. But in my example, the ...
19
votes
2answers
9k views

\listings code style for HTML5 (CSS, HTML, JavaScript)

I would like to create a code style for HTML5 that can be used with the \listings package. An HTML5 document consists of three languages: CSS, HTML and JavaScript. That makes the whole thing a bit ...
3
votes
2answers
2k views

Keyword-Highlighting of C++ using Listing

I have a little problem in my settings. I cannot locate the error and need some additional eyes to tell me where I should look. I use listing to show my c++ code but when I try to add additional ...
3
votes
1answer
418 views

regular expression in listings

I'm looking for a possibility to find a way to colorize data. If a text starts in a line with XYZ from that point until the next blank line the text should be set in a defined colour. With the comment ...
2
votes
1answer
859 views

How can I typeset Greek letters in listings?

Is it possible (and if yes, of course how) to use Greek letters within lstlisting (of the listings package)? However, \epsilon, for instance, puts of course exactly that and not a Greek epsilon. I ...
3
votes
1answer
2k views

LaTeX source code listing with less space between characters [duplicate]

I want to write shell Code in my LaTeX document. I'm using the listings package, with a code sample adapted from Tormod Fjeldskår: \documentclass{report} \usepackage{color} \usepackage{xcolor} ...
3
votes
1answer
582 views

odd displays of accentuated characters in lstlisting environment

when i try to write accentuated characters (éà...) in a lstlisting environment, hence : \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{xcolor} ...
2
votes
2answers
1k views

Multiline listing within multicolumn row

I have a problem putting a listing (using lstlisting package) within a table. The problem is that I want to put a multiline listing in a row taking 2 columns. The following minimal example shows ...
3
votes
1answer
794 views

Changing lstlistoflistings title [closed]

I'm having difficulty getting the list-of-listings section to display the proper title, it simply says "Contents" no matter what sort of changes I make. Here is the command I put in the preamble at a ...