{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
67 views

linebreak with \lstinline

Why does \lstinline not break lines correctly like with \begin{lstlisting}? The text goes over the documentborder with \lstinline. Thank you! \documentclass{scrreprt} \usepackage{listings} \lstset ...
2
votes
1answer
52 views

\lstinline: color of “#pragma”

I am trying to use \lstinline but it does not work as expected: \documentclass{scrreprt} \usepackage{color, listings} \lstset { language=C, keywordstyle=\color{blue}, } \lstset{language={[...
4
votes
1answer
55 views

Why does this syntactic element not get properly highlighted by matlab-prettifier?

I've found that the matlab-prettifier does not highlight all the syntax compared to the original file. For example, here is a snapshot of part of the file I am trying to include in my document from ...
1
vote
0answers
68 views

How to color numbers in certain parts of a lstlisting

So, I'm a student and my teacher posted this kind of "how to make XML look cool in LaTeX". We were using it in class but I noticed some errors. For example, when printing numbers inside the labels (...
1
vote
2answers
63 views

Shortcut for listinputlisting reference

I would like to know if it is possible to set up a command such that when the \ref of the Matlab \lstinputlisting is called, that the words "Matlab Algorithm X.X" itself becomes a hyperref link and ...
3
votes
1answer
101 views

How to avoid “overfull” warnings with tcblistings and parskip package?

Consider the following MWE: \documentclass{article} \usepackage{lipsum} \usepackage{tcolorbox} %%% this two following packages are used in the format I have to use \usepackage[parfill]{parskip} \...
1
vote
1answer
94 views

It is possible to define “styles” in tcolorbox listings? [duplicate]

I am writing a document where I use tcolorbox to list code. I would like to have a couple of commands to list code from an external file, and one (or two) environment for inline snippets. What I have (...
2
votes
1answer
150 views

lstlisting environment with caption on the first line separated with a dashed border

Still on my way to write my own LaTeX class file. My today's purpose is to write an environment similar to the result available here, in the Arch Linux Media Wiki. My question is deeply linked with ...
4
votes
1answer
100 views

Supressing the very first line number in the code

So I have looked at the following: Suppress line numbering for specific lines in listings package And the solution works great for the nth line of code. What if I want to suppress the very first ...
2
votes
1answer
194 views

Float for lstlisting

I'm trying to set float to my lstlisting (It means lstlisting without pagebreak). I found 2 ways, but it not works for me: Float attribute in lstlisting. It is OK only for lstlisting then count of ...
17
votes
1answer
553 views

How to display LaTeX code and the typeset version next to each other without repeating myself?

I would like to write some LaTeX code, and without repeating myself, I would like that to be used for displaying that particular piece of code as-is and its typeset version, next to each other. The ...
4
votes
3answers
76 views

Listings: Define new language from Emacs highlighting

In my document, I need to include code written in Macaulay2, which is not a predefined language in listings. To define it myself, I started looking for a list of keywords, and found the variable ...
1
vote
0answers
37 views

Frame structure is not working [duplicate]

For my following code, the frame is not working. Latex gives a lot of errors, such as Undefined control sequence \end{frame}, Illegal unit of measure (pt> inserted) \end{frame} I cannot find ...
1
vote
0answers
36 views

Listing next to the tikzpicture [duplicate]

I'd like to ask you about the way of putting the listing next to the tikzpicture. Is there any way to place lstlisting as it is shown below? \documentclass[12pt]{article} \usepackage{tikz} \begin{...
1
vote
1answer
55 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? ...
2
votes
1answer
198 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
30 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
42 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}{ \section{...
4
votes
0answers
133 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
94 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
158 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} \definecolor{mauve}{...
2
votes
1answer
72 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
73 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
66 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
74 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
331 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
48 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
101 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
88 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
49 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
47 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
52 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} \definecolor{pblue}{rgb}{0.13,0....
2
votes
0answers
50 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
121 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
85 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
149 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
93 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
40 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
160 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
44 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
543 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
41 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} \begin{minipage}{.45\...
3
votes
1answer
248 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} \begin{...
3
votes
2answers
258 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
148 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
62 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
49 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 ...