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

Format code listing package

I am documenting a script which has almost 43+ keywords. The output I want is something on the below lines... and the latex code I have is \documentclass[a4paper, onesided]{article} ...
4
votes
1answer
33 views

Beamer: Section used before declaration

I'm creating a presentation using beamer and listings - when I end a section with a {lstlisting} call, the next section title appears in the slide. Is there a way that I can specify when the next ...
1
vote
1answer
40 views

How to use lstlisting “moredelim” inside quoted text [RESOLVED, but with possible caveats for others]

update: Arun's answer, below, works for me, since I'm not using syntax highlighting anyway. Thanks! Here's my original question: I use the following setting to allow me to mark text as bold within ...
3
votes
1answer
39 views

Why does this listings command keep giving me this error?

\documentclass[titlepage]{article} \author{foobar} \title{foofoofoo} \usepackage{syntonly} \usepackage{verbatim} \usepackage{lipsum} \usepackage{listings} \begin{document} \maketitle \newpage ...
1
vote
1answer
22 views

Setting different environment setup depending on the location in two column (also considering the figure environment)

I asked about using listings environment to put the line numbers left or right side according to the location. Setting different environment setup depending on the location in two column The code ...
1
vote
1answer
38 views

Setting different environment setup depending on the location in two column

I have a lstlisting environment that shows a line number either left or right side of the document. Setting up lstlisting environment by passing parameters Setting the ruby code in a two-column ...
3
votes
1answer
31 views

Setting up lstlisting environment by passing parameters

I have listing setups (rubyl/rubyr) for ruby for the case the line numbering is on the left or right hand side. \lstdefinelanguage{rubyr}{ escapechar=\, basicstyle=\scriptsize\ttfamily, ...
0
votes
1answer
74 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: ...
2
votes
1answer
53 views

lstinputlisting not recognizing comment character

I have some code which I like to incorporate in to my latex document. I have set up the aesthetic so the code is easy to read as follows \lstdefinestyle{numbers}{numbers = left, stepnumber =1, ...
2
votes
1answer
52 views

Using an overlay on lstinputlistings in latex

I want to have to multiple overlayed lstinputlistings on one slide in a presentation, created with latex and documentclass beamer. The only solutions I find are for lstlistings, but those don't work ...
4
votes
2answers
206 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 ...
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 ...
5
votes
1answer
55 views

Conflict with subcaption and sublisting?

In the code below, partially derived from Split subfigures from pgfplots groupstyle, I am not able to compile my code when I include the sublisting environment. I need this listing for my Python code ...
4
votes
1answer
91 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 ...
4
votes
1answer
101 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} ...
1
vote
1answer
94 views

Ignore errors in environments in latex-suite in vim

I use the latex-suite vim plugin, which shows me errors inline in my vim editor. However, I get false positives for certain environments like lstlistings. How can I configure latex-suite to ignore ...
5
votes
1answer
152 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
1answer
45 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. ...
2
votes
2answers
122 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?
1
vote
0answers
57 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, ...
3
votes
1answer
61 views

How to dump listings to a file?

I thought to share my solution to a problem I had. (This is one of those “answer your own question” things, plus, this way, people can improve upon it – dual-licence under The MirOS Licence please. ...
4
votes
2answers
90 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
49 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
44 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 ...
2
votes
0answers
28 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
33 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 ...
5
votes
1answer
127 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 ...
3
votes
1answer
87 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
52 views

\lstlisting in \multicolumn in a macro [closed]

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
46 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
29 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
43 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
84 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
51 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
33 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
40 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
49 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
57 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
53 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
84 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
68 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
137 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
90 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
111 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
538 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
67 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
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
58 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, ...