{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

6
votes
2answers
964 views

Copy-pasting leading whitespace and blank lines in listings package (pdf) [duplicate]

I'm trying to use the listings package to typeset some code in a PDF document, in a way that allows me to copy-paste the resulting code. This mostly works well, if ...
4
votes
1answer
81 views

How can I get identifier style to apply to '%' (in a Perl listing)?

When using Perl variable names with sigils with listings, the $ and @ sigils somehow get coloured in identifierstyle, but the % sigil remains unstyled. Therefore, this code: \documentclass{article} ...
0
votes
1answer
226 views

Caption below lstinputlisting in multicols + redefining lstlisting caption format

I have 2 problems with caption for lstlisting. I can't get the caption of lstlisting to go below the list when it's in a multicols environment. Although I've added ...
4
votes
2answers
134 views

Math escape in listings and surround white space

I want to use the double right arrow for some Scala code in listings. I thought I'd use the mathescape option and $\Rightarrow$. However, this "eats" whitespace around it, e.g. if I have foo ...
2
votes
1answer
81 views

Multiple listings in one box with sub captions and using listings counter

I am using separate counters for (graphics) figures and listings. I am using the caption and subcaption packages. I construct sub-figures using subfigure: \begin{figure} ...
3
votes
1answer
94 views

Caption package destroys center/varwidth

I have received a wonderful comment how to get listings centered: \documentclass[a4paper]{book} %\usepackage[hang,small,it,hypcap=true]{caption} % screw hypcap \usepackage[T1]{fontenc} ...
2
votes
0answers
48 views

Center a Listing [duplicate]

What is a simple way to make a lstlisting centered? Like \documentclass{article} \usepackage{verbatimbox} \usepackage[T1]{fontenc} \usepackage{fancyvrb} \usepackage{listings} \lstset{ ...
5
votes
1answer
81 views

\lstset{numbers=none} not working

I'm trying to have LaTeX examples in a document. I use the showexpl package which lets me use the listings package options. Because all fragments are short, line numbers are redundant. The following ...
5
votes
1answer
63 views

Font for inline Listings is not changing

I am writing my thesis in LaTeX and use \lstinline{} a lot. The problem is that the font on the output does not change to 'this', but rather continue like 'this'. How do I correct this behaviour? I ...
6
votes
1answer
180 views

How can I put a curly brace inside a listing to group code lines?

I am using the listing package. Is it possible to use curly braces to group some lines in the listing so as to be able to put an explanation to the right? I'm trying to use the code given in Peter ...
3
votes
1answer
67 views

How can I use \vfill in a lstlistings environment?

I'd like to do something like this: \begin{lstlisting} public do(int whatever} { \vfill } \end{lstlisting} So basically, I want a method definition and then add spaces in the body of the method ...
2
votes
1answer
130 views

listing package error

I am using listing package for inserting code snippets in my thesis in several chapters of my thesis. I use the following style to insert code snippets : \lstset{emph={sensors, string}, ...
7
votes
1answer
94 views

Wrong border position on tabular when using lstlisting

I have encountered a problem while using tabular environment. The following code \documentclass [12pt,a4paper,oneside]{report} \usepackage {listings} \usepackage {fontspec} \usepackage {enumitem} ...
4
votes
1answer
147 views

Wrap lines of code with curly bracket and add some text next to it

I am currently studying algorithmic complexity of some programs, I have to deal with lines and lines of code and it would be really nice and helpful if I could wrap some of those lines in a right (or ...
3
votes
1answer
95 views

How to wrap floated minted listing in my own environment?

Here's what I'd like to do: \begin{code}{c}{Hello World in C}% I would prefer the caption to be optional #include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; } ...
7
votes
1answer
116 views

Printing index of keywords in listings for first mention only

I am writing a technical report, which integrates chunks of code using listings. I would like to add an index of the keywords used in the listings (using index=[1][keywords]), but reporting in the ...
1
vote
0answers
198 views

Change font style for \texttt [closed]

I am afraid if this is a repeat question. I have checked the following links for any hints: Change font size of \texttt globally? Using same font for \texttt and \Verb The question is simply. I ...
7
votes
1answer
140 views

Listings - break on whitespace+

I'm using listings for the first time, and have some rather long lines of code. I get that I can break lines automatically with breaklines=true, and I can break only on whitespace with ...
1
vote
0answers
69 views

Can I get the list of all letter/digit/other characters inside LaTeX? [closed]

I'm searching for a command which is (almost) the inverse of \catcode. Is there a command to print all the characters of a character group? Use-case: disable linebreaking of listings at all but one ...
3
votes
1answer
480 views

Problem with lstlinsting biblatex utf8 T1 and babel

I am a Spanish speaker. I have in my TeX file all the usual stuff for my language. Also I use lstlistings and now I want to use biblatex (ex bibtex user). However I can not get working together this ...
0
votes
0answers
65 views

How to undo the feasible breakpoints of `lstlisting`?

Is there a way to prohibit pagebreaking at the beginning/end of an lstlisting environment? I'm trying to keep together the following two pairs of lines: the first line of lstlisting and the line ...
4
votes
1answer
179 views

How to avoid double dash seem as a continuous line?

I'm using listings to show some source code (bash scripts) in my document but there is a problem, when using mono spaced fonts, the space between dashes is very small and in the printed document two ...
4
votes
1answer
149 views

Making Inline Code Printing Pretty

I have to include small code snippets like method and class names within continuous text. I do not want to display those snippets as complete seperated listings, they should be displayed inline, ...
5
votes
1answer
145 views

Unicode characters in a listing environment are not colorized!

When using the package listing, colorized comments will not yield colorized exotic unicode characters. This is a minimal working example: \documentclass{minimal} \usepackage{ ...
7
votes
1answer
105 views

How can I arrange 3 equations in boxes with arrows like this picture?

Can any one tell me how to make a figure exactly like this picture, with 2 arrows etc. This is my unsuccessful attempt: \begin{figure}[ht] \centering \begin{minipage}[b]{0.35\linewidth} ...
4
votes
1answer
143 views

Color lines in source code that is embedded in LaTeX

I am looking for a way to mark some lines in a source code sample that will be integrated into my LaTeX code. I already found solutions to embed source code and have syntax highlighting like this ...
4
votes
1answer
98 views

Listing composed of multiple “sublistings”

As a workaround currently I am using framed Verbatim, but I would like that this set of listings appear as a single listing in the list of listings the codes be rendered by the listings package ...
0
votes
1answer
109 views

Using listing with minted gets wrong listoflistings

I wanted to make a \begin{minted} block to show on the ToC in Listings section with a link to its label. So I did (with links to my Github working repo) \begin{listing}[!h] \begin{minted}[ ...
2
votes
1answer
63 views

How can I get rid of bold just for one word in the listinings environment?

I have the following Matlab code in my Latex file: \documentclass[a4paper,12pt]{article} \begin{document} \begin{lstlisting}[frame=single,escapeinside={@}{@}] gamma=[1/4,3/4]; ...
1
vote
1answer
91 views

Could someone explain how to fix the 'listings.sty' issue in a very “for dummies” way?

I've been trying to use the listings package, but whenever I try to install it I get the message: ! LaTeX Error: File `listings.sty' not found. I'm new to LaTeX and I have no clue how to do ...
3
votes
0answers
143 views

Is TeX the only document creator with syntax highlighting? [closed]

Is there any other document creator software other than TeX (word processor, DTP, webapp etc.) that can include syntax highlighted source code in a number of programming languages? For me it seems ...
1
vote
0answers
52 views

Dropping boxes on top of the listings environment [closed]

I was wondering if anyone knew a decent way to drop boxes of text on top of the listings environment. This would be most useful for a beamer presentation that I am currently writing. Ideally the text ...
2
votes
1answer
173 views

Cross reference line number within program listing in lyx

I'm trying to cross reference program code line numbers within a program listing using lyx. From what I can tell, both labels and ERT are disabled within the program listing, but I'm not sure why. I ...
6
votes
1answer
101 views

Listings: text highlighting based on prefix

How can I apply different styles to keywords depending on their prefix? Here is some sample code: (-2,0,0) (2,1,1) op-registerbox !box1 ;box1 /Blue op-setproperties I'd like to typeset words ...
3
votes
1answer
688 views

lstlisting: Syntax highlighting for C++ like in Editor?

i want to insert some C++ code into my thesis and i tried tons of options to make the code look like in my editor. Here is what i have so far: \usepackage{listings} \usepackage{color} ...
0
votes
0answers
17 views

Listings: Extract filename (not path to file) [duplicate]

I'd like to get just the filename of a text file I'm including using the listings package. I use \lstname; however, it gives me the full (relative) path to the file. I just want to the filename ...
3
votes
1answer
179 views

latexdiff and lstlisting

I was wondering if it is possible to have latexdiff ignore all lstlistings from my documents when finding diffs. Most of my listings contain special characters. That works rather nicely within an ...
10
votes
1answer
229 views

How to force lstlisting caption names and numbers to always appear, even when captions are empty?

I noticed lstlisting environment seems to supress the caption name and number when no caption is specified. See the code below: \documentclass{article} \usepackage{listings} \lstset{language=C} ...
3
votes
0answers
148 views

Avoid page break after last line in lstlisting [duplicate]

I have a listing as follows: \lstdefinestyle{yamlCode} { numbers=left, language=Yaml, backgroundcolor={\color{lightgray!40}}, breaklines=true, frame=single, columns=fixed } ...
4
votes
1answer
163 views

Combining newenvironment, quote and lstlisting (mcode)

I am trying to combine various packages and commands with PdfLaTeX (through MikTex on MS Windows), including newenvironment, quote, mcode and lstlisting, to create an environment to define multiple ...
8
votes
1answer
90 views

Strange interaction between listings and sections

Consider this example: \documentclass[a4paper]{article} \usepackage{listings} \lstnewenvironment{shell}{}{} %\usepackage{verbatim} %\let\shell\verbatim %\let\endshell\endverbatim \begin{document} ...
6
votes
2answers
155 views

Uniform Unicode for text, math and listings?

What should I put in the preamble (preferably packages) for this to work as expected with its unicode characters? \documentclass{article} \usepackage{listings} \begin{document} $α$ α ...
4
votes
1answer
172 views

Using listings inside mdframed causes unknown compilation error

I have a problem with the listings and the mdframed package together. The following code compiles with errors, but the only info I managed to get about it is that it was fatal. ...
6
votes
2answers
116 views

Widow Orphan lstlisting

I have a listing of 6 lines. The listing box does not seem to fit on one page (it is on the bottom of the page) so the rest of the box is printed on the next page. There is nothing actually in the box ...
0
votes
1answer
158 views

Listing numbers go outside margin [duplicate]

I'm trying to add sample code to my document. It seems that the listing is left aligned with the margin, and the numbers go outside it. How should I align the number, instead of the code? Here is my ...
7
votes
1answer
82 views

Listings package - the symbol \ isn't colored while rest of the macro is

I am using the package listings for code printing, but I have come across a problem. I usually write down a lstlisting environment like this (this is for the LaTeX language): ...
4
votes
1answer
183 views

Captioning an mdframed box without making unbreakable

I would like to a have a caption below my mdframed box (outside the border if possible) which sometimes span across multiple pages. I managed to create a caption several ways but the pagebreaks are ...
5
votes
1answer
114 views

\lstMakeShortInline with @ delimiter

I'm including a fair amount of inline C++ code in a beamer presentation I'm making, and I want to be able to use the short syntax for \lstinline. My code displays fine if I use, for example, the ! ...
2
votes
1answer
86 views

Conditional execution based on style existence (listings)

Is there a way in LaTeX (or e-TeX) to check if a style is defined using the listings package (inside a \lstnewenvironment definition)? I mean something like this: \lstdefinestyle{tmpdefaultstyle}{} ...
2
votes
1answer
130 views

Adding caption and counter to source code environment

I have a source code listing with minted environment. How can I make a counter/caption to be shown as follows. I also need to make \tableofsourcecode to enlist all the source code references. The ...