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

How can I get rid of indentation before my code? [duplicate]

My Javascript code has a large amount of whitespace in its block in the output pdf file. How do I get rid of this without un-indenting my latex code? Thanks in advance. \documentclass{article} \...
3
votes
1answer
41 views

error using tcblisting inside longtable, no error inside tabular.

I was testing a nice solution provided in this answer how-to-crop-background-color-in-listings-to-the-longest-line-in-the-code However, I happened to be using longtable and not the standard tabular. ...
9
votes
2answers
99 views

Listings for plain tex

Is there a package to produce syntax-colored blocks of source code in plain TeX ? A listings equivalent ? Or (maybe) some macro to produce a colored tex input for some given source code ? Is it ...
3
votes
0answers
42 views

Latex complains about missing $ from listing of source code

This is the smallest example I can come up which shows this problem. Latex complain about missing $ and the error is pointing to a line in code listing ! This problem can be resolved by doing 3 ...
5
votes
1answer
108 views

how to crop background color in listings to the longest line in the code?

listings package allows one to put background color to the code listing. The problem is that the background color extents to the as large as the text area the code listings happened to be in. This can ...
4
votes
1answer
48 views

Square brackets in listings caption

How to add square brackets as a caption in a listing? I tried putting caption inside of "{}", but then the output is quiet weird. \documentclass{article} \usepackage{listings} \begin{document} \...
3
votes
1answer
18 views

listoffigures not working properly

I have noticed that in my document the \listoffigures and probaly \listoftables are not working properly. There is no space in between the number of the figure and the text in the list. Also, if the ...
5
votes
1answer
35 views

Inline escaping {{ myVariable }}

