{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
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
93 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
364 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
672 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
894 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
60 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
96 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
212 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
309 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
247 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
464 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
203 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
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
321 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
746 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
931 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
48 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
169 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
2answers
306 views

Read integers from external data file to document programming code in LaTeX

I am attempting to document my MATLAB programming code in LaTeX. For this, I use the mcode package, which defines the MATLAB lstlisting environment. With the commands ...
3
votes
1answer
111 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
2answers
194 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
299 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
652 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
110 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
300 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
446 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
277 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
912 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
224 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
594 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
770 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
304 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 ...
3
votes
1answer
333 views

linerange reference in lstinputlisting

I have a listing that refers to my c code; I would like to reference the code using commented section in the code, as seen in the code example bellow. I have created a list style which does this, but ...
3
votes
1answer
279 views

Hide listing from listoflistings [duplicate]

Possible Duplicate: remove unwanted contents from list of listings How can I hide a listing from the listoflistings, similar to using \section*{Title} to hide a section from the table of ...
3
votes
1answer
798 views

Background color in inline code listings with linebreak

I want to highlight code inline with a gray background. Preferably with listings. This question is related to Colored background in inline listings. But as my MWE shows it doesn't work with line ...
3
votes
1answer
221 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 ...
3
votes
1answer
748 views

Latex listings R: need mono-spaced font with bold keywords and correct caret (^)

I am using the listings package to display R code. I would like a monospaced font, bold keywords, and I would like code that works when the user cuts and pastes from the pdf file into rstudio. The ...
3
votes
1answer
972 views

Problem with alignment in listings

I have a follow up question to this post I am using listings in beamer. The content in listings is being pushed further left than the other contents on my slides. I am using the code below to correct ...
3
votes
2answers
656 views

How listing and verbatim do to escape special character?

I use one macro to display text using texttt style. For the moment this macro is very basic. For example, if I want to use the character _, its catcode must be changed. Is there a clever way to ...
3
votes
1answer
512 views

Visual separation when using linerange in listings

I have read through the listings documentation and couldn't find an answer to the following question: How do I insert some sort of visual feedback in a listings listing when using the linerange ...
3
votes
1answer
2k views

How to highlight own keywords in HTML lstlistings?

I would like to highlight some words in a lstlisting. The language is HTML. However, \emph seems not to be working with HTML. Any suggestions how I could work around this problem? Right now I have: ...
3
votes
2answers
2k views

How to use a comma in lstlisting keywords?

I am creating a language for the doxygen tool. I need to create a set of new keywords. When I try to use the comma in one of them, it does not highlighting. I protect comma with a backslash, but it ...
3
votes
1answer
864 views

Custom numbering of listings

I have a number of listings in my document, numbered 1, 2, 3 and so on. I need a table with three listings (say, three different variants of the same algorithm), that will be numbered as 2a, 2b, 2c. ...