{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

16
votes
1answer
250 views

How to strip a listing of all (line and block) comments without leaving white space?

I'm looking for an easy and robust way to strip all the comments from a listing. My approach (passing \@gobble to the commentstyle key) correctly removes all the one-line comments and block comments. ...
4
votes
1answer
3k 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?
1
vote
1answer
2k views

including python code in beamer? [closed]

Suppose I have a python file. How can I include in beamer presentation in one of the slides? \insertcode{"Scripts/mc.py"}{Python} does not work with \usepackage{listings} , which otherwise work in ...
9
votes
3answers
833 views

Listing background broken by \colorbox and \framebox

I am using listing environment (listings package) with the background parameter. I want to highlight some lines of code and I am using the \colorbox, \makebox and \framebox to achieve this. However, a ...
11
votes
1answer
6k views

Package hyperref Warning: Token not allowed in a PDF string [duplicate]

My document contains section titles that are formatted by the listings package. (The section names are names of configure script switches.) \subsection{\lstinline!--enable-so-version!}\label{enable-...
9
votes
1answer
647 views

Different colors for default and language-specific listings

I'm generating pdf documents using knitr and pandoc. The conversion is mostly automated from R markdown -> markdown -> latex -> pdf. However, my documents combine R source code and its output, and I ...
10
votes
2answers
869 views

Can the listings package highlight by regexp?

I'm trying to typeset SuperCollider code using the listings package. Any "freestanding" identifiers that begin with a capital letter are class names, and should be highlighted; by "freestanding", I ...
8
votes
1answer
455 views

How can I automatically highlight SuperCollider symbols and environment variables?

This question led to a new package: sclang-prettifier I've been poring over the listings manual, trying to figure out how to get some very specific types of formatting for the SuperCollider ...
7
votes
1answer
145 views

How can I test the first character on each line of a listing?

The listings package defines a hook called EveryLine to allow users to execute TeX code at the beginning of each line of a listing; the following is taken directly from the listings source code (...
2
votes
1answer
189 views

Listings on multiple pages - keep number like Continuedfloat

I have the following code: { \lstset{language=C, basicstyle=\tiny, tabsize=3, frame=lines, breaklines=true, breakatwhitespace=true} ...
6
votes
1answer
143 views

What's up with the tag key?

Subsection 4.18 of the current listings documentation (2013/08/26 Version 1.5b) describes a key called tag. That key is used in lstdrvrs.dtx, which is a file that ships with listings and takes care of ...
4
votes
1answer
313 views

How to handle listings, fancyvrb, newfloat and caption?

I am planning a "small thesis" for university which will need to display lots of code (C, C++, gnuplot, LaTeX, ...) - thus I spent this evening reading about listings and fancyvrb. The latter I've ...
4
votes
1answer
640 views

messy/overwritten numbering in enumerate tag

I have the following in my LateX code: \begin{enumerate} \item \begin{lstlisting} ...
3
votes
1answer
345 views

Lstlisting in twocolumn document

I have a problem when using lstlisting in twocolumn document. At my university I have to make reports in twocolumn documents. My teacher send me pre done .tex file with this code in it: \...
4
votes
1answer
131 views

Changing side of line numbering in two columns documents part two

I have the same question as this one: tex.stackexchange.com/questions/9510/changing-side-of-line-numbering-in-two-columns-documents/ I'd like to use the listings package in a twocolumn document. An ...
8
votes
1answer
338 views

Display of source code in customised (IDE-like) format in PDFLaTeX

I want to put some “C” source code snippets in latex (I am using PDFLaTeX), but I don’t get the result that I want using the “listings” package. What ideally would like to get is the same result as ...
7
votes
1answer
113 views

Problems with amsbook, lstdoc, and sections

The code \documentclass{amsbook} \usepackage{lstdoc} \begin{document} \chapter{Chapter} \section{Section} \end{document} produces the error messages Missing } inserted. [\section{Section}] and or ...
4
votes
1answer
174 views

Why is this \def not working as expected?

I am having a weird problem with \def. I am new to (La)TeX and can't figure this out. I have a simple code as follows. \documentclass[10pt,a4paper]{article} \usepackage{listings} \begin{document} ...
2
votes
1answer
110 views

Remove heading lslisting multiple pages

Hi guys I have a problem with lslisting because the code spans over multiple pages. I really hope you can help: How can I remove the heading (BILIAG A. APPENDIKS)? Here is a minimal example of the ...
2
votes
1answer
90 views

Signature below listings

How can I put automatic signature below my code listings. Now I put my code listings like this: \begin{lstlisting} MY CODE \end{lstlisting} Settings of listings: \usepackage{color} \...
1
vote
0answers
21 views

Change language of caption in lstlisting [duplicate]

When I define a caption in lstlisting, LaTeX writes, for example, "Listing 1.1: ..." but I want to change the "Listing" to another language. How can I do this?
7
votes
1answer
358 views

Listing within tcolorbox: how to adjust width to the natural listing width?

I would like to create a tcolorbox whose width is computed based on the longest line I have in listed code. I know it is possible to adjust the width with respect to the title. Is it also possible to ...
4
votes
1answer
596 views

Floatable centered and non-splittable lstlisting

I've been looking around and tried various setups but have yet to found the solution. I'm trying to define a lstlisting environment that is a float, is centered in the page, and cannot be broken ...
3
votes
2answers
953 views

Put figure and listing side by side [duplicate]

I'm trying to put a listing and figure side by side. I tried to follow the suggestions in this link How to put algorithm and figure(s) side by side? without using caption package but the listing stays ...
4
votes
1answer
151 views

Line break at a whitespace in inline code listing

How can I automatically break the following inline code at a whitespace? The problem is that I have to use breaklines=false. \documentclass{article} \usepackage[latin1]{inputenc} \usepackage[T1]{...
5
votes
1answer
2k views

Escape moredelim in lstlisting

I am wondering if it is still possible to print characters chosen to be moredelim in \lstdefinestyle. It turns out that since I've defined a character as moredelim, it can only be used inside quotes ...
4
votes
1answer
383 views

How can I prettyprint a URL of a http-request in this particular way?

I have a URL for a HTTP-Request as the only content of an lstlisting environment, and I want to prettyprint it as follows: color1 for the first line, and for ?, &, and |, color2 for parameter ...
12
votes
1answer
632 views

Using listings: “zebra effects” AND line numbers

I just made a code listing with a "zebra effect", just like here: Creating a zebra effect using listings But afterwards, the line numbers at the left side of the listing don't appear any more. This ...
6
votes
1answer
110 views

Alignment problem if line breaks are used in listings

I am using a monospace font and I want that all lines are horizontally aligned ("a" should be directly under "a"). How can I do this? I have noticed that also the pagebreak symbol shifts the text. ...
2
votes
0answers
35 views

LaTeX List of listings name in front of number [duplicate]

I am having problems with LaTeX specifically using listings package. The first one is I want to add the word "Código" in front of number of Listing in List of Listings. For example List of ...
2
votes
1answer
395 views

Add coloring rules for specified language keywords in lstinputlisting [duplicate]

I would like to add coloring definition for e.g. @Override in java files. How can I do that ? So far I have the following coloring definitions : \documentclass[a4paper,11pt]{article} \usepackage{...
3
votes
1answer
80 views

Manual line break in listings or listings doesn't work in figure env

The example illustrates my problem. I have long code rows which should break automatically (see line 1) but some lines I want to break manually (line 2 / 3). How can I do this? I have played a little ...
40
votes
4answers
2k views

Has the time come for a LaTeX3 successor to 'listings'?

I'm currently looking for a nice and challenging open-source project to work/collaborate on after my thesis. I don't have a Comp. Sci. background, but I'd like to learn more about compiler ...
4
votes
2answers
157 views

How to ensure footnotes being at the same height on every page?

I have added a footnote to the text but I also have some "unbreakable" code listings. Because of that the footnote gets dragged "higher" in the page. As you can see there's more space between ...
3
votes
1answer
364 views

How to embed special markers into the code listing that will mark certain parts of code to be colored using a custom scheme?

I would like to color my C# code listings as Visual Studio does. However, all language definitions that I found so far only color the keywords and not the user types. I understand that it requires ...
0
votes
0answers
21 views

How to prevent page breaking for lstinputlistings? [duplicate]

In my pdf created from latex sources I can see that sometimes \lstinputlisting will have a page break in the middle just because it happened to be in the end of the page. I would like to prevent it. ...
3
votes
1answer
132 views

Automatic line breaks of long numbers in listings

How can I automatically break long numbers in a listing? Redefining \lst@lettertrue doesn't work. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{listings} \lstset{ breaklines=true } \...
4
votes
1answer
173 views

How can I mimick the listing caption style for my custom “Listing (cont.)” caption?

I have the following LaTeX code which works fine: \documentclass[12pt,a4paper]{article} \usepackage[a5paper]{geometry}% just for the example \usepackage[utf8x]{inputenc} \usepackage{listings} \...
1
vote
0answers
30 views

An environment for C-code [duplicate]

I am trying to create an environment specifically for C-code, but when I compile the document below, LaTeX just hangs. I'm running MiKTeX 2.9 if that matters. Is lstlistings one of those environments (...
1
vote
0answers
345 views

listings package: embed text from a .txt file in a LaTeX document [closed]

I'm using the listings package to put text from a text file into a LaTeX document \lstinputlisting{file.txt} However, it isn't putting in special characters correctly, % is displaying fine which ...
13
votes
1answer
3k views

How can I highlight YAML code in a pretty way with listings?

I'm trying to highlight simple YAML (the markup language, not the CSS framework) code. I know that there is a solution using pygments and minted, however, I would prefer a solution with \...
2
votes
1answer
308 views

Is there a way to ignore the empty lines while for importing matlab code through \lstinputlisting for matlab code

I use the mcode latex package available here: I use: \lstinputlisting{G:/PROJECT_and_SEMINARS/sms/v.1.39.a.1/sms.m}[caption={Source code of program: SMS. Version:1.39.a.1}][firstnumber = 1] ...
3
votes
1answer
132 views

Description definitions and ntheorem

I want to have inline listings in description items, so I used this very nice answer. Unfortunately this hackery destroys my theorem environments with error something's wrong--perhaps a missing \item ...
4
votes
1answer
90 views

Handling a PDF with user text strings

I am using LaTeX to generate descriptive receipts for an online system. I use special character tags and replace these with content e.g. {{ first_name }}. Now, there are several of these and they ...
4
votes
1answer
629 views

Change indentation depth when using spaces in lstlisting

I have an lstlisting that renders some lines of code. The code is indented by four spaces per indent. Is there any setting to change the indentation to only two spaces? I know that there is tabsize ...
3
votes
1answer
309 views

Coloring or Bolding multiple lines in fancyvrb integration with listings

I would like to apply latex commands on a bunch of lines in a Verbatim environment with listings, especially make bold or color a block of code. I am able to do that for a single line, but not for ...
17
votes
1answer
925 views

How to remove the leading unnecessary white spaces when using linerange option?

To be honest, I am looking for people who already read the listings documentation completely. If those people also cannot solve it, then the documentation does not mention anything about it. Sorry for ...
7
votes
3answers
265 views

How can I parse the first word in a token stream, token by token?

Some programming editors and IDEs highlight legal and illegal variable names in different ways. I wish listings easily allowed for such syntax checking and highlighting, but it doesn't, at least at ...
5
votes
2answers
588 views

Setting up `Ubuntu Monospace` font for a specific listing

My OS : Ubuntu 13.10 Latex version used : Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) In my report, I am using the following listing : \lstdefinestyle{BashInputStyle}{ language=bash, ...
1
vote
0answers
145 views

written tab (not only a non-copyable space) in listings enviroment (LaTeX) [closed]

I am trying to put python code in the appendix of report using listings package. Visually it works fine, but there are not tab symbols in the pdf file, only space without symbol in background. The ...