{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
24 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}} ... ...
3
votes
1answer
102 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; ...
4
votes
1answer
28 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 ...
0
votes
1answer
25 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
18 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 ...
3
votes
1answer
91 views

Isolate Latex Environments

I want to build a framework for sharing latex mathematics exercises. When trying to assemble exercises from different authors into one "homework assignment", I have a problem. How can I deal with ...
6
votes
1answer
49 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 ...
4
votes
1answer
24 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 ...
2
votes
1answer
58 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 ...
2
votes
1answer
44 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 ...
5
votes
1answer
32 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 ...
4
votes
1answer
23 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 ...
3
votes
2answers
25 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 ...
2
votes
1answer
28 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
1answer
31 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
22 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
36 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} ...
3
votes
2answers
143 views

Problem with gobble listing option inside a tcblisting

Please, compare next two listings inside a beamer frame. The upper one is made with listings and the second with tcblisting (form tcolorbox). Both use same source and listing options. Following ...
0
votes
0answers
29 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 ...
2
votes
0answers
34 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} ...
2
votes
1answer
24 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 ...
0
votes
0answers
24 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
1answer
70 views

\itshape is to \textit as ?? is to \mathit?

In the following example, I've set listing's basic style to \itshape. However, the + operator is italicized, and so are the parentheses: \documentclass{article} \usepackage[english]{babel} ...
4
votes
2answers
85 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 ...
5
votes
0answers
19 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 ...
16
votes
3answers
8k views

How to insert code with accents with listings?

I'm trying to insert source code in LaTeX with using listings, but my code has accents and pdflatex gives me this error: Unicode char \u8:�\expandafter not set up for use with LaTeX. This is a code ...
0
votes
0answers
15 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 ...
1
vote
1answer
42 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
1answer
28 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 ...
19
votes
1answer
240 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 ...
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} ...
1
vote
0answers
40 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} ...
3
votes
0answers
36 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
61 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
82 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
219 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
198 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} ...
3
votes
2answers
51 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 : ...
3
votes
1answer
40 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
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 ...
2
votes
0answers
33 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
20 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
15 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
21 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
27 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
584 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
41 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
545 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 ...