{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

2
votes
0answers
22 views

How to use onslide in a listing?

I need to animate single contiguous code listings by showing and hiding parts of code using \onslide. However, TeX is complaining. How can I achieve this? I tried the advice here but it didn't work. ...
2
votes
1answer
25 views

Skipping line numbers in lstlisting

Referring to Skip line numbers and resume from specific number I tried to skip several line numbers in my listings and continue with a specific number. But in my case there is a really bad side ...
0
votes
1answer
26 views

Using setmonofont with Bera Sans Mono in Beamer produces garbled output

I am using Bera Sans Mono as the monospaced font for typesetting code listings using the listings package. This is done for slides which are produced using beamer and XeLaTeX. My preamble includes the ...
5
votes
1answer
15 views

Can't escape curly braces in \lstinline

Upon trying to typeset the following TeX I get the error: Too many }'s. ...handleClick } >Button component} TeX: \lstinline{<Button onClick=\{this.handleClick\}>Button ...
2
votes
2answers
50 views

Highlight asterisk in lstlisting

I would like to emphasise the asterisk used in \begin{equation*} in lstlisting. I have tried using emph, also including the alsoletter macro, but it doesn't work. Why not? \documentclass{article} ...
0
votes
0answers
14 views

How to get Unicode in code listings? [duplicate]

I want to use Unicode text (a mixture of cyrillic and japanese characters) in a code listing that uses default LaTeX fonts (in other words, source code fonts are left to default). However, for all ...
0
votes
0answers
7 views

lstlisting indentation versus editor-formatting [duplicate]

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
33 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
29 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 ...
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} ...
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 ...
1
vote
1answer
32 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
14 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 ...
3
votes
2answers
30 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, ...
4
votes
1answer
108 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} ...
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
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 ...
0
votes
0answers
27 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 ...
3
votes
0answers
47 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
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 ...
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 : ...
3
votes
2answers
106 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: ...
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 ...
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 ...
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}, ...
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? ...
2
votes
1answer
69 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: ...
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.
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 ...
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
61 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 ...
2
votes
1answer
77 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 ...
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: ... ...
5
votes
1answer
48 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 ...
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 ...
3
votes
1answer
53 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

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
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 ...
2
votes
1answer
49 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 ...
3
votes
1answer
75 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 ...
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 ...
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 ...
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 ...
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
0answers
13 views

Is it possible to include a lstlisting code block inside an lstlisting? [duplicate]

I am trying to include a LaTeX code within an lstlisting. But the problem is that the LaTeX code includes an lstlisting, so the \end{lstlisting} within the included code is terminating the actual ...
5
votes
1answer
55 views

Rewrite \begin{foo}\end{foo} to \begin{bar}{opts}\end{bar}?

I know this is likely a simple Latex macro question. I've got a large document with a ton of lstlisting blocks, and I'd like to use minted instead. That means turning blocks that look like this: ...