{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

2
votes
1answer
30 views

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about ...
9
votes
2answers
161 views

How to get listings that both feature line breaking of long identifiers and keywords highlighting?

I'm currently writing a book chapter in bioinformatics, and I would like to provide my readers some useful command lines to invoke recent software. To that purpose, I'm using the listings package to ...
2
votes
0answers
55 views

Problem with Listings package concerning line breaking and wrong alignment [duplicate]

Hello I have the following code: \documentclass[12pt]{article} \usepackage[top=0.3in, bottom=1.5in, left=0.8in, right=0.8in]{geometry} \usepackage[utf8]{inputenc} \usepackage{setspace} ...
7
votes
1answer
96 views

How can I color braces in showexpl?

I want to use showexpl and have the LaTeX code printed with colored braces. I can do this within a lstlisting environment by adding a literate option like in the example below, but not within a ...
3
votes
1answer
61 views

How can I automatically include all source code files located in a given directory?

Is there a way to include all files in a directory and all sub directories in a report as a code appendix using the listings package? I know I can include each individual file using the listings ...
17
votes
3answers
3k views

Listings, Literate Programming, and Beautiful Typography

Now that I'm procrastinating with tweaking LaTeX, instead of finishing my Ph.D. thesis, I'm wondering what's the most beautiful way to typeset source code (C#, C++, LISP, XML, BNF) in LaTeX. ...
21
votes
2answers
1k views

Ensure verbatim code block is copy/paste-able

After rendering a document containing this code block \begin{verbatim} if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist. if [ ! -f README.md ]; ...
7
votes
2answers
177 views

tcolorbox: option for “listing outside (but ABOVE) text”

The tcblisting environment provided by the tcolorbox package allows one to display LaTeX codes in the lower part of a tcbox and the output in the upper part of the same tcbox, using the text and ...
7
votes
4answers
4k views

language option supported in listings

I am afraid that listing doesn't support javascript. \begin{lstlisting}[language=javascript] ... \end{lstlisting} What am I doing wrong?
10
votes
3answers
839 views

Avoiding “minus sign” dash in listings commentstyle

Is there a general way to get listings package to typeset a hyphen as a minus character in the rest of the code (the default behavior), but typeset a hyphen as a true hyphen if it occurs in comments ...
2
votes
1answer
56 views

How can I highlight a freestanding regexp in string style?

I'm using listings to format a piece of JavaScript code, and I met a problem for the following code: ... regex = /abc/; ... ratio = 1.0/2.0; ... I want the regex is highlighted as a string, but if ...
6
votes
2answers
136 views

How can you highlight a C compiler directive spanning multiple lines?

In my \lstset{...} I have morecomment=[l][{\color[rgb]{0.1, 0.2, 0.8}}]{\#}, which I've seen used to give preprocessor commands colour. This works just fine but I'd like to get multi-line macros to be ...
1
vote
1answer
41 views

Optional caption in listings (for listoflistings)

I have some cites in my captions. But I do not want to appear them in the table of figures or listings. With figures I managed to display an different caption like this: \begin{figure} \centering ...
19
votes
2answers
8k views

Extend a language with additional keywords?

I'm using listings and I want to extend a language with additional keywords for highlightning. I know there is an option morekeywords available, but that only works for a particular lstset declaration ...
16
votes
1answer
311 views

How to remove the leading unnecessary white spaces when using linerange option?

To be honest, I am looking for people who already read the listings documentation completely. If those people also cannot solve it, then the documentation does not mention anything about it. Sorry for ...
17
votes
2answers
252 views

How can I redefine my macro to accept a charcode instead of a character?

I recently posted this answer to How to highlight all words of the form [0-9][A-Za-z0-9]* immediately following an equal sign?. It works, but it suffers from (a lot) of code duplication. What I have ...
4
votes
3answers
144 views

How to get listing to print only the header of a Matlab file?

How to extract the first line of a simple matlab file and the following lines just after that begin with the character % ? The number of lines to extract is unknown. Then I want to use listingsutf8 to ...
4
votes
1answer
31 views

lstlisting directly after section start removes margin before next section

If I place an lstlisting directly after the start of a (sub)section, the margin before the following (sub)section (title) disappears. Here is a an example document showing the issue: ...
4
votes
1answer
117 views

tikzmark, listings and beamer's onlyenv

I found this limitation in the current tikzmark solution for highlighting lines of listings code in beamer. When I put the whole lot in an onlyenv environment, it seems the marks are not set, or ...
6
votes
1answer
64 views

Problem with listings when using line numbers, `name`, and `beamer` overlays

It's is well known that to ensure that a certain <counter> is automatically reset on subsequent slides of a same frame one has to use either \resetcounteronoverlays{<counter>} (for LaTeX ...
4
votes
2answers
67 views

Indent content of verbatim / lstlisting environment relative to containing environment

I want the content of \verbatim to be indented relative to the actual indent of \verbatim, not the exact number of spaces. For example, I like to indent at sections to make the LaTeX source more ...
2
votes
2answers
419 views

XML listing shows incorrect quotation marks

I'm using \lstinputlisting from listings package to insert an xml file as a listing in my latex file. In the XML file the quotation marks are double quotes as normal when I view my PDF they appear as ...
2
votes
0answers
43 views

Unicode and listings - still no luck

Although there are already some discussions on this issue, I can't get any of the proposed solutions to work for me. Take this document and compile it with xelatex: ...
10
votes
2answers
530 views

How to highlight all words of the form [0-9][A-Za-z0-9]* immediately following an equal sign?

I am using the Latex Listings package to include code in a document. I need to implemented syntax highlighting similar to what you see in a standard IDE. I've been able to assign colors to comments, ...
4
votes
1answer
88 views

How can I preclude copying & pasting of listings?

When I include code snippets in my documents, my lazier readers, i.e. students :), are often tempted to just copy and paste those snippets instead of typing them themselves. However, there are risks ...
6
votes
2answers
183 views

Improving the POV definition in the listings package

I'm attempting to create a language definition in the listings package that mimics exactly the syntax highlighting in POV-Ray 3.6 for Windows (http://www.povray.org/download/). Here is a screenshot ...
11
votes
1answer
748 views

Automatic background coloring in listings using tikzmark

I am authoring Beamer presentations that feature numerous code listings, and I am required to highlight portions of code with semi-transparent balloons. Yet I've come up with a solution that uses a ...
1
vote
1answer
65 views

How can I nicely typeset this MySql query with the listings package?

I am trying to show output of MySql explain in my LaTeX document. I am using listings package to make listings. Sample LaTeX code: \begin{lstlisting}[language=SQL,caption={SQL query explained}] ...
2
votes
1answer
96 views

Lstlisting in beamer presentation

I would like to insert a source code listing into my beamer presentation. I learnt that we cannot use lstlisting directly in the frame environment, so I am using the following trick: ...
4
votes
1answer
94 views

lstlistings works strangely

I have some Java source code and want to display it in LaTex: \lstset{language=Java} \begin{lstlisting} IntentFileter intentfilter = new IntentFilter(); ...
3
votes
2answers
927 views

Listings package: how to suppress highlighting/emphasis on identifiers containing keywords?

I'm using the x86masm dialect of Assembler and register names are emphasized even when they occur inside of a label or a hexadecimal number. For example, dh is register, but 0dh is a number, yet the ...
4
votes
1answer
41 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} ...
14
votes
2answers
1k views

