{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
1answer
38 views

How can I use underscore in listings package properly?

I understand that underscore is a special character in LaTeX, but how can I input underscores within lstlisting blocks without changing the code block itself? Here is a short example: Settings: ...
4
votes
2answers
186 views

Sourcecode colorization for more than one programming language

I want to colorize my source code. I followed this page and everything works fine. My problem is that I am using 4 different programming languages: Have I to define the \lstset{} tag separately for ...
0
votes
1answer
50 views

Defining keywords for SQL using listings

Problem: I use listings package to highlight SQL code but for some reason, unknown to me, I can't get certain keywords in SQL to highlight in a different color. Minimal Working Example: ...
1
vote
0answers
15 views

Listings With Two or More Sets of Keywords [duplicate]

I am looking for a way to create two different sets of keywords, because I want to assign each set of keywords a different color. The language of the code I want to import, is not supported by the ...
4
votes
1answer
78 views

Curly braces as comment delimiters

In the language I am defining in listings, text put inside {* and *} is commented out. I tried to implement this as morecomment = [s]{{*}{*}}, but understandably LaTeX gets the nesting confused. The ...
21
votes
1answer
7k views

How can I use LaTeX-commands inside of a listing?

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the ...
4
votes
1answer
82 views

Setting style for Python docstrings in lstinputlisting environment

I am using the listings package for source code in my LaTeX document. I am trying to set the style for docstrings in the Python programming language: \documentclass{article} \usepackage{listings} ...
5
votes
1answer
112 views

How to reference source code listing

I am using the listings package to incorporate listings into my paper. However I'd like to reference individual parts of the code with a small circular number (such as say the number 1 in white ...
2
votes
2answers
109 views

Some problem with listings and C++

I have to insert a C++ code in a .tex file but I want that is written with the text coloured like in the C++ program. If I use lstlisting there is the C++ program but in b/w. Any idea?
2
votes
1answer
39 views

listing in two-column mode

I want to place a listing, with colored background, in a two-columns document. For safety (for cases when the width of listing only slightly exceeds column width) I put the listing in a \maxsizebox. ...
1
vote
0answers
49 views

Re-using tikzmark names?

It seems that tikzmark names can't be re-used. In the code below, I try to draw a box outline in the first lstlisting section, and a filled box in the second lstlisting section. In each lstlisting, ...
4
votes
2answers
73 views

Drawing a rectangle around text inside lstlisting

I'd like to draw a rectangle (outline only, not filled) around a few words inside an lstlisting environment. I've tried the following, but it doesn't treat the text inside the box as "verbatim" as ...
2
votes
0answers
36 views

How to fix “Dimension too large” error with lstlisting

I use listings as the verbatim enviroment. However, I get the "Dimension too large" error with very long lines. The following is a sample code. \documentclass{article} \usepackage{listings} ...
0
votes
0answers
30 views

Forcing page break of a minted listing with \centering on

I am using minted to create a code listing. I need the listing to be centered so according to this solution, I use the \RecustomVerbationEnvironment to escape the verbatim environment so that it can ...
5
votes
1answer
68 views

Using different colors for different keywords in lstlisting

I've looked through a few answers on here, and either they don't work or don't fully answer my question. I have to format some C++ code and I want it to have these colors for these specific keywords ...
2
votes
0answers
25 views

Using Listings Package: the Colour of the Text After the Listing is the same as that of the Identifiers Inside the Listing

So I have some LaTeX which looks like \usepackage{graphicx,bm,times, hyperref, amsmath, listings, xcolor, enumitem} \lstset{language = C++} \lstdefinestyle{customcpp}{ ...
4
votes
1answer
29 views

Double delimiters in listings

Using the listings package, one can define a format for some arbitrary set of delimiters and the characters enclosed within. However, when using double delimiters, the specified format doesn't apply ...
3
votes
1answer
73 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: ...
3
votes
2answers
2k views

LyX Error: Could not find LaTeX command for character '' (code point 0x2009)

I have been trying to copy and paste some code into LyX (via the 'Program Listings' menu item), and when I compile the document I get the LyX error: Could not find LaTeX command for character '' ...
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}} \\ ...
4
votes
1answer
62 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 ...
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 ...
7
votes
2answers
310 views

Can comment delimiters be typeset in a style different from commentstyle?

Using listings, I'm trying to typeset single-line comments in a very specific way: although whatever follows should be typeset according to the value passed to the commentstyle key, the opening ...
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 ...
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}, } ...
0
votes
2answers
169 views

What's a good way to insert very few lines of code?

I know about the listings package, but it seems that it can't be put where I want it to be (h in float). And since I just maybe want to insert exactly one line of code, I really want it to be where I ...
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
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 ...
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 ...
3
votes
1answer
62 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} ...
2
votes
1answer
106 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 ...
5
votes
2answers
588 views

Bad Character code (256)/ \select@language{greek}

I was trying to install minted package in TeXLive. I installed it and then run sudo tlmgr update --all. It was running slow so I stopped it using Ctrl+Z in an ubuntu terminal and then I run sudo tlmgr ...
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 ...
1
vote
2answers
38 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 ...
1
vote
1answer
46 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 ...
1
vote
1answer
65 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 ...
2
votes
1answer
69 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 ...
2
votes
1answer
97 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 ...
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 ...
2
votes
3answers
983 views

Define a new environment to combine tikzpicture and lstlisting

I would like to define a new environment to combine the tikzpicture environment from package pgf/tikz and the lstlisting environment from package listings. The result would be to first produce the ...
10
votes
2answers
343 views

How to add listings environment to DTX files

I am working on my first DTX file and want to add a code example, which shall be printed with listings. This works so far, but since the documentation is commented the listings code is using a full ...
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} ...
7
votes
2answers
5k views

Use $ in lstlisting

I need to create some jQuery-Listings but when I try to do so \documentclass[12pt,oneside,a4paper]{scrartcl} \usepackage{textcomp} \usepackage{listings} \usepackage{color} ...
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
43 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
65 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 ...
4
votes
0answers
86 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 ...