{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

17
votes
0answers
538 views

TeXLive and MikTeX behave differently in handling BOM

It is a followup of my answer that has been converted to comment (click) posted several decades ago. Shortly speaking, MikTeX does not remove leading BOM but TeXLive does as shown in the following ...
6
votes
0answers
57 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
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 ...
4
votes
0answers
83 views

How to let minted break across pages but keep the caption together with the end of listing?

I want to create a listing using minted that has background colour and can be split across pages. The usual advice in that case is to use the mdframed environment and I have written a command that ...
4
votes
0answers
137 views

How to emphasize or highlight single words in comments in listings?

I'd like to highlight single words (or phrases) in the comments of C files displayed by the listings package. Using the emph key does not work in comments (apparently listings is too intelligent in ...
4
votes
0answers
270 views

\inputminted: distinct file parts in one listing (equivalent to linerange in listings)

I want to include code from a file into my document. However, several distinct line ranges should appear in the same listing. Also, I want to use gobbling, and it would be nice to include some blank ...
4
votes
0answers
56 views

Add vertical space only if there is no pagebreak

I'd like to define a new listings environment where the listing has an \hrule before and after the listing itself. In order to do this I've defined this environment: \lstnewenvironment{haskell}[1][] ...
4
votes
0answers
118 views

Unicode and listings - still no luck

Although there are already some discussions on this issue, I can't get any of the proposed solutions to work for me. Take this document and compile it with xelatex: \documentclass[12pt,a4paper,...
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 ...
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
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 ...
3
votes
0answers
76 views

How can I highlight certain words in minted with different colors?

I would like to highlight some specific words inside the minted environment when using beamer. \documentclass[14pt]{beamer} \usepackage{minted} \begin{document} \begin{frame}[fragile]{} \begin{...
3
votes
0answers
367 views

Syntax Issues with lstdefinelanguage

I have some issues defining a new language for the lstlisting package. The source code shall look like this in the end: And my latex definition looks like this atm: \documentclass[]{article} \...
3
votes
0answers
83 views

How to add my listings to the table of contents?

I am using the thesul class. I would like to add my listings to the table of contents. I found a way to do that by using the \addcontentsline{toc}{spsection}{Listings} command: \tableofcontents \...
3
votes
0answers
83 views

minted or listings input a file between markers

Is it possible, using the minted or listings package to format a file between or till a certain textual marker automatically. E.g. consider a source file: code code //marker code ... //end marker ...
3
votes
0answers
111 views

Drawing arrows using tikz package (fine tuning coordinates)

I am making some lecture slides for my class and sometimes I need to label the different components of the C/C++ program. For this I have referred to the post How can I draw arrows within a listing to ...
3
votes
0answers
46 views

How to get listings package line number behavior of v1.3 in v1.5?

In the listings package v1.3, when including lines from a file, the numbering is that from the file, even if lines are omitted (absolute numbers). But in v1.5, the numbering ignores the location in ...
3
votes
0answers
261 views

How to use same font-style with escapechar in lstlisting?

Original Question I want to highlight something inside a C++-comment in a code-listing. \documentclass[a4paper, 12pt]{article} \usepackage{color} \usepackage{listings} \definecolor{light_gray}{rgb}...
3
votes
0answers
146 views

Can I use “moredelim” in package “listings” to fetch a regular expression?

I would like to know if it is possible to use the listings package to highlight regular expressions in order to make them look like a normal string object. Note: The syntax of a regexp is not context ...
3
votes
0answers
340 views

fancyvrb + listings inside a list

I'm trying to put Verbatim environment from fancyvrb package, with activated interface to listings package, inside enumerate environment. When Verbatim environment is first element in \item, item's ...
3
votes
0answers
118 views

Listing sourcecode - two columns, associations with colored background

I stumbeled over a way of formatting sourcecode in a book I am currently reading. It looks like this: So basically we have a following structure: There are two columns. Left column contains the ...
3
votes
0answers
557 views

listings: How can I highlight Makefiles?

I am trying to typeset a makefile using listings. Now I would like some differential highlighting, e.g. for variables and ordinary commands in the target body. In this snippet, want to have different ...
3
votes
0answers
130 views

Relatives/absolute path for listing with subfiles

I have problem with path management. Let me explain you: I work with subfiles that are arranged in this way: REPORT --Main.tex --lab1 ----Matlab ------CodeLab1.m ----Report ------Report_P1_1.tex --...
3
votes
0answers
379 views

How to make listings display characters special characters

I am trying to show a directory structure of a tree using the listings package like so: ├── controllers │   ├── application_controller.rb what I get looks like this: controllers ...
2
votes
0answers
62 views

Code crashes on Mac OSX, not linux?

Using TexWorks. 2 people using Mac OSX, one El Capitan, one Yosemite. 1 person using linux. The following code works on linux: \begin{tabular}{|l|l|l|} \hline Scalar form & Meaning & ...
2
votes
0answers
34 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{...
2
votes
0answers
29 views

Spaceing Issue with listings

I am having a bit of trouble putting python code into a latex document using listings. The code is appearing with a large indent on the left so that it has to go onto multiple lines. Here is an ...
2
votes
0answers
70 views

How to fix “Dimension too large” error with lstlisting

I use listings as the verbatim enviroment. However, I get the "Dimension too large" error with very long lines. The following is a sample code. \documentclass{article} \usepackage{listings} \begin{...
2
votes
0answers
28 views

Using Listings Package: the Colour of the Text After the Listing is the same as that of the Identifiers Inside the Listing

So I have some LaTeX which looks like \usepackage{graphicx,bm,times, hyperref, amsmath, listings, xcolor, enumitem} \lstset{language = C++} \lstdefinestyle{customcpp}{ backgroundcolor=\color[rgb]{...
2
votes
0answers
50 views

tex4ht and listings: lines don't break when using escapeinside

This is the first I'm posting a question. So, I hope I don't do anything wrong. I've tried to get HTML from my latex document by using tex4ht. For cross-referencing within the lstlisting environment, ...
2
votes
0answers
128 views

lstlisting with sublistings and captions and floating environment

I try to create a floating environment with a layout similar to this: _____________________ ___________________ | | | | | | | | |...
2
votes
0answers
145 views

Problems with PHP tags (and code) in listings with HTML

I want to highlight PHP and HTML in the same code. In my attempts I experience three challenges: Seems like listings treats <?php and ?> as one large HTML tag. How to tell listings that the &...
2
votes
0answers
45 views

Listings - Getting the colors right for custom language

I have lots of bookkeeping transactions that I would like to typeset in a color coded format. I am using the listings package to accomplish what I want. I tried the following code. \documentclass[...
2
votes
0answers
59 views

Typeset code within a simple macro?

I want to use a macro to typeset programming code with the usual characteristics (particularly lines should be obeyed - this is the most important issue; highlighting and such stuff is - for now - not ...
2
votes
0answers
286 views

Python console code with minted

I am using minted to highlight source code in my document. I have defined \definecolor{codeyellow}{RGB}{255,251,204} \newminted{python}{linenos,breaklines,frame=lines,bgcolor=codeyellow} in the ...
2
votes
0answers
33 views

Indentation marker for listings

I'm currently writing a document that contains several code samples. I included them as lstlistings and played around with the colors and everything, so they loot quite nice now. My only problem is ...
2
votes
0answers
80 views

How to highlight php code in a HTML document and the document itself?

how can I highlight php code in a HTML document and the document itself? Example: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8"> <title>Title</title&...
2
votes
0answers
78 views

How to mix LaTeX listings numbering with custom characters?

In order to display a command-line GAP session using the listings package, I need to distinguish between input and output. I tried to do this by appending a marker in front of every output line, so ...
2
votes
0answers
34 views

Listings package and forcing inclusion of empty lines at end of line ranges?

By default, the listings package suppresses empty lines at the end of the file, and this behavior can be switched off with the option showlines. However, listings also suppresses empty lines at the ...
2
votes
0answers
94 views

linewrap included Javafile with lstinputlisting

I've spent few days already trying to properly include a Java source file dynamically in a tex file. The text is included. However the lines don't wrap. The following is the "srinked" project \...
2
votes
0answers
45 views

XeLaTeX Listings package tabsize not correctly shown

I'm using XeLaTeX and I used the listings package to display some source code. In \lstset I set the tabsize to 4: \documentclass[a4paper, 11pt]{article} \usepackage{filecontents} \begin{filecontents*}...
2
votes
0answers
240 views

Use dollar sign in verbatim environment within auctex

I am using something similar to the following, \documentclass{article} \usepackage{listings} \lstnewenvironment{shellsession}[1][] {\lstset{language=bash basicstyle=\small\ttfamily, numbers=...
2
votes
0answers
202 views

Different display of listing's background (Texmaker internal PDF viewer & Adobe Reader)

I have following code: \documentclass[10pt,a4paper]{article} \usepackage{color, eso-pic, tikz} % Create commutative diagrams \usepackage{listings} \definecolor{light-gray}{rgb}{0.95,0.95,0.95} \...
2
votes
0answers
241 views

Listings: color numbers only out of keywords

With the listings package, I would like to color the integers out of strings and comments and out of keywords too. The question for coloring numbers has been asked several times. Some answer handle ...
2
votes
0answers
152 views

Code alignment using listings with proportional fonts is poor

I would like to typeset code using proportional fonts and the listings package, but no matter what I do, alignment is always off. Here is an example in Java (taken from Wikipedia): \documentclass[...
2
votes
0answers
119 views

Different colours for each argument and value in listings

This recent question (Print blue brackets in one language and black in another) made me come up with (up to) two more questions regarding the listings package: Is there an option similar to opstyle ...
2
votes
0answers
142 views

How can I apply different custom caption styles to different listings?

In the MWE below, is it possible to define different caption formats for the two listings? In the example the first listing should use a blue caption background (like it is now) while the second ...
1
vote
0answers
27 views

Syncing Python code with LaTeX document using Listings package

I have a Tex document that uses the listings package to print a Python source code. I also want to separately print certain Python function signatures in my document. I do not want to use the line ...
1
vote
0answers
31 views

“This file requires `listings.sty' version 1.6”

I have written my paper in LyX, and exported to LaTeX. When I compile on the journal website, the resulting pdf says: This file requires `listings.sty' version 1.6. You have a serious problem, ...
1
vote
0answers
27 views

Two different listings at the same time

I would like to show two different pieces of listings at the same time in a slide. With the following code the second listing only shows up at the end, while I would like it to alongside with the line ...