{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

0
votes
0answers
6 views

lstlisting indentation versus editor-formatting

Whenever I use the listings package to typeset code, I encounter the problem that the way lstlistings work collides with the formatting my editor likes (I use vim). For instance, see this code: ...
2
votes
0answers
29 views

Problems with PHP tags (and code) in listings with HTML

I want to highlight PHP and HTML in the same code. In my attempts I experience three challenges: Seems like listings treats <?php and ?> as one large HTML tag. How to tell listings that the ...
3
votes
1answer
52 views

Latex, two-column listing in an array

I am trying to display to codes side-by-side, using this: \begin{center} \begin{tabular}{c|c} \begin{lstlisting} while (x > 0) do x++; \end{lstlisting} & \begin{lstlisting} x = 0; ...
3
votes
1answer
27 views

lstlistoflistings is unformatted

I habe a problem to get a list of listings that looks like the normale table of figures or basically like any other list of anything. As I am not a tex or latex pro, i tried several packages and ...
1
vote
1answer
20 views

How to lstinput a text file path and get content of ext file into pdf

I tried to insert some data using listings package labels(lstset) into pdf which was successful but if the same data is put into a text file ans lstinput it as follows is not successful .Can some one ...
3
votes
1answer
34 views

How to set the label for listings?

Hi I'm new in Latex and I'm using this code from the Board everything is working, but I don't know how to set the label for the listing with this code \usepackage[many,minted]{tcolorbox} ...
5
votes
3answers
375 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} ...
1
vote
1answer
31 views

Listings and verbatim-like environments in a tikz node using newcommand

I have seen answers to this question floating around but none of them appeared to solve the problem. I want to be able to throw a code block into an already defined tikzpicture. So I attempted to ...
0
votes
1answer
13 views

Font size of inline code-listings too small

I'm using the listings package and am satisfied with how my code listings look. The font in my inline-listings however is too small compared to the rest of the text. How can I only increase the font ...
4
votes
1answer
107 views

Why is listings' frame width a little larger then \textwidth?

Here is the sample code: \documentclass[]{article} \usepackage{listings} \lstset{ basicstyle=\ttfamily\footnotesize, frame=single, % adds a frame around the code } \begin{document} ...
3
votes
2answers
29 views

Setting lineskip affects the caption in listings

