Tagged Questions

{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

4
votes
1answer
97 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
57 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
66 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
20 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
136 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 ...
3
votes
1answer
199 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 ...
2
votes
2answers
200 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
77 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} ...
5
votes
1answer
541 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
188 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 ...
11
votes
1answer
451 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
70 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
31 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
128 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} ...
3
votes
1answer
48 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 ...
38
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
112 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
221 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
19 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
65 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
127 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
26 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
158 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 ...
9
votes
1answer
1k 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
98 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
80 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
78 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 ...
3
votes
1answer
142 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
168 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 ...
16
votes
1answer
445 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
208 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 ...
4
votes
2answers
269 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
75 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 ...
0
votes
0answers
254 views

How to replace (unicode) characters by ü,ğ,ş etc.?

\documentclass[11pt,a4paper]{article} \usepackage[utf8x]{inputenc} \usepackage{ucs} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage[T1]{fontenc} ...
0
votes
1answer
471 views

two-column lstlisting in landscape orientation

How can I divide my page in two to show my code with lstlisting? This is a large code and I want to set as 2 pages in one. Is an appendix of my project not all the document. EDIT thanks to ...
3
votes
1answer
56 views

latex R code with %*%

I'm using latex with lstlisting to format my R code. Some of my code uses matrix arithmetic, including %*%. Unfortunately this causes errors when compiling. There is an example of what I would like ...
2
votes
1answer
467 views

lstlistoflistings entry in table of contents name is always 'Contents'

I'm trying to add a list of code listings to my document, with a reference to it in the TOC. By simply calling \lstlistoflistings I end up getting everything I need (the list of listings, an entry ...
6
votes
1answer
948 views

LaTeX commands in Verbatim using fancyvrb and listings

I am trying to use LaTeX commands like \textbf, \textit, \textcolor in fancyvrb combined with listings. Especially I want to bold and color any text or entire blocks of Java code (not just keywords) ...
7
votes
1answer
224 views

Faster compiling [duplicate]

I'm writing at my thesis and it has now about 60 pages.. When I want to compile it (to pdf), it lasts about 20 seconds.. Is it normal? I think, the included graphics costs a lot of time?! ...
4
votes
2answers
234 views

Integrating listings with fancyvrb

I am trying to use fancyvrb with listings and I get an error saying l.2 ...{Verbatim}[formatcom={\lstset{style=Java}}] Package Listings Error: language java undefined. ...
4
votes
1answer
81 views

Listings environment within another environment

\newtheorem{alg}{Algorithm}[subsection] \begin{alg}\label{alg:1} \begin{lstlisting}[frame = single, breaklines = true, numbers = left] test code \end{lstlisting} \end{alg} How can I prevent the ...
1
vote
0answers
12 views

include “\end{lstlisting}” inside lstlisting block [duplicate]

I'm writing a shell script that returns all shell scripts in LaTeX lstlisting environments. Now, the shell script that does this is also included in the LaTeX file it generates, which gives me a ...
3
votes
1answer
229 views

Listing / lstinline and line breaks

I'm using \lstinline among other things for writing file names of my source files. For example \lstinline{foofoo.pl} Then, sometimes I have the problem that some lines containing this string are ...
5
votes
2answers
157 views

How to colorize escaped math in syntax highlighted listings?

my listings are syntax highlighted using \lstset with escapechar=$ and commentstyle=\color[rgb]{0,0.5,0}. Now my C-code looks like int16_t speed; // calculated speed in $\(\frac{cm}{s}\)$ and the ...
5
votes
2answers
211 views

Why is the space between words in my source code listing so big?

I used the following code to list my java code, but the it looks like there's too much space between words. What can I do? % source code listing \usepackage{listings} \usepackage{color} ...
4
votes
1answer
246 views

Math symbols in listings

Does anyone know how to write math symbols such as sums and integrals inside a listing? \begin{lstlisting} vl(i)= \sum\limits_{i=1}^N{Al(i,j)*xl(j)} ; i = 1,3 \end{lstlisting} UPDATE: ...
3
votes
1answer
90 views

How to set a background color for a listing?

Someone who knows how to fill with color only the box? \begin{shaded} \begin{lstlisting} if (a < b) { printf("A is smaller than B!\n"); } a = b; \end{lstlisting} \end{shaded}
5
votes
1answer
82 views

Adapt labelling facilities of listings package

I compiled a catalogue from past exercises for a lecture (running to several hundred pages), which makes consistent labelling a bit of an issue. My solution is to use labels of the form ...
10
votes
1answer
80 views

How can I define additional literate replacements without deleting existing ones?

I'm trying to improve some language definitions that ship with listings. Those improvements consists in, among other things, a number of literate replacements (see subsection 5.4 of the listings ...
2
votes
1answer
240 views

Footnotemark in caption of listing causing problem

I have the following listing: \begin{lstlisting}[float=h,caption={Description\footnotemark.}, label={listing2}, keywordstyle=\color{blue}\bfseries, ndkeywordstyle=\color{black}\bfseries, ...