{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

3
votes
1answer
71 views

Questions about including source code in a TeX file

I'd like to include some Sage code in a TeX file. Originally I thought the right way would be to use $\texttt{}$ whenever I had to include the source code, but then I ran into some difficulties: ...
1
vote
0answers
42 views

\lstlisting in \multicolumn in a macro

I want to create a macro for putting a multiline JSON code in a multicolumn row in a tabular environment... \newcommand{\apiMethodRequest}[1]{ \multicolumn{5}{l}{\cellcolor{DsnGreen}{Request}} \\ ...
2
votes
1answer
33 views

Crossreference \lstinputlisting code

I frequently need to put C code into my document, so I defined, \newcommand{\Ccode}[1]{\lstinputlisting[backgroundcolor=\color{gray!5},caption=\texttt{\lstname},language=C]{C/#1}} in my document ...
1
vote
0answers
25 views

listings: enable language settings only inside delim

I wish to enable language settings (keyword, string etc.) only inside delimiter. Example based on Jubobs answer to question about highlighting oneline delim. \documentclass[a4paper, 12pt]{article} ...
3
votes
1answer
34 views

listings: Highlight one-line delim without the delimiter itself

I would like to use a one-line delimiter (with [l] parameter), but without highlighting the delimiter itself; something like sqlite> .open ex2.db What follows sqlite> should get highlighted but ...
4
votes
1answer
58 views

Use listings in tufte-book with captions in margin

In my tufte-book document I would like to show source code listings using the listings package but with their captions in the margin. Modifying the code for typesetting the listing caption is not ...
0
votes
1answer
42 views

lstlisting - keep hyphens/dashes from combining into one

I'm using lstlisting to display some ProLog code, in this code I need to add 5 dashes after another: -----, but they keep combining into one line, which is not what I want. I tried using \lstinline ...
1
vote
1answer
24 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
32 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}, } ...
4
votes
1answer
42 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
53 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
37 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
60 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
45 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
103 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
74 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
66 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
504 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
1answer
42 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
36 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
35 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} ...
1
vote
1answer
47 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
42 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
63 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
23 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} ...
1
vote
1answer
26 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
85 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
37 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
48 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
57 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
45 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
57 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
52 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
21 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 ...
1
vote
1answer
92 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
32 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
70 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
77 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
39 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
50 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
40 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
25 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
65 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
57 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
75 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
68 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
22 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
81 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} ...