{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
39 views

Is there a solution to the differences between listings and verbatim [duplicate]

My code is here, \documentclass{article} \usepackage{listings,xcolor} \lstnewenvironment{code} {\lstset{language={Matlab}, lineskip=-1pt, belowskip=3pt, breaklines=true, ...
4
votes
1answer
69 views

How can I get a macro (e.g. for a function parameter) to gracefully expand within a listing?

I try to pass a parameter to code environment (lstlisting): \documentclass{standalone} \usepackage{listings} \def\parameter{home/Desktop/example_01/} \begin{document} \begin{lstlisting} \parameter ...
2
votes
1answer
62 views

How can I show only an arbitrary set of lines of my listing (e.g. lines 1-10 and 15-30)?

I want to make a listing with a interval, this mwe : \begin[firstline=5, lastline=10]{lstlisting} <inkscape-extension> <_name>Export to TikZ path</_name> ...
1
vote
0answers
37 views

increase margins of floats page

I have several sections in my article, each with a sizable (~22 lines) code listing explaining the concept of that specific section. I do want to float my listings, as they look nasty if broken off ...
0
votes
0answers
48 views

A problem about typesetting Mathematica code [duplicate]

I want to typesetting the words as below: My code: \documentclass[b5paper,UTF8]{article} \usepackage{graphicx} \usepackage{geometry} \usepackage{fancyhdr} ...
11
votes
2answers
762 views

How to highlight all words of the form [0-9][A-Za-z0-9]* immediately following an equal sign?

I am using the Latex Listings package to include code in a document. I need to implemented syntax highlighting similar to what you see in a standard IDE. I've been able to assign colors to comments, ...
1
vote
0answers
18 views

Problem with spacing above some, but not all, “\paragraph” headers [duplicate]

I am writing a text using \paragraph, and I am completely baffled as to why the 1st paragraph has no space between it and the above text whereas the 2nd does! If I add one more paragraph after the ...
1
vote
0answers
40 views

Spacing between words in listings package and emphasizing identifiers

I have written some source code using listings package but is stretching out of the page. This package leaves huge spaces between the words, so is there a way to make them smaller? At least like the ...
8
votes
1answer
547 views

Listings line numbers that match the linerange specification

This is a follow-up question to First line number in lstinputlisting environment. Consider the MWE: \documentclass{article} %\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox ...
3
votes
1answer
199 views

How can I line-break a long string of numeric digits and hyphens?

I have a cls file that contains a definition for source code: \lstnewenvironment{code}[1][] { \lstset{ basicstyle=\ttfamily\footnotesize, breaklines=true, ...
3
votes
1answer
37 views

Package listings and Perl here documents with apostrophes

I sometimes write ordinary English prose in my here documents in a Perl usage sub, for example --[no]alias [don't] use the alias list in the ini file (default noalias) The problem is the a ...
3
votes
1answer
37 views

How to display a code using lstinputlisting that isn't separated with figures?

This is the code I used: \lstinputlisting[language=Python,breaklines=true]{seminar_ED.py} It works fine with displaying the code over multiple pages when I don't add other figures in the text. But ...
0
votes
0answers
62 views

Font shape 'OT1/cmvtt/bx/n' undefined

I'm getting the following warning: Latex Font Warning: Font shape 'OT1/cmvtt/bx/n' undefined (Font) using 'OT1/cmvtt/m/n' instead on input line 25 How can I suppress that warning? Or: ...
3
votes
1answer
66 views

Why do minus signs vanishes in listings typeset with matlab-prettifier? [duplicate]

I am typesetting my MATLAB code with package matlab-prettifier. However, the - sign are gone. How can I get it back? MWE \documentclass[12pt]{article} % For MATLAB code ...
3
votes
1answer
194 views

TeX capacity exceeded with listings package

In trying to find the source of the following error in my LaTeX document, the listings package seems to not be runnable The minimal example, which I implied but did not include was: ...
34
votes
3answers
23k views

What can I use to typeset MATLAB code in my document?

This question led to a new package: matlab-prettifier Does anybody have a quick and easy way to typeset some relatively long MATLAB code in the appendix? I looked up a few methods, and the ...
2
votes
1answer
60 views

tcblisting: two listings side by side

can anybody tell me, how to place two source doe listings side by side within a tcblisting? Something like: \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,sidebyside, listing ...
1
vote
1answer
74 views

How can I set a font size smaller than \tiny in lstlisting?

I'm writing a presentation using LaTeX and beamer. In some slides I put an image and some code using the listings package and the lstlisting environment. I'd like to use a font size smaller than \tiny ...
4
votes
2answers
78 views

Unnecessary line break with listings and prebreak

A lstlisting environment with prebreak may break lines unnecessarily. Here is an MWE: \documentclass[draft]{article} \usepackage[final]{listings} \begin{document} \begin{lstlisting} 1 3 5 7 9 1 3 5 ...
1
vote
0answers
37 views

How to make listing program ConTeXt at LaTeX ?

I want make listing program Context at LaTeX, my MWE like this : \documentclass[]{article} \usepackage{listings} \usepackage[dvipsnames]{xcolor} \lstset { frame=single, framesep=\fboxsep, ...
3
votes
1answer
108 views

Should I use \lstinline for the language keywords embedded in text?

When writing about programming languages, there are examples to format as listings. That works fine and produces beautiful results. Sometimes I want to mention the keywords used in the listing further ...
5
votes
2answers
158 views

Beamer overlay and listing conundrum

When I try to overlay the lstlisting C code with escape character (so that I can insert a \colorbox), I get the following error: ! Missing number, treated as zero. <to be read again> ...
3
votes
1answer
47 views

Using listings within a \only section

Is there any way to use listings within \only sections of Beamer presentations? The following is an example of what I'd like to achieve: \documentclass{beamer} \usetheme[height=7mm]{Boadilla} ...
2
votes
1answer
48 views

Vertical border between number and code in lstlisting

what I am trying to achieve is a vertical line between the line numbers and the code in a lstlisting. I have experimented with the frame option a lot, but i guess it is not possible this way, if at ...
5
votes
1answer
73 views

Can you specify a word separator for variables in listings?

Depending on the language specified, the listings package may or may not bold keywords inside of variable names. Python is fine \documentclass{article} \usepackage{listings} \begin{document} ...
18
votes
3answers
13k views

Shrinking monospace style for listings package

I am working on a thesis and putting together a "pretty" listing. I'm looking at setting up a small font style for a code view. What I have here is: \usepackage{listings} \lstset{language=C, ...
0
votes
0answers
35 views

Error in tabularx+listings example with TexLive 2014, which compiles in TexLive 2011 (! Missing { inserted)

Consider this MWE: \documentclass{article} \usepackage{trace} \usepackage{tabularx} \usepackage{booktabs} % \toprule etc; \let\botrule\bottomrule % temp hack \newcommand{\tn}{\tabularnewline} % for ...
3
votes
1answer
745 views

How to define default 'program listing' title and parameters in Lyx

I'm using LyX software and need to embed python code snippets and the option I found is to put snippet in a file and then use: insert> file> Child Document ----> choose the snippet file ----> set ...
4
votes
1answer
73 views

Using lstinline in caption of lstlistings with multicol?

Consider this MWE: \documentclass{article} \usepackage{multicol} \usepackage{listings} \begin{document} \def\extra{extra} \begin{lstlisting}[ multicols=2, caption={ [short] aaaa \extra, ...
1
vote
1answer
45 views

how to use verbatim within a list

I tried to use verbatim within a list like this: \begin{lstlisting} Search(HTMLpage, \begin{verbatim}``<TITLE>*</TITLE>''\end{verbatim}); Copy(HTMLpage); Paste(Title); \end{lstlisting} ...
8
votes
1answer
66 views

Adding color package destroys listing centering

I am using @egreg's answer to make listings centered: \documentclass[a4paper]{book} \usepackage[T1]{fontenc} \usepackage[ hang, small, it, hypcap=true ]{caption} \usepackage{fancyvrb} ...
5
votes
1answer
57 views

Can I avoid source formatting with the listings package?

Is there a way to use the listings environment, without resorting to a specific language formatting? (but instead use the usual Latex commands being formatted correctly.) The reason I want to do it ...
0
votes
2answers
91 views

Listing spanning two columns with ieee template

I'm writing an article with the IEEEtran template, which have two columns. I'd like to have a listing with source code that spans the two columns of the article, like in the attached figure. I'm ...
16
votes
1answer
332 views

How can I draw arrows within a listing to explain positional association?

I need nice drawing in lstlisting C/C++ code. I'm trying to make something like this This is what i have made so far \documentclass[11pt]{article} \usepackage{listingsutf8} \usepackage{tikz} ...
1
vote
3answers
76 views

How to make listings with mathematics notations?

I have a problem about make a listing program and I want make it like this: For my example: \documentclass{article} \usepackage{listing} \usepackage{amsmath} \begin{document} ...
0
votes
1answer
110 views

Beamer: How to showcase LaTeX-Code and results that look like scrartcl

We are currently working on a beginner's course for LaTeX. We are using LuaLaTeX and Beamer for the slides. We typeset code with the listings-package. We often show Code on the left and a result ...
0
votes
0answers
50 views

How do I hide page numbers when overlapped?

I'm trying to add an environment for code listings to stay on one page as described in "How to prevent lstlisting from splitting code between pages?". When my listing is at the bottom of the page, ...
2
votes
1answer
76 views

LuaLaTeX and listings do not work while XeLaTex works fine

I am trying to move from XeLaTeX to LuaLaTeX. I have some listings with special delimeters (an underscore). The following MWE compiles perfectly under XeLaTex, but gives the following error under ...
6
votes
1answer
69 views

Code listing inside of tabu environment

I'm trying to insert a small code listing into a tabu table, however I'm unable to build a PDF. The code I'm trying to use (well- a simplified form of it) is as follows: % !TEX encoding = UTF-8 ...
1
vote
1answer
105 views

Problem listing (List of Listings) in the table of contents [closed]

I am writing a document using Latex. I have group pf codes in my document and I wanted to show it in the list of contents. I managed to do so, but I still have (contents) appearing in table additional ...
1
vote
1answer
31 views

Custom caption for lstset to use in table of contents [duplicate]

I would like to use the functionality of figure captions (that can have two captions: one for table of contents and one for the caption below/above the figure) with my custom filecode environment. ...
2
votes
1answer
2k views

Environment lstlisting undefined

Hi I have installed the listings package in order to display my code. I am running the following code within my document: \begin{lstlisting} public static void main(String[] args) { ...
1
vote
1answer
115 views

Don't break lines at certain characters in lstlisting

Is it possible to configure lstlisting such that it doesn't break lines at certain characters? In this example, a line break is inserted after the opening parenthesis: public void someMethod( ...
3
votes
0answers
34 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][] ...
24
votes
4answers
8k views

Having problems with listings and UTF-8. Can it be fixed?

I'm having some problems with listings and UTF-8 in my document. Maybe someone can help me? Some characters work, like é and ó, but á and others appear at the beginning of words... ...
3
votes
1answer
55 views

listings-package custom language delimiter match left-side

I'm trying to define a new language cli-like interface, but I can not figure out how the use the delimiter to match my prompt. I want to apply tree different styles to the text. In the example below ...
6
votes
2answers
46 views

How to skip first line lstlistings

I need help for lstlistings. I have a code that start with: INPUT: c, m rest of code... I want that the first line doesn't view the number line. This is my lstset: \lstset{language=Java, ...
5
votes
1answer
97 views

Strange “Undefined control sequence” message

I am using biblatex for the first time. When I do quick compile on the document it compiles no problem, after that I run the BibTeX command and it also works. After that I try a quick compile again in ...
16
votes
3answers
235 views

Fancy code environment

I'm writing a small tutorial about LaTeX. So I'd like to insert some code and obtain the result on the right. I'm almost there. I got the desired output but I'd like something more clear, that is, ...
2
votes
1answer
92 views

Unable to define scala language with listings

I'm using the solution here for scala support, but this fails to properly color the scala code, and throws a number of errors when processing lstset - % ! Package keyval Error: breakatwhitespace ...