How to escape Mustache notation inline for example: This is a Mustache placeholder {{ myVariable }} that will output myVariable. This seems to be causing errors: \lstinline{ {{#if}} ... {{else}} ... ...
0
votes
1answer
28 views

lstinputlisting shows wrong number in reference

I'm pretty new to LaTeX, so please be a little patiently with me. So here is my problem: I got some text and there i want to reference a little bit code shown in the next line. What i tried so far: ...
2
votes
1answer
33 views

adding frame=none to lstlisting options in \lstdefinestyle gives error with tabular

lstlisting has an option called frame= But when I use the frame=none in \lstdefinestyle and put the lstlisting command inside tabular or longtable I get an error Forbidden control sequence It ...
4
votes
2answers
40 views

Single character keywords/operators with no spaces with listings package

I want to add a very simple macro language to listings. It uses single-letter keywords/operators, with no whitespace between. I can't see how to make keywords that don't require some kind of separator ...
4
votes
1answer
32 views

Why making program listing with ACM style produces extra narrow caption?

I want to prepare a manuscipt for an ACM journal. The program listing appears with extra narrow caption, see at bottom. It is hard to believe, I found incompatility with package 'listings', in an ACM ...
4
votes
1answer
30 views

How to set macrocode using the listings package

When writing a dtx file, is it possible to typeset the code samples (i.e., everything enclosed in a macrocode environment) using the listings package? For completeness, here's Joseph Wright's model ...
5
votes
1answer
45 views

Using Bash listings to bold variables and functions

I am using the listings package to show some sample bash script lines; however, the otherkeywords argument is giving me trouble. As the listings documentation states: If one keyword is a ...
2
votes
1answer
32 views

why is adding subdepth package makes lstlisting give Matlab error loading file?

If I have a dollar each time I find a conflict between Latex packages I would be a rich man. I added \usepackage[low-sup]{subdepth} and now I am starting to get errors from matlab-prettifier when ...
3
votes
2answers
28 views

Source code listing using \lstinputlisting - prevent other floats splitting it up

I am using the listings package to take an external PHP file and display it as a code listing in my document. It spans several pages (fine) but unfortunately there are other floats which end up being ...
3
votes
1answer
33 views

How can I make a reserved word loose its special formatting in listings?

Consider the following example. \documentclass{minimal} \usepackage{listings} \begin{document} \begin{lstlisting}[language=sh] cat foo.c cat.c bar.c echo The cat ate the cheese \end{lstlisting} \...
0
votes
1answer
31 views

Listings titles in List of Listings

I have a question analogous to this one, but for listings instead of figures. In my TeX file, I have multiple listings defined as follows: \begin{lstlisting}[caption={A really, really, really, ...
3
votes
1answer
38 views

How to number program listings like figures

Is there a way to number program listings like figures and reference them? I have the following mwe: \documentclass{article} \usepackage{hyperref} \usepackage{listings} \begin{document} \autoref{...
2
votes
1answer
39 views

How to make Latex recognize individual keywords in lstlisting without delimiter?

I want to add a few lines of G-Code (used for 3D-printing) to my latex file using the listing package. Unfortunately, g-code is not supported as a language and therefore has no highlighted commands. I ...
5
votes
0answers
23 views

lstlining changing font in moredelim

lstlisting is not using the identifierstyle font inside of the moredelim that makes the identifier name red. In the example, the first varname is in tt font but the second is in roman. I want the ...
0
votes
0answers
26 views

Lining up character codes beside source code

I would like to create something similar to this structure: for (int i=0; i < 10; i++){ FOR05 System.out.println("Hello world"); OUT10 System....
4
votes
2answers
95 views

Why is text turning white (possible scope leak?) after page break and listings + tcolorbox + xelatex?

I had a very difficult time pinning this problem down, because it only exists when certain page-breaking conditions occur. Problem Text after environment mysteriously turns white under some ...
6
votes
1answer
51 views

highlight text between selector without highlighting nor deleting the selectors [duplicate]

So I'm trying to render something beautiful for my PHP code using the \lstdefinestyle command. I think the basic configuration is good, but I would like to highlight the function name to render it in ...
2
votes
0answers
35 views

Empty list of listings [duplicate]

How can I add my Listings to the \lstlistoflistings?! Here is the Listing with example: \documentclass[a4paper,11pt]{article} \usepackage[ngerman]{babel} \usepackage[T1]{fontenc} \usepackage[utf8]{...
3
votes
1answer
24 views

Listing with overlay only next to content not to title

I got this listing with a gray bar on the left side with line numbers in it. I want it not to be showen next to the title. Here is my code: \usepackage{listings} \usepackage[many]{tcolorbox} \...
2
votes
1answer
35 views

Title with counter for Listings

I am trying to add a title with counter to my Listings. This is what I have so far: \usepackage{listings} \usepackage[many]{tcolorbox} \tcbuselibrary{listings} \newtcblisting[auto counter,number ...
1
vote
0answers
49 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} \usepackage{...
3
votes
0answers
51 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 ...
3
votes
2answers
73 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 : \documentclass[...
3
votes
1answer
44 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
61 views

Latex lstlisting: stringstyle not working

I defined my own language Drools and I want that the words between "" have the color red. I used stringstyle to do that but this doesn't work. Am I forgetting something because I couldn't find any ...
0
votes
0answers
17 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 ...
0
votes
0answers
27 views

minor missing star character incompatibility between lstlisting and mdbch mathdesign

Minor problem I ran into: Using \usepackage[mdbch]{mathdesign} \usepackage{listings} \lstset{language=C} and then look at the output of a /* **** */ C comment. I think it is because mdbch does ...
2
votes
0answers
35 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: \definecolor{...
0
votes
0answers
21 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 ...
4
votes
1answer
17 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} \usepackage{...
2
votes
1answer
29 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 ...
3
votes
1answer
30 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? ...
5
votes
1answer
90 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 "Code-...
3
votes
1answer
53 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
28 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?
1
vote
0answers
26 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
0answers
35 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 ...
2
votes
1answer
39 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, labelfont=...
1
vote
1answer
29 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
40 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
1answer
34 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} {\begin{samepage}\begin{...
1
vote
1answer
29 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 ...
3
votes
0answers
46 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 ...