{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

7
votes
4answers
1k views

listings in a footnote

This code won't compile: \documentclass{article} \usepackage{listings} \lstset{ language=C, basicstyle=\small } \begin{document} lorem ipsum\footnote{% \begin{lstlisting} // some C code or ...
7
votes
2answers
996 views

Grouping the list of listings by chapter

I am using the listings package. I want to print out a list of listings, which I can do. The thing is that in the other listings the typesetter "groups" figures/tables by chapter. Is it possible to ...
30
votes
4answers
15k views

How to prevent lstlisting from splitting code between pages?

Is it possible to prevent lstlisting from splitting a code between pages if it does not fit on one page? Instead splitting I would like to have the code on the next page. I tried to put all ...
7
votes
1answer
3k views

How can I start the line numbering of my listing by an arbitrary number?

This is what I want: 15 <servlet> 16 <servlet-name>udpListener</servlet-name> 17 <servlet-class>oli.servlet.UdpServlet</servlet-class> 18 <!-- UDP Port fuer ...
5
votes
1answer
536 views

Remove\begin{Schunk} \begin{Sinput}

I am using Sweave to produce my tex. In addition I use lstlisting to highlight the source code as below. \begin{lstlisting}[caption={Computation $\widehat Y_4$ and its ...
2
votes
3answers
309 views

How can I have inline code (delimited by |) in a footnote or in a caption?

I've defined | as a "short inline character", using \lstMakeShortInline| I'd like to use that delimiter to typeset inline code in a footnote or a caption, e.g. \footnote{Java uses the |break| ...
3
votes
3answers
913 views

Changing side of line numbering in two columns documents

I'm trying to type some report and I have a small problem with the twocolums document class and the line numbering in listings. The document is on two columns : ...
1
vote
2answers
1k views

Why does Listings package not display anything? [closed]

I'm writing a C++ course for secondary students and wanted to display some source code in a nice way (indenting, eventually coloration) and tried the Listings package. But I have a problem, the file ...
7
votes
1answer
2k views

How to define a new environment with a fancy box (tikz) around sample source-code (listings)?

This is what I want to do: \documentclass{beamer} \begin{document} \begin{frame}[fragile]{Frame 1} Some \structure{Python} code here: % I want to define a new "pythoncode" environment, so ...
11
votes
1answer
5k views

LaTeX Listings Package, No Line Number for Comments

I am trying to get only the actual code to be line numbered rather than both code and comments. Example: \lstset{basicstyle=\footnotesize, xleftmargin=40pt, frame = single, numbers = left,caption = ...
1
vote
1answer
237 views

How to make my unusual environment accept one argument?

I cannot find a good title to express my question. Therefore, please parse the following code first. Minimal Code \documentclass[dvips,dvipsnames,cmyk,table]{book} ...
1
vote
2answers
770 views

Define a new environment to combine tikzpicture and lstlisting

I would like to define a new environment to combine the tikzpicture environment from package pgf/tikz and the lstlisting environment from package listings. The result would be to first produce the ...
4
votes
2answers
2k views

Can I get a shadowbox with rounded corners? (using `listings` package)

I'm using the listings package as below: \usepackage{listings} \lstnewenvironment{pythoncode}[1][] {\lstset{language=Python, basicstyle=\ttfamily\footnotesize, frame=shadowbox, ...
0
votes
1answer
144 views

Is there a side effect if we use listings.sty with chained styles?

Even though I have not detected the side effect, I am still worrying I might do a bad practice here. Is there a hidden side effect when doing the following? \documentclass[cmyk]{article} ...
20
votes
3answers
5k views

How can I highlight some lines from source code?

I am preparing a presentation (using beamer) and I'll need to include many snippets of source-code. For including source code, I'll probably use listings package. (I know there is also minted package, ...
1
vote
1answer
439 views

Without defining a new command for each setting, is it possible to pass the set of settings to the optional argument of lstinputlisting ?

Screenshot Scenario I want to define two sets of settings for \lstinputlisting--One setting for CSharp A and the other one for CSharp B. They are different only in the color settings. ...
1
vote
1answer
249 views

Program listing outputs text wider than usual

\documentclass[12pt]{article} \usepackage{listings} \lstset{basicstyle=\ttfamily} \begin{document} \texttt{int main(void)} is rendered tighter than in the listing. What lstlisting option would need ...
14
votes
3answers
5k views

How to make overlay still work inside lstlisting environment?

Problem I want to explain C# programming language step by step using overlay in beamer.cls. But it does NOT works as shown in the following figure. How to solve this problem? Code Snippet ...
0
votes
1answer
2k views

How to prevent beamer from removing the tab alignment of lstlisting?

I want to show my C# code snippet on the presentation slides using beamer. Because the code is long, I set the frame to be breakable using the frame option allowframebreaks. The code now can be shown ...
1
vote
1answer
383 views

Listings: new environments with arguments

I have this basic question. How can use arguments with listings? I tried this and it doesn't work: \lstnewenvironment{cor}[2][] {\linerange{#1-#2},\lstset{language=[Sharp]C,,basicstyle=\scriptsize, ...
3
votes
1answer
2k views

Multiline listing in a table environment

I'm trying to simulate an effect that is very easy to do in WYSIWYG environments, namely having a table with some cells containing somewhat complex multi-line entities. For instance, consider the ...
3
votes
1answer
200 views

Shrink code chunks in a documentation

i'm making a documentation of a system, and i have a lot of code chunks that i want to explain, but some of them are too long. My questions if there are some way to automatically shrink those too big ...
5
votes
4answers
950 views

What configuration do you propose for listings.sty to make the output look comfortable?

The objective of this topic is to make a common place where we can share our settings for listings.sty. So we can use this as a reference. Note that I am only interested in the following settings: ...
4
votes
1answer
2k views

How to make tabsize also affect lstinputlisting?

I noticed that tabsize only affects lstlisting and lstinline macros. Here is the output. The top figure is displayed using lstinputlisting and the bottom one is displayed using lstlisting. The ...
5
votes
2answers
2k views

Listing over two columns - how to page break?

I have a two column article: \documentclass[a4paper, twocolumn]{article} Inside this is a bigger lstlisting which has a float=* to merge the two columns. However this listing needs a page break. ...
4
votes
2answers
659 views

pass “global” options to minted/fancyvrb

Is there a way to override default options for the minted environment, rather than having to specify them for each and every snippet of code ? In other words, is there an equivalent to listings's ...
2
votes
1answer
211 views

Is it possible to load 2 or more languages at the same time in one document using listings.sty?

Assume in my book I am discussing two (or more) languages, e.g. PSTricks and LaTeX. Can I load these languages at the same time in my book document such that their keywords get proper markup?
1
vote
1answer
416 views

line numbering of minipages

I can't manage to add linenumbers left of the boxes. Can anybody help me? \documentclass{article} \begin{document} \fbox{\fbox{ \begin{minipage}{0.8\linewidth} \textbf{def} mapper (key, value): ...
12
votes
1answer
2k views

fancy verbatim - bold letters for the first 4 columns

I am writing a book on Python and IPython. I want to insert in this book code listings of Python and IPython. For the code itself I have no problem customizing listings for my intents. Including ...
3
votes
1answer
509 views

How to change the formating of the title of a “Listing” from roman to arabic?

I recently stepped out of my comfort bounds and decided to add some Code snippets to my paper. I was able to get everything working fine and looking good, except the actual title. Everything else in ...
1
vote
2answers
370 views

How to make a LTXexample-like environment by using the package listings.sty only?

For some reason, I am forced to create a LTXexample-like environment. The following is my effort, but it cannot work. :-) I don't know how to fix the problem. Thank you in advance. ...
4
votes
1answer
396 views

How to get tex4ht to respect listings styling better ?

I've been producing PDFs and HTML from Latex sources, using tex4ht for the HTML (I'm on Debian/Lenny; so whatever versions are default on that). I'm using the listings package to include source code. ...
11
votes
1answer
6k views

Using listing for displaying Matlab code

I'm trying to display matlab code in a LaTeX document and the comments are typeset with an ugly space between letters: \documentclass{article} \usepackage{listings} \lstset{language=Matlab} ...
6
votes
3answers
3k views

LaTeX beamer: Code listings in notes

How can I add a code listing to a beamer note slide? I tried the following which doesn't work: \note{{\tiny{This is a note \begin{lstlisting} foo bar \end{lstlisting}}} Any ...
5
votes
2answers
1k views

Minus signs vanish with listings and breqn - any solutions?

When using listings and breqn, the minus signs (or dashes, according to the unix.SX site then there's some controversy about which it is) disappear from code listing. Here's an example: ...
1
vote
1answer
3k views

change font color in a lstset [closed]

Hi I need put java code to latex. I use \lstset and \begin{lstlisting}. I need change color of font in SOME part of code. How I can do this? Help pls
7
votes
3answers
5k views

Rename “Algorithm” to “Listing”

Background Syntax-highlighted source code image listings are being used as Algorithm floats with the lst: prefix for captions. Problem The following LaTeX code in the preamble renames the caption ...
6
votes
3answers
1k views

“Listing #” below listings without a caption

When not specifying a caption for a lstlisting nothing is shown below the listing while "Listing #: mycaption" is displayed as soon as I specify a caption. However, I'd like "Listing #" to be ...
8
votes
1answer
3k views

How to make \lstinputlisting applicable to file paths with spaces?

I am using the listings package and the path to the source code contains some spaces. For example, the path can be /some dir/sub dir/file 1.txt and \lstinputlisting{/some dir/sub dir/file 1.txt} does ...
12
votes
2answers
412 views

How to use showexpl with an external class?

The showexpl package defines LTXexample environment which allows to define a latex code and shows its result side by side. The problem is that it uses the same document class where the LaTeX code is ...
0
votes
2answers
689 views

How to hide LaTeX commands and keywords in a listing? [duplicate]

Possible Duplicate: How can I highlight some lines from source code? How to hide LaTeX command (keywords) in a listing? When I use for example \textbf{} in the listing it appears as ...
6
votes
3answers
855 views

How to suppress BOM effect in the output?

When I used listings package to import C# code snippet from within my LaTeX file, I got an output as follows. At the first line, there is an unnecessary white space because of the BOM (Byte Order ...
19
votes
3answers
1k views

Typesetting LaTeX Source Code with the listings package

I am writing some documentation for a LaTeX package, in which I am going to be including some example LaTeX code. What is the best way to typeset that code? I know I could just use verbatim, but it ...
6
votes
3answers
341 views

How to skip both the first n rows & the last m rows simultaneously?

I am using showexpl.sty to display side by side the code snippet and its corresponding output. Because of the paper size limit, I intentionally want to remove the "redundant" rows, i.e., the first n ...
20
votes
1answer
5k views

How to center a listing?

I'm trying to get some console output in my homework. I put it in a listings environment but I want it to be centered horizontally on the page. The only thing I get centered is the caption ;-/ ...
7
votes
1answer
994 views

Hiding code comments in listings

I'm using listings package and \lstinputstring command to insert code from a file. Is it possible to hide code comments in inserted code? I'm using a language in which # starts a comment and it lasts ...
4
votes
2answers
1k views

How to highlight operators and brackets in a C listing?

How can I apply a certain style to C (or, well, any other programming language) operators? So that when I write \begin{lstlistings}[language=C++] int i = 0; if(i > 1) { // do ...
9
votes
1answer
1k views

how to colorize syntax using R + Sweave?

I'm writing a LaTeX document using Sweave (a Beamer presentation, really), which weaves R code and LaTeX. Is there a way to make my chunks of code and its output highlighted? I could use listings ...
12
votes
3answers
3k views

Phantom spaces in listings (pdf)

I have a problem with SQL code in a PDF document. For code representation I'm using the listings package. Everything works perfect until I copy-paste that code from the created PDF document. I get ...
8
votes
1answer
1k views

Package to indent and syntax highlight C++ code

I am looking for a package to have an environment for C++ source code, with options for syntax highlighting, automatic indentation, proper multipage behavior, etc. I read something about the listings ...