If I specify a lineskip in lstlisting, it affects the caption too. How can I prevent it? Example: \documentclass[a5paper]{article} \usepackage{listings} \begin{document} \begin{lstlisting}[float, ...
0
votes
0answers
17 views

removing linebreak listing (e-mail, eml)

I tried to use an eml-file as an listing but because the encoding doesen't really work I had to include some German Umlaute (ä,ö,ü), unfortunately there is still a problem with the line break symbol ...
1
vote
1answer
19 views

Why doesn't listings' breaklines work, here?

see the sample code and the screen shot: \documentclass[UTF8]{article} \usepackage{listings} \usepackage{color} \begin{document} \lstset{ basicstyle=\ttfamily\footnotesize, language=Python, ...
2
votes
1answer
64 views

Filename in line 0 of a lstlisting

I'm trying to write a lstlisting-environment which sets the filename as line 0. I tryed \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{numbers=left} % @param 1 : ...
2
votes
2answers
82 views

Listings: add vertical padding without abusing frame

I have the following setup for my displayed listings: \documentclass[a4paper]{article} \pagestyle{empty} \usepackage{listings,xcolor,lipsum} \lstset{ backgroundcolor = \color{yellow}, ...
2
votes
1answer
51 views

how to wrap a long terminal command without real line breaking?

this may look like a duplicate question to this one and many, but really I had a hardtime in finding the desired solution. The breaklines=true didn't work as it breaks the long command. Hence simple ...
3
votes
0answers
46 views

How can I make listings look like minted?

Up until now I used the listings package for my code-listings. Today, I tried minted and I'm pleased with the default look. Since I'd have a lot to do to switch from listings to minted at this stage ...
0
votes
0answers
26 views

Is there a nice way to split an algorithm float over multiple pages?

I am using the algorithm float with an lstlisting in it containing the code. Unfortunately, the code is just a little too long to fit on one page. I'd like to keep the layout provided by the ...
0
votes
0answers
20 views

Call environment lstlisting without begin-end [duplicate]

I want to create a command for calling the lstlisting environment without the use of \begin{lstlisting}...\end{lstlisting}, i.e. I want to write something like \lst{text in enviromnent}. I have tried ...
0
votes
1answer
17 views

Coloring of @param and @return with Listings

Here is a MWE of what I have, along with a screenshot \documentclass[paper=a4, fontsize=11pt]{scrartcl} \usepackage{color,soul} % For text coloring and highlighting ...
1
vote
2answers
228 views

listings - highlighting additional keywords inside own delimiters (like Doxygen annotations)

According to listings - use different style for normal comments /* and doxygen comments /** I used listings package to set style for /** Doxygen comments */ as user defined delimiter moredelim = ...
3
votes
2answers
105 views

Emphasizing all occurrences of given word in document

Please forgive my naivety, but I have a fairly large TeX document and I was hoping that there was an easy way to do the following. I can create code blocks in the text using the following: ...
6
votes
2answers
60 views

Renewing the \thelstlisting command when hyperref is on

I'm trying to change the appearance of the cross-ref to a listing in the appendix, so that it prints as \textsc{a}.1, not just A.1. The redefinition ...
2
votes
1answer
31 views

hyperref to line number in listing imported from file

Can I refer to a line number from the imported file without escaping chars inside the file? Say, I import my file like this \lstinputlisting[language=c]{main.c} and I want to \hyperref{} line 50 ...
4
votes
1answer
36 views

How to have free accents in `lstlisting`

There are quiet some questions about getting accents like è into the lstlisting environment. But I actually want to have a free floating accent. However, Latex always changes it to some other symbol ...
3
votes
1answer
42 views

Listing inside table does not work after upgrade to MacTex 2015

I have updated my Latex installation to MacTex 2015 and the following latex code does not compile anymore: \documentclass[10pt]{article} \usepackage{listings} \lstset{language={java}, ...
2
votes
1answer
67 views

Customizing the list of listings from minted

This question is in regards to customizing the format of the list of listings produced with the minted package. In particular, I want to replicate the formatting produced via the tocloft for Figures: ...
5
votes
1answer
84 views

Align a floating lstlisting to the very top

The following code does not align the lstlisting entirely to the top, but keeps some unwanted space between the page's top and the listing. How can I align the lstlisting to the very top? ...
4
votes
1answer
20 views

How to make linenumber referencing in lstlisting work with autoref

This Link provides an answer to the question how to make line-number referencing work with lstlisting. However, if I use \autoref it will only return the number and not something like Line 31.
2
votes
1answer
73 views

Formatting R chunks when using knitr

How can I apply the same formatting with R chunks that I apply to regular listings? The following example shows a nicely formatting listing and an (IMHO) awful looking R chunk. I already loaded ...
1
vote
1answer
38 views

Formatting changes

I want some text to appear as below I am not getting the exact output. The code I have written is as follows (Please pardon me for lack of knowledge of Latex) \hspace{2mm} A simple paragraph of ...
5
votes
1answer
56 views

Delimit comment on special character

I have defined a new language in Latex (Clojure) but I'm having some issues with delimiting keywords. A keyword in Clojure is any alphanumeric string starting with a colon. E.g., :foo-bar-baz. So far ...
0
votes
0answers
29 views

Inline listing in ams environment drops space before mathescape

In http://tex.stackexchange.com/a/127018/83257 there is a patch to make inline listings work in math mode. When using this together with listings' mathescape option, the space after a math escape is ...
0
votes
1answer
60 views

Remove “space symbol” [duplicate]

I'm trying to write: LCD_write_String_to_Buffer("Esperando \nconfiguracion..."); but what I get is: I get like horizontal square brackets. Is there any way to remove all symbols and leave ...
3
votes
1answer
24 views

How to set optional argument for caption in a lstlisting environment

Usually, if I set a caption, I use \caption[short]{long} to have only a short description in my list of figure for example. But how do I do it with listings? Here a MWE which has a very long caption ...
3
votes
1answer
53 views

Allowing line break at C++ operators ('::', '->', …) in \lstinline

The following picture shows my problem: How can I tell \lstinline to break lines at specific C++ operators? For example: FooFactory::instance()->createFoo() should be broken as follows: ... ...
3
votes
0answers
43 views

How to add my listings to the table of contents?

I am using the thesul class. I would like to add my listings to the table of contents. I found a way to do that by using the \addcontentsline{toc}{spsection}{Listings} command: \tableofcontents ...
5
votes
1answer
47 views

beamer + lstlistings + overlay -> wrong numbering in caption

In my tex file I have the following code. It results in the Listing being numbered with an increasing index. Is there a way to prevent this from happening? (see screenshot: the second slide should say ...
5
votes
1answer
47 views

How to include Matlab code into LaTeX in colour? [duplicate]

I need Matlab code, e.g. the one here, in LaTeX and in colour (the comment is green, for/if/else/end is blue). % super cooles Programm i = 1 for i = 1:10 if i > 3 i=i+2 else ...
3
votes
1answer
74 views

Getting Swedish letters to work in LaTex

Problem: Issue 1 (solved): The Swedish letters ÅÄÖ/åäö do not print out correctly when used with listings package. Issue 2: How can it be solved so that the Swedish letters also get orange color ...
3
votes
1answer
26 views

Quoted code changes color when imported from source

I wrote a simple code to highlight syntax when I quote some C++ in latex. However, when the code is directly imported from a source file, the headers are in blue instead of green, this being the only ...
5
votes
2answers
608 views

Stop listings going over page breaks

I am using Pandoc to generate Tex from Markdown. It automatically generates listings when it comes across the appropriate Markdown (code indented four spaces). It then uses the listings package to ...
2
votes
1answer
46 views

NewEnviron, \BODY and lstlisting [duplicate]

I was trying to understand egreg's answer to Hide content to show later, and I noticed that there were some problems when using lstlisting or tcblisting environments inside the solution environment ...
25
votes
2answers
21k views

How to format an inline source code

I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options ...
2
votes
2answers
812 views

Code listing spanning multiple pages with captions at top

Is it possible to span a lstlisting environment or lstlistinginput on multiple pages, such that the caption is repeated on each page (the listing counter stays the same), as well as being able to ...
7
votes
1answer
2k views

Listing with line numbers inside a table

I typeset a lot of listings (using the listings package) inside (array-based) tabular environments. This works like a charm, however, breaks when I pass the numbers= option to the listing: ...
2
votes
1answer
29 views

How should multiline pieces of code be put into a table?

I have the following two pieces of information that I would like to present side-by-side in a Beamer slide. I think I'd like these two things in two cells of a two-column table. Is there a good way to ...
8
votes
3answers
101 views

Include a footnote in verbatim text

I have seen how to add verbatim text to a footnote: How to obtain verbatim text in a footnote? What I would like to do is the opposite, include a footnote in a verbatim section. I am using the memoir ...
1
vote
1answer
37 views

Margin notes in listing with float enviroment – Error: Float(s) lost

Based on this question: Margin notes in listing with float enviroment - Error: Float(s) lost I have now other question. The solution is working fine. But I want to use floats for listings, to prevent ...
1
vote
1answer
42 views

How to prevent line breaks in code listings?

I am adding a big Linux terminal output as a listing and would like to prevent these line breaks from happening: e.g. user@pc ~ $ top PID USER PR NI VIRT RES SHR S %CPU %MEM ...