{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

7
votes
1answer
3k views

“Display math should end with $$” error

I'm trying to write math in a code listing, like so : \documentclass{article} \usepackage{listings} \begin{document} \begin[mathescape]{lstlisting} $\infty$ \end{lstlisting} \end{document} I get ...
3
votes
0answers
347 views

Regular expressions in listings [closed]

I'm looking for a possibility to use regular expression in listings. I'd like to highlight each N thats followed by 4 decimal numbers for example N1234. How can I achieve that? Here is an example: ...
4
votes
1answer
290 views

Use pxfonts in listings only

I really like the pxfont package for displaying code in listings. I would usually just do this to load pxfont for the entire document; \usepackage{pxfonts}. However, this time I am required to use a ...
2
votes
1answer
648 views

Minted: customise listing name? [duplicate]

How do I customize listing name: Listing 1: thing -- when I use minted? Here's an MWE: \documentclass{article} \usepackage{minted} % \renewcommand{\lstlistingname}{Something} % doesn't work! ...
5
votes
2answers
136 views

How to combine listing and figure into a single figure?

I am using package listings, and I would like to combine a listing and a figure into a single float. As an example, I am using listings as follows: ...
2
votes
1answer
278 views

\lstlistoflistings doesn't have enough room between numbers and title

I'm using the \lstlistoflistings command from the listings package to generate my list of code samples. Unfortunately there isn't enough room between the number and the code listing title. See the ...
2
votes
0answers
367 views

LaTeX source code listing like in professional books for \lstinputlisting [closed]

Found this topic: http://stackoverflow.com/questions/741985/latex-source-code-listing-like-in-professional-books and I'm very satisfied with this soulution, it looks just great in a generated pdf ...
1
vote
1answer
181 views

lst include has first line indented [duplicate]

When I'm including a source file, by way of \lstinputlistings{file/path/to/file} However, This results in the following below: Why is the first line not being formatted correctly? And how do i fix ...
6
votes
1answer
2k views

Adding words to lstlisting for Python langaue

I wish to add a few keywords to some python code inserted into a latex document. I want to make 'True' & 'False' appear yellow and also some module calls such as 'ttk' appear red. I have tried ...
1
vote
1answer
312 views

lstlisting: how to align highlighted code

I want to define a couple of new commands in order to highlight parts of my code (this is actually for a trace dump, not for a programming language). My problem is that I can't seem to make the ...
2
votes
1answer
1k 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, ...
6
votes
1answer
607 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
15k 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
376 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
333 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
3k 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
438 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
92 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
194 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
124 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
409 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
852 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} ...
40
votes
2answers
3k 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
2k 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 ...
5
votes
1answer
667 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} ...
3
votes
2answers
368 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
79 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
183 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
167 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
678 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
116 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
162 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
447 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
356 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
785 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
632 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
601 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
571 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 ...
4
votes
1answer
545 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
112 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
870 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
723 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
351 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
350 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
859 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 ...