Coloring digits with the listings package

I'm trying to typeset some python code, and I would like integer literals to be highlighted. I've come up, after about two hours of fighting with the documentation and various other questions here and ...
8
votes
1answer
136 views

How to apply the star (*) to only a few of the literates in listings environment?

I have a problem with the definition of literate: \lstset{ numbers=left, numberstyle=\footnotesize, stepnumber=1, numbersep=12pt, frame=none, framesep=7pt, breaklines=true, ...
4
votes
2answers
1k views

How to highlight operators and brackets in a C listing?

How can I apply a certain style to C (or, well, any other programming language) operators? So that when I write \begin{lstlistings}[language=C++] int i = 0; if(i > 1) { // do ...
5
votes
1answer
48 views

How do I maintain structure in structured output?

I am trying to ensure output from a Linux command - which looks like: Into a LaTeX document with the same column structure with the output headers lined up with the output sections on the next ...
9
votes
2answers
1k views

How can I remove “Listing #: ” from listings caption?

I am working on a C++ reference manual for myself and I want good-looking listings. The Stack Overflow question entitled LaTeX source code listing like in professional books was very helpful but, for ...
2
votes
1answer
32 views

Splitting a code listing inside a longtable

Is there a way to have code listings split across multiple pages when included inside a longtable? For example, the following code: \documentclass{article} \usepackage{listings} ...
3
votes
1answer
98 views

Coloring or Bolding multiple lines in fancyvrb integration with listings

I would like to apply latex commands on a bunch of lines in a Verbatim environment with listings, especially make bold or color a block of code. I am able to do that for a single line, but not for ...
0
votes
0answers
50 views

Don't break lines at certain characters in lstlisting

Is it possible to configure lstlisting such that it doesn't break lines at certain characters? In this example, a line break is inserted after the opening parenthesis: public void someMethod( ...
8
votes
2answers
275 views

How can I highlight an interactive GAP session just like so?

Suppose I want to typeset a screen session in some programming language (GAP in my case, but it could be Python, BASH, or something else with an interactive read prompt just as well). So on my screen, ...
5
votes
2answers
82 views

Best way to deal with overfull inline listings

I am typesetting inline code listings using the listings package. Since I'm using C# syntax, oftentimes listings contain long words (type names/variable names). Since words in listings won't be ...
2
votes
1answer
47 views

inline code listing runs into right margin

I am trying to typeset an inline C# code listing using the listings package. However, the chunk of inline code spans a few lines, so listings has to insert a coupe of line breaks into my code. So far, ...
1
vote
0answers
24 views

Line breaks in inline listing + correct emphasiation?

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
1answer
60 views

Escape comment syntax in strings with listings

Consider the following: \documentclass{standalone} \usepackage{listings} \lstset{ language=Python, morecomment=[s]{<<}{>>}, } \begin{document} \begin{lstlisting} def expand(): ...
1
vote
0answers
148 views

Wrap text to one line under cvitem [closed]

I am using the moderncv package. When listing items using the \cvitem{}{}, it seems to put these over two lines what I actually want is for everything to be on one line. Here is my code: ...
5
votes
2answers
116 views

Manually break lines like auto-breaking in lstlisting

I would like to decide where the long line should break, but with actions pre-/postbreak and without advancing in line numbering. I've tried that one: \documentclass{article} \usepackage{color, ...
1
vote
1answer
19 views

How can I have a hyphenated XML tag in a listing?

Consider the following valid XML according to http://stackoverflow.com/a/1478623/1443496? \documentclass{article} \usepackage{listings} \lstset{ language=xml, morekeywords=some-tag, } ...
5
votes
2answers
418 views

How to highlight all identifiers starting by '@'?

I would like to highlight any expression made of letters and that starts with one @. The use of moredelim=*[s][\color{blue}]{@}{\ } works only in case like @name is followed by one space. The ...
7
votes
1answer
3k views

How can I start the line numbering of my listing by an arbitrary number?

This is what I want: 15 <servlet> 16 <servlet-name>udpListener</servlet-name> 17 <servlet-class>oli.servlet.UdpServlet</servlet-class> 18 <!-- UDP Port fuer ...