{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

5
votes
1answer
82 views

How to display code formatted with lstlisting in a bussproofs proof tree?

I wish to include Java-code formatted with lstlisting as a conclusion in a bussproofs proof tree. The code has to be in boxes so two peaces of code can be displayed next to each other in the same ...
5
votes
1answer
90 views

Incorrect tree view of document structure with Winedt, VerbatimPlus and listings package

I´m having some trouble working with Winedt 8 and 9 and VerbatimPlus add-on. Here is my MWE. File "main.tex" \documentclass[a4paper]{article} \usepackage[utf8]{inputenc} % Codificação da entrada ...
5
votes
1answer
68 views

Multiple literates in a listings style definition [duplicate]

I have a style defined for a language which has lot a lot of literate replacements. In the individual listings that use this style I would like to introduce more listing-specific literate ...
5
votes
1answer
101 views

Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX? ...
5
votes
2answers
178 views

Beamer overlay and listing conundrum

When I try to overlay the lstlisting C code with escape character (so that I can insert a \colorbox), I get the following error: ! Missing number, treated as zero. <to be read again> ...
5
votes
2answers
2k views

Missing \endgroup inserted error in a table

I am getting 'Missing \endgroup inserted morekeywords={class,run}]' on line 16 while running the tex. I am using TexStudio. How can I solve that problem? \documentclass{article} ...
5
votes
1answer
612 views

How to copy/paste from lstlistings? [duplicate]

I'm trying to write code in a LaTeX document that can be copy/pasted from an outputted pdf using Adobe Reader and that also word wraps, rather than breach the right margin. I've found that in ...
5
votes
1answer
162 views

Emphasizing some parts of string in lstlisting

I need to stress out some parts of string in lstlisting. I tried with \emph{}, but I got the verbatim result. Is there any way to that? \begin{lstlisting}[frame=single] Array1: 78 54 31 54 92 86 23 ...
5
votes
1answer
262 views

Floating text around listing

I can't manage to let my text float around an listing. Assuming I have a text paragraph and I want the listing to be at the top right place with a certain width, and to be floated by the text. ...
5
votes
1answer
164 views

define moretexcs (listings)

I want to define moretexcs lists outside of a lstdefinestyle macro because I want to load these definitions from a separate tex file. However inside lstset moretexcs is ignored: ...
5
votes
1answer
91 views

Prevent Listings from breaking frames

Is there any way to prevent the listings package from leaving unsightly gaps in the frame when using breaklines=true. I'm just \lstinputlisting some code, placing it in a shadowbox frame and letting ...
5
votes
1answer
102 views

vertical extra space below lstlisting environment inside a list environment

i want several code listings to be embedded in an item of a custom list environment. To achieve this i employ the lstlisting environment of the listings package. Unfortunately extra vertical space is ...
5
votes
1answer
1k views

How can I use multiple declarations (\textbf, \emph) in listings' emphstyle?

How do I provide multiple emphstyles with the listings package? \begin{lstlisting}[emph={if,for},emphstyle={\textbf\emph}] if something end if \end{lstlisting} Both styles above (\emph and \textbf} ...
5
votes
1answer
374 views

Listing index uses wrong dashes

When generating an index of all my Listings, the library seems to use the wrong dashes to connect words: Expected Unported-2.0-Graphic Actual Unported—2.0—Graphic In the title of the listings, ...
5
votes
2answers
689 views

How can I set columns=fixed for lstinline globally?

I typeset my listings using listings with a proportional font. This looks good for the lstlisting environment. However, when I use \lstinline|code|, the spacing reverts to variable-width. I would like ...
5
votes
1answer
904 views

UTF-8 (BMP character set) support in listings.

I'm submitting a paper to a journal using LaTeX, and I need to be able to write Unicode symbols into listings. So far, I've been able to get by with the moreverb package. It's listing environment is ...
4
votes
1answer
75 views

Print blue brackets in one language and black in another

In addition to that question i wonder if it is possible to have that settings for one language and default settings for another ? How to highlight operators and brackets in a C listing? ...
4
votes
1answer
62 views

How can I mimic the output of syntax macros (\marg, \oarg, etc.) without using the ltxdoc class?

I have come to realize that the pleasant style (argument in italics, enclosed by angle brackets) of macro descriptions in numerous package documentations is actually produced by a number of special ...
4
votes
1answer
72 views

Distorted caption in listings

The following code produces strange results. Everything looks fine, if I don't include the subfig package or don't use the xleftmargin parameter. It also works if I use captionpos=t. Is there a ...
4
votes
1answer
107 views

Listings and Babel (with some languages) are breaking hyphenation

In the following document \documentclass{article} %\usepackage[german]{babel} % also try english, ngerman and dutch \usepackage{listings} \begin{document} \thispagestyle{empty} \begin{minipage}{1em} ...
4
votes
2answers
236 views

How to make a minted code listing centered on a page?

So, I am writing a report with Prolog code listings in it. I have been using lstlisting to make my listings and I made my code centered on the page, such as this: \renewcommand{\figurename}{Listing} ...
4
votes
1answer
323 views

Consolas: Straight Quotes

I am using the listings-Package to display code. As I am using The Consolas Font as the Monotype-Default I expected straight quotes which isn't the case (check my MWE) ...
4
votes
1answer
256 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. ...
4
votes
1answer
482 views

Creating a table around a java script code highlighted using minted

I would like to create a block around javascript code in latex. I use minted package for format highlighting. Here is my example code: \documentclass[]{article} \usepackage{minted} %opening ...
4
votes
1answer
83 views

test if a listings or glossaries style is valid

I want to test in my template if a call of \lstinputlisting[style=mystyle,... or \printglossary[style=mystyle,... is valid or will fail because of an unkown style. However I could no find out ...
4
votes
1answer
208 views

How to I emphazise all words beginning with ` in an lstlisting

I use a preprocesser to process some code before my verilog compiler. All preprocesser words start with the ` character Example: `pp_if unfortunately its possible to define your own preprocessor ...
4
votes
1answer
229 views

Headers and footers for listing environment?

What I need to be able to do is apply a header and footer when I use the listings environment. I have a few requirements: The header and footer should be outside the listing itself, i.e. they are ...
4
votes
1answer
2k views

Color \ , [], {} and / in listings environment

I tried to color a source code listing as follows. I would like the \ to be the same color as the word that follows for example: \documentclass in red including "\" \usepackage in blue including "\" ...
4
votes
1answer
324 views

Add word Listing in front of number in list of listings

I have to add the word Listing or Lst. in front of the number of a listings in the list-of-listings. I use the listings package. I know how to achieve this with tables: ...
4
votes
1answer
2k views

How to increase the padding in the code snippet box when using `listings`?

So I am writing a book on Awk programming language, and I have enabled a single frame via \lstset{frame=single}. However, I would like the code within the snippet box to be further away from the frame ...
4
votes
1answer
759 views

\fbox inside listings

I am trying to highlight a specific line inside a listing with listinline. The code I am currently using looks like this: \begin{lstlisting}[escapechar=!] class A { void m() { B b = ... ...
4
votes
1answer
933 views

lstlistoflistings font

I'd like to change my list of listings to match my list of figures, which I have changed using tocloft: \renewcommand{\cftfigfont}{\sffamily\mdseries\upshape} Is there a way to do the same with my ...
3
votes
1answer
51 views

Getting WinEdt to ignore lstlisting

WinEdt 9.0 gives me incorrect TOC in its side panel when I use listings package to illustrate a piece of LaTeX code: How can I get WinEdt to ignore \begin{lstlisting} ...\end{lstlisting} (and ...
3
votes
1answer
217 views

How can I replicate the syntax-highlighting style of the Kate editor?

I am trying to add a java and c++ code in a LaTeX document. I am using listings package and I will define a different style for each language using \lstdefinestyle{myStyle}{<options>}. What I am ...
3
votes
1answer
131 views

How to define colors in style file (lstlang0.sty)

Per the listings package documentation, I have a file lstlang0.sty in the same directory as my .tex file (well, .lyx file) which defines a new language. I used to have this language definition in my ...
3
votes
1answer
80 views

Line breaks inside inline code break syntax highlighting. Any workaround?

I want to have both code snippets ABC and ABC_DEF in red (in both cases only ABC is red). If I remove the literate line it works but I also want to have automatic line breaks at underlines. How can I ...
3
votes
2answers
200 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} ...
3
votes
1answer
314 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 ...
3
votes
2answers
698 views

Numbering of listings

I would like to numerate listings according to sections. If the listing is in subsection then it should have subsection numbers. This example is very good and I'm using it for some other numbering, ...
3
votes
2answers
112 views

Title of listing is missing

I am using the listings package to mark-up C and Assembler code. Unfortunately the title of the listing is missing (the same with the caption=... command). In the document section I using my clisting ...
3
votes
1answer
313 views

\lstinputlisting does not respect the \lstset 'float' option

How can I force \lstinputlisting[...]{filename} to obey all parameters set by \lstset? (Note the float option given to the TeX example, but not to the LaTeX example.) ...
3
votes
1answer
115 views

texcl and range prefixes in listings with shorter comments

I'm trying to use the line range markers from the listings package to include sections of code. I'd previously been using actual line numbers, but based on the answer to this question, I've been able ...
3
votes
1answer
467 views

Markup Haskell sources in complex structured document with `lhs2TeX`

Simple task Suppose there is a example.tex file with Haskell listings: \documentclass{article} \usepackage{fancyvrb} \DefineVerbatimEnvironment{code}{Verbatim}{fontsize=\small} \begin{document} ...
3
votes
1answer
293 views

listings range end markers in comments with texcl

I'm trying to using the listings package to generate nice listings of some Lisp-style code (where line comments begin with a ;). I'd like to keep the code compilable, and so put the range markers ...
3
votes
1answer
938 views

LaTeX - Using commands inside inline code

I want to be able to have inline code (printed in typewriter or something) where I can also use LaTeX commands like \myinlinecode{here comes a backslash: <\textbackslash>}. So it should be ...
3
votes
1answer
236 views

Use pxfonts in listings only

I really like the pxfont package for displaying code in listings. I would usually just do this to load pxfont for the entire document; \usepackage{pxfonts}. However, this time I am required to use a ...
3
votes
1answer
622 views

How to use angle brackets for a keyword in \listings?

I've got a code of a HTML website that I want to show in my LaTeX document. The problem is, that the HTML code has a tag called <canvas> and the JavaScript code inside the HTML document has a ...
3
votes
1answer
842 views

LaTeX source code listing with less space between characters [duplicate]

I want to write shell Code in my LaTeX document. I'm using the listings package, with a code sample adapted from Tormod Fjeldskår: \documentclass{report} \usepackage{color} \usepackage{xcolor} ...
3
votes
1answer
309 views

regular expression in listings

I'm looking for a possibility to find a way to colorize data. If a text starts in a line with XYZ from that point until the next blank line the text should be set in a defined colour. With the comment ...
3
votes
1answer
129 views

Auto include specific part of source files

I'm creating a lot of code to our small projects (in computer science), and finding myself copy/pasting my comments into the document. Would it be possible to make a reference point in the code file ...