{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

1
vote
1answer
52 views

Unicode character in listings

I need to insert character "└" in lstlisting and compile it with pdflatex. Other unsupported characters like "ě" I am handling via literate option in \lstset{}. Is there any way how to insert it? ...
0
votes
0answers
61 views

lstlisting in tabular

I try to put code into a table. custom lststyle: \lstdefinelanguage{XML} { identifierstyle=\color{darkblue}, } \lstdefinestyle{my-xml-style} { basicstyle=\ttfamily\footnotesize, ...
2
votes
1answer
124 views

Listings: Skip line number on current line

So I am trying to use the listings package to show some source code. However I would like to be able to skip line numbers for certain lines, such that the do not receive any line number, but does not ...
1
vote
1answer
27 views

Decimal number coloring give unwanted space in lstlisting

I'm trying to set coloring for decimal numbers in lstlisting. Here is my code: \documentclass[border=2pt]{standalone} \usepackage{listings} \usepackage{color} \definecolor{codeblue}{rgb}{0,0,1} ...
2
votes
1answer
38 views

lstlisting breaks ifbool block

I have the following piece of code: \documentclass{article} \usepackage{etoolbox} \usepackage{listings} \newbool{xyz} %\booltrue{xyz} \boolfalse{xyz} \begin{document} \ifbool{xyz}{ ...
4
votes
0answers
112 views

How to emphasize or highlight single words in comments in listings?

I'd like to highlight single words (or phrases) in the comments of C files displayed by the listings package. Using the emph key does not work in comments (apparently listings is too intelligent in ...
1
vote
0answers
23 views

listings “escapeoutsides” [duplicate]

I know, it's escapeinsides. But how can I show only the part of code? Not by linerange? But by "word" range? For example i will show only code from //<B> to //<qB> //<A> class A{ ...
2
votes
1answer
60 views

How to not override string style by literate in lstlisting?

I'm trying to do color code listing for java. I use this definition: \usepackage{listings} \usepackage{color} \definecolor{codeviolet}{rgb}{0.65,0.11,0.36} \definecolor{codeblue}{rgb}{0.1,0.21,0.57} ...
0
votes
1answer
87 views

Remove horizontal lines above and below the code - listings package

How can I remove the black lines above and below the code here: \usepackage{listings} \usepackage{color} \definecolor{dkgreen}{rgb}{0,0.6,0} \definecolor{gray}{rgb}{0.5,0.5,0.5} ...
2
votes
1answer
67 views

Float listings in LyX with classicthesis style

I can not figure out how to insert floating listings in LyX with (or without) classicthesis style. Any hints would be highly appreciated.
3
votes
1answer
67 views

Different frame style for different sides in listings

So, I'm using the listings package to stylize source code (I'm currently using the solarized colour scheme). I've set a frame to have a coloured background for the line numbers. I don't want this ...
2
votes
1answer
61 views

Listings inside tabularx table?

I'm doing a very long sidewaystable with tabularx. The thing is that I have a lot of text in columns: I did it using minipage and enumerate. The thing is that I was wondering if there's any way I ...
0
votes
3answers
59 views

how to insert any utf-8 char in lstlisting? especially '⮀', a character without LaTeX equivalent

I need to insert a text with ⮀character (u+2b80), in a document. Is there any way? I've tried: \literate {⮀}{{???}}1 but can't find what to write instead of ???. Any suggestions?
1
vote
1answer
24 views

change font as well as size in listing

I am including some R codes in my thesis using listing. I want to have the codes in footnotesize and in ttfamily font. I can get either of them by using lstset{basicstyle=...}. But I cannot figure out ...
2
votes
1answer
215 views

beamer: \only and lstlisting do not work together

I have a slide divided in two columns and one of them should include code inside a block that changes in the following slides. This code works: \documentclass{beamer} \usepackage[utf8x]{inputenc} ...
0
votes
0answers
47 views

Two columns — listing line|latex comment line

I'd like to list code in the following manner, but not in a table-structure (which would mean that i'd have to include each 'code line' individually). I'd like to include the code listing from one big ...
0
votes
2answers
89 views

Converting latex highlighted code listing to image

Does someone know how I could submit a paper to a journal which contains source code highlighting with minted https://github.com/gpoore/minted ? I really like the highlighting and don't want to go ...
0
votes
0answers
82 views

Using menukeys within lstlisting

I'd like to use the menukeys package to print keyboard key symbols like "enter" or "ctrl+c" in a listing. They should (1) not change the alignment of other characters, (2) keep some distance to ...
0
votes
0answers
44 views

Problem with quotation spacing in listings

I'm having a problem where my quotes are being processed in inline listings rather than just literally being output. An example of the problem I have is below where despite there being a space after ...
0
votes
1answer
44 views

How to get consistent rule lengths for algorithmicx and listings floats?

In the following MWE, I would like the rules (the gray lines above and below the floats) of both environments (listings and algorithmicx, resp. algpseudocode style) to have visually (I'm not aiming ...
2
votes
1answer
51 views

How to position a listing correctly?

I have a situation similar to the following code: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{inconsolata} \usepackage{color} \usepackage{graphicx} ...
2
votes
0answers
46 views

tex4ht and listings: lines don't break when using escapeinside

This is the first I'm posting a question. So, I hope I don't do anything wrong. I've tried to get HTML from my latex document by using tex4ht. For cross-referencing within the lstlisting environment, ...
3
votes
1answer
29 views

How to use correctly the reference on lstinputlisting command?

In my tex I have this command: \lstinputlisting[breaklines=true,label={lst:use_case_ip}]{ch5/code/get.txt} \captionof{lstlisting}{HTTP Request where string was found} which generate 1.2 value when ...
1
vote
1answer
93 views

How can I specify a short caption for a listing?

One of my listings has a very long name. In the \lstlistoflistings table of contents, I would just like to have a shortened version of it. How can I specify an abbreviated name for my listing? ...
4
votes
1answer
67 views

How to add caption correctly in listing?

I have two blocks lstlisting and another listing as follows: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{inconsolata} \usepackage{color} \definecolor{pblue}{rgb}{0.13,0.13,1} ...
3
votes
1answer
117 views

How to display the symbol dollar $ correctly?

I have a minted block as follows: \documentclass{article} \usepackage{minted} \usepackage{listings} \begin{document} \begin{listing}[ht] \begin{minted}{xml} <plugin> ...
1
vote
2answers
85 views

pass escapechar to newcommand inside listing

i have defined a new command for colored bold text as follows to use in listing environment: \definecolor{mycolor}{rgb}{0,0.8,0} \newcommand{\lstemph}[1]{\textcolor{mycolor}{#1}} In my ...
0
votes
0answers
38 views

Keep keywords in comments - listing - LateX

Is it possible to keep the keywords highlighted in comments in the listing package of LateX? I want to be able to define two types of comments: one for normal comments and the other one for ...
3
votes
1answer
134 views

Underline in lstlisting environment

I would like to get the same result I get with \underline in a lstlisting environment. I was almost sure I got it in this way: \documentclass{article} \usepackage{listings} \usepackage{upquote} ...
2
votes
1answer
41 views

Bash script between report lines - Line Breaking

I'm using the following commands to introduce bash script text in the middle of a report: \newcommand{\shellcmd}[1]{\\\indent\indent\texttt{\footnotesize\# #1}\\} \begin{document} \noindent ...
3
votes
1answer
410 views

How to change verbatim text to Consolas?

How to change the verbatim text so that a zero shows up with a slash across it? I would like to know if the verbatim text can be changed to say Consolas? Here is my code: \documentclass{article} ...
1
vote
1answer
32 views

Re-position of contents after uncover of other contents

Updated: Considering the following latex document: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[t,fragile] \frametitle{Implementing FA} ...
2
votes
1answer
177 views

Uncover lstlisting on a particular slide using \onslide or \uncover

Updated: How can I uncover a certain lstlisting environment on a particular slide using \onslide or \uncover? For example: \documentclass{beamer} \usepackage{listings} \begin{document} ...
3
votes
2answers
209 views

lstlisting: how to underline a keyword?

In the following, I am trying to underline the keyword 'true' in a C++ code listing. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage[lighttt]{lmodern} % bold and italic ttfamily ...
1
vote
1answer
109 views

Multipage listings with minted and captions

I have source long listings (2+ pages) that I highlight using minited via \inputminted. I wish to have have a caption and a reference label for the listing in \listoflistings and in my text when I ...
3
votes
1answer
53 views

force at least two lines on a page in using lstlisting

I use the lstlisting package a lot in my theses. Unfortunately, it sometimes renders the caption (at bottom of the listing) on the next page or starts the listing at the end of a page, renders no line ...
2
votes
1answer
48 views

Large table in “programming” type font

In my code below, the table appears in a "programming" type font. If I have a larger table (like say in a text file), how can I import that table into my document without having to typing the whole ...
2
votes
1answer
65 views

Listings - Only highlight between delimiters

I want to implement a function name color highlighting and I use the listings package. My 'regex' for this is def %s( where def (including space) is the first delimiter %s is the function name and ( ...
2
votes
1answer
133 views

How to properly number between lstlisting and listing the same latex file?

I'm having trouble with the legend of the lstlisting and listing the latex file when I reference them both are appearing as listing 1. How do I display the number of correctly caption for listing 1 ...
1
vote
1answer
158 views

Fitting codes in a Latex Code block

\usepackage{listings} \begin{document} \lstset{language=Java} \begin{lstlisting}[frame=single] PDDocument doc = PDDocument.load(file); String ...
2
votes
1answer
137 views

how can I explain a MATLAB code in my document like picture?

I have a matlab code and I want explain part of them like picture. or any other idea can do better. \documentclass{article} \usepackage{listings} \usepackage{color} %red, green, blue, yellow, ...
7
votes
1answer
97 views

Listing creation fails with “dimension too large” given a large block of characters

When creating a code listing, we recently ran into a strange error from the listings package. Specifically, listings bails out on a large block of text. Here's a minimal working example: ...
2
votes
0answers
91 views

lstlisting with sublistings and captions and floating environment

I try to create a floating environment with a layout similar to this: _____________________ ___________________ | | | | | | | | ...
3
votes
1answer
127 views

Packages used in this image?

Does somebody know which packages were used to create the following homework assignment? I would like to insert Java source code in exactly the same way in my .tex files
3
votes
1answer
109 views

mixing minted with lstlisting

I have a List of Listings that looks like this: The first listing, which is correct, uses lstlisting. 3.1 is the correct chapter. The second listing uses minted. Somehow it shows 1 as chapter, ...
0
votes
0answers
45 views

How to fix comment indentation of code using the listings package?

My problem is that the code itself is indented correctly, but the comments (e.g. //comment) are not. In my source file, I aligned comments in one column by using tabs. In the pdf produced by LaTeX, ...
2
votes
1answer
64 views

How to prevent \settocdepth{chapter} lead to an empty list of listings

Why does uncommenting the (IMHO innocent) call to \settocdepth{chapter} in the following MWE make the list of listings become blank? Or rather: what can I do to both preserve a chapter-only TOC for ...
1
vote
0answers
34 views

Passing optional arguments to a listing environment based on conditionals

I am trying to make a presentation which can optionally compiled for handouts. This presentation also contains highlighted code snippets. For highlighting I use the code from this question. (Which ...
2
votes
2answers
110 views

Colored background in listings environnement

I would like to make my listings environnements more readable by coloring the background of some keywords with a specific color. Like this : I thought using the \colorbox function from xcolor ...
7
votes
3answers
239 views

lstlisting: color LaTeX commands like `\\` or `\!`

How can I achieve it with lstlisting, that LaTeX commands like \\ or \! are properly highlighted as syntax? Adding those commands (with or without backslash) to moretexcs does not deliver the indented ...