{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

1
vote
0answers
28 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
75 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
136 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
39 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
41 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
62 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
30 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
703 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
67 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
42 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
64 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
56 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
68 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
297 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
72 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
106 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
48 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
71 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
53 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
103 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
29 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
114 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
33 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
53 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
42 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
87 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
230 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
68 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 ...
0
votes
1answer
67 views

Including both XML code and Java code in a document using lstlisting package

I am writing a document which has both java and xml codes, I managed to highlight my java code but unfortunately I was unable to do the same with xml, so far I have tried more than one way either by ...
5
votes
1answer
58 views

Multiple literates in a listings style definition [duplicate]

I have a style defined for a language which has lot a lot of literate replacements. In the individual listings that use this style I would like to introduce more listing-specific literate ...
0
votes
0answers
54 views

How to install listings.sty in tex-live DVD version. Ubuntu/Fedora

I run tex-live (pdfLatex) at home on Ubuntu and on Fedora in college. And this error comes up every time and forces me to go to the WriteLatex website. I know the Windows solution of running MPM. But ...
2
votes
1answer
88 views

Coloring tables without xcolor, colortbl and tabu while using listings package

currently, I want to color my tables. However, presumably since I'm using the listings package, I can't apply the abovementioned packages, as they totally mess up the default table looks (lines ...
3
votes
1answer
68 views

Customize Color for lstset morekeywords

I have done some extensive searching and have yet to find the answer to changing the color for lstset morekeywords. I want them to be a different color than my regular keywords. Here is what I have ...
4
votes
2answers
149 views

How can I automatically replace subscripts and highlight GoTo labels?

I have to show a lot of autogenerated code throughout my document. The generated code represents loops with explicit block labels and gotos. The following code applies function f to each element of ...
7
votes
2answers
329 views

Change the background color of line numbers in a lstlisting?

Consider the following code which deals with a lstlisting. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{listings} \usepackage{xcolor} ...
0
votes
1answer
51 views

Weird symbol in white spaces inside listings environment [duplicate]

I get that symbol inside quotes in listings environment. It seems to appear only inside quotes.Outside of them it seems that is not happenning the same thing. Why do I have that problem and how can I ...
1
vote
1answer
84 views

How to avoid Greek letter symbols in lstlisting

I am using the lstlisting package, but I don't want it to show Greek letters by its symbol. For example: \begin{lstlisting} Parameter.delta_x = 0.002e-6; \end{lstlisting} I want that line ...
0
votes
1answer
193 views

How to place the caption of a lstlisting in the margin? (scrreprt, floatrow)

In the following mwe I am using the floatrow package to place the figure captions in the margin. How can I do the same for listings? Update: Some listings are spread over two pages. ...
2
votes
1answer
470 views

How can I typeset Greek letters in listings?

Is it possible (and if yes, of course how) to use Greek letters within lstlisting (of the listings package)? However, \epsilon, for instance, puts of course exactly that and not a Greek epsilon. I ...
1
vote
1answer
70 views

How can I prevent page breaks from occuring inside the body of a function?

Is it possible to tell the listings package not to insert page breaks inside the body of a function? For instance, void foo() { // Do not insert page break here } //But here is fine An ...
15
votes
1answer
423 views

Is there a good reason for lstlistings code to look so ugly by default?

I thought, the purpose of LaTeX was to make it easy to create beautiful documents. Yet every time I see one of those lstlistings I can't help but wince at the mutilated kerning. Take for example this ...
5
votes
2answers
2k views

Background overflows when using rounded corners for listings (package: `listings`)

I'm using listings to list code in my document, and I want the code to be displayed in a frame with rounded corners and a grey background color. But the background overflows the frame, as if the frame ...
4
votes
1answer
482 views

Make arrows inside lstlisting

Inside my lstlisting environment I want to make the assignment symbol an arrow instead of =. How can I do that? Adding just \leftarrow doesn't work, because then the whole word is displayed.
9
votes
1answer
112 views

How can I highlight \[…\] properly in LaTeX listings?

The listings package provides the option moredelim, allowing for custom styles for words enclosed by given delimiters. I would like to give $...$, \[...\] and $$...$$ custom colors. \[...\], however, ...
2
votes
3answers
331 views

How can I highlight text before a character with listing?

All is in the title. I would like to add a color to the text before a character with listing package. For example, I would like to add a color to text between the beginning of a line and : or =, in a ...
3
votes
1answer
631 views

Rendering VHDL in latex

I have a VHDL code which I want to insert into my latex document. I need a package that takes care of syntax highlighting, indentation etc. Is there a package which serves this purpose?
2
votes
1answer
130 views

How to include program listings in C# with custom font and syntax highlighting in LyX?

I'm rather new to LaTeX and use LyX editor to create my documents. There are similar questions but none of them answer how to do that in LyX. I am wondering, how to include a program listing in ...