{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

3
votes
1answer
580 views

Problems customizing listings captions

I'm trying to "decorate" source code with listings, but I'm getting some warnings and bad boxes when I compile my document. However the document compiles and looks like I want. I noticed the warning ...
4
votes
1answer
213 views

custom float (newfloat): entry in listoflistings is not indented

I'd like to use a custom floating environment for lstlistings so as to be able to draw frames around the listings using mdframed. My float uses the same counter as lstlisting, and also appears in the ...
7
votes
3answers
1k views

Hang caption in lstlisting

If I use the following command \usepackage[skip=20pt,hang]{caption} when a caption is very long it hangs in figures and tables, however, if the caption is of a lstlisting environment it doesn't. ...
5
votes
1answer
375 views

Mathematical symbols as keywords in listing

Is it possible to use mathematical symbols as keywords in listing? I'm using listings package to typeset Mathematica code and I have used emph parameter of lstset to use blue bold font for some of my ...
3
votes
1answer
2k views

listings doesn't print my keywords bold in lstlisting

I've got the following problem: I want to print a listing with the listings package and lstlisting: \documentclass{scrreprt} \usepackage{listings} \begin{document} \begin{lstlisting}[language=...
4
votes
1answer
706 views

lstlistings - How to highlight single quotes og keywords

I want to highlight some keywords in a listing. One keyword has an apostrophe. I searched and read already quite some time and found a couple of postings that textcomp could be very helpful for quotes....
5
votes
1answer
369 views

Problem with listings package using stix fonts

Consider the following code: \documentclass{article} \usepackage{stix} \usepackage{listings,xcolor} \lstdefinelanguage{test}{sensitive=true, morekeywords={TEST}, morecomment=[l]{--}} \...
6
votes
1answer
118 views

Conditionals in lstlistings

I am trying to put in some lines of code using the lstlistings-package but the code differs on conditionals. How can I only change some lines depending on the conditional? Assume I have the If: \...
4
votes
1answer
2k views

Listing code going out of page [closed]

I'm using listings to display my codes. I'm getting some issues. First, the codes when it is too long, it is going out of page as shown here. Secondly, the codes are in SPARQL. It is recognising some ...
7
votes
1answer
832 views

How can I make \lstinline function normally inside math mode?

\lstinline of the listings package doesn't work in math mode. When I try to use it, I get the error that \ttfamily is invalid in math mode. However, when reasoning about program semantics, it is ...
1
vote
1answer
111 views

Extra space in front of keywords in listings

Does anyone know why I'm getting extra spaces in front of the keywords in my code listings? I've attached a picture of one of my listings that I've compile with showspaces=true and showtabs=true. You ...
10
votes
1answer
464 views

How to add a colon after listing label?

I want to add a colon ":" after each lstlistingname in the lstlistoflistings. At the moment the it shows me "Code 1 StatusCalculator Initialize....." But I want a colon after lstlistingname "Code 1: ...
6
votes
1answer
2k views

lstlistoflistings isn't showing the lstlistingname

I've actually a problem with my document. I redefined the listing for my ruby code: \usepackage{listings} \renewcommand\lstlistingname{Quellcode} \lstloadlanguages{Ruby} \lstset{% basicstyle=\small\...
5
votes
0answers
444 views

Collapse/expand in document [closed]

Perhaps this is a dumb question. I write a small pdf-book on coding and use there many examples using listings package. But the amount of code expands text too much, for every 5 lines of text there ...
12
votes
2answers
20k views

MikTeX fails to download the listings package

I'd like to use the listings page to include code snippets in my master thesis. I used the \usepackage{listings} command but it failed with the following error message: downloading http://piotrkosoft....
1
vote
0answers
384 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: \cvitem{...
11
votes
1answer
5k views

listings package: no numbering in case the code has only one line

I have a custom style in lstlisting with numbers on the left and the number step is set every line. I would want to know how the listings could appear without number in case the listing has only one ...
4
votes
2answers
1k views

Various \textcolor within lstlisting?

How can you set various words in your lstlisting to various text colors? For instance, I want the word "fail" to appear in red and the word "pass" in green. I have the feeling there should be some ...
6
votes
2answers
642 views

`listings` and `sidecap` - Side captions for listings

I am using the package sidecap for captions which appear left or right of a picture/table, like so: \documentclass[a4paper,twoside,11pt,openright]{scrbook} \usepackage{graphicx} \...
10
votes
2answers
382 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 ...
9
votes
1answer
246 views

Hyperref adds vertical space to listings

When I input a listing with \lstinputlisting from the listings package, I get an additional vertical space, when I use this in combination with the hyperref package. As the picture shows, a certain ...
5
votes
2answers
8k views

Syntax highlighting in listings for C# that it looks like in Visual Studio

Community, I want to get my C# listings syntax highlighted like in Visual Studio but I did not get it so far. Here's an image of the syntax highlighting of Visual Studio: Here is the code I have: ...
8
votes
1answer
885 views

defining a centered shadowboxed listings environment

I'm trying to define a environment for code listings wrapped in a shadowbox and centered in the line. Using this code, I can generate the kind of output that I want: \documentclass[twocolumn]{...
16
votes
1answer
370 views

Why are lstlang*.sty files from listings package loaded 3 times?

During compilation of the following MCE: \documentclass{article} \usepackage{listings} \lstset{language=TeX} \begin{document} \begin{lstlisting} Foo \end{lstlisting} \end{document} the lstlang*.sty ...
5
votes
1answer
275 views

“Listings” environment for GAP

I was searching the web for a possible environment where I can put my GAP (Groups, Algorithms, Programming) codes. The most promising I saw was the "listings" package. But to my disappointment, this ...
4
votes
1answer
452 views

Replace lstlisting with verbatim depending on a boolean

I use latex2rtf to convert latex documents to .rtf and thence to MS-word (see this thread). To do this, I set up a custom class and limit which packages are used as latex2rtf only accepts a limited ...
3
votes
0answers
108 views

Highlight LaTeX code and presenting results as in a manual [duplicate]

I would like to write a short guidelines of LaTeX for my students. In the spirit of some LaTeX manuals, I'd like to present the code and the result as follows, This example illustrate more or less ...
6
votes
1answer
745 views

Including LaTeX documentation as comments in source code

I am working on a large C# project (hundreds of source files). I am trying to add documentation on various user inputs and options. For maintainability I would ideally like to be able to write the ...
9
votes
1answer
316 views

Problems at page boundaries trying to highlight `\lstinline`

I was trying the code given in Colored background in inline listings, which is actually the same than in How to redefine \lstinline to automatically highlight or draw frames around all inline code ...
0
votes
1answer
201 views

Generating a list of Source Code Listings of a document [duplicate]

how I can generate a list of source code Listings like a list of Figures ?? here is an exemple of a code source Listings: \lstset{ numbers=left, stepnumber=1, numbersep=5pt, numberstyle=\small\color{...
2
votes
1answer
348 views

caption for listings in margin

The floatrow package enables one to put in the margin captions for figures and tables, but it seems there is missing the possibility of doing the same for the lstlisting environment from listings ...
6
votes
3answers
318 views

Referring to a whole line of code instead of a line number

This code fits quite nicely my needs: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{lipsum} \usepackage{hyperref} \usepackage{lstlinebgrd} \definecolor{myComment}{rgb}...
2
votes
1answer
90 views

Does the trick that prevents to copy the line numbers work anymore?

After updating my MiKTeX distro I have noticed that this trick (the community wiki one) does not work anymore. I have tried to reinstall MiKTeX from scratch but the problem persists. Can someone check ...
1
vote
1answer
203 views

How to set identifier “Listing 1” in listing in bold

I use figures and listings in a document. By default, the identifier "Figure 1" is set in bold, while "Listing 1" is normal. For consistent looks I would like to have either everythin bold or normal. ...
5
votes
1answer
586 views

The % symbol overlaps inside a listing with MatLab code

I'm using the listings package to insert MatLab routines that I've created for some papers I need to write. Everything works awesome, except the symbol % (comment in MatLab) which overlaps with the ...
5
votes
1answer
245 views

compilation error in creation of new command

I'm trying to manipulate a bit an environment that I've found in internet, in GUIT forum. This is the minimal example \documentclass[a4paper,10pt,twoside,openright,titlepage,fleqn,headinclude,...
7
votes
2answers
746 views

How to insert a keyword with accents (extendedchars) in listings

This is what I would like to do: morekeywords={SENÃO, ENTÃO, FAÇA, ATÉ, ENQUANTO, PARA, SE, DECLARA, DECLARE, E, OU, FIM_ENQUANTO, FIM_PARA} I'm defining a new language, and I would like to use ...
5
votes
1answer
342 views

lstlistings in defined Tikz box

I have created a box using \newcommand, based on TikZ named "mybox". The equation easily insertable in it. But I want to insert a \lstlisting environment in it. But it doesn't work. How can I do it? ...
21
votes
1answer
14k views

Reference to a listing returns wrong number

I'm using the following code to create a listing with sourcecode: \begin{lstlisting}[caption={caption_text}\label{lst:a_label},language=Java] // Code... \end{lstlisting} Unfortunately, a \ref{lst:...
4
votes
1answer
750 views

How to add lstlisting to Algorithms List

I have written a document where I use pseudo code to describe some general algorithms (with \usepackage{algpseudocode} ) which can be viewed at the begining after toc as „List of Algorithms”. I also ...
0
votes
1answer
699 views

Only Select Code without Line Numbers [duplicate]

I'm writing a LaTeX document and want to include several listings for source code examples. Is there a way to disable the selection of line-numbers when selecting the source code? My prof just wants ...
1
vote
1answer
491 views

Use Listing in newenvironment

I am trying to do a new environment or command (i tried both) where i can put in the name, description and code of a Method in c++ and it gives me a new section with the MethodName, the code listed ...
5
votes
1answer
372 views

Two columns for grammar environment

My grammar is long and thin. I'd like to space it out horizontally, as two columns. \newenvironment{BNF} {\captionsetup{type=lstlisting}} {} \begin{BNF} \caption{My Grammar} \label{grammar:my-...
0
votes
1answer
812 views

Issues when including a tex file [closed]

I have this without any issues if I use it alone. However if I call it with input or include I get this Why?
0
votes
1answer
446 views

Long codes using listing or mcode which do not break into 2 pages

I'm using the mcode package for including my codes into my documents, but the problem is that when my codes are too long, and they need more than one page the program tries to keep them in one page, ...
1
vote
1answer
3k views

Several errors concerning lstlisting

In my Bachelor Thesis I'm using highlighted code using lstlisting, which comes with the listingspackage. Unfortunately I'm getting some errors and I cannot figure out why they appear. Especially ...
1
vote
0answers
30 views

How to use \lstinline inside figure environment's caption argument [duplicate]

Here is the code that I have (I have removed parts which I think are not relevant): \documentclass[12pt]{article} \usepackage{listings} % Python style for highlighting \newcommand\pythonstyle{\...
1
vote
1answer
176 views

Extend keyword list for fancyvrb / listings, based on a given language

I use fancyvrb and listings packages, and I have defined a language scala, which is the default to use. In one occasion, I have an extension of that language, escala, which adds additional keywords. ...
1
vote
0answers
201 views

LaTeX places a float in the middle of my script. How do I prevent this? [closed]

I have a multi-page script in my thesis, and I have used the listings package to format the source code. This works really well, however LaTeX wants to put a float in the middle of this code, which ...
8
votes
1answer
6k views

Problems with the lstlisting environment (margin and white line)

Consider the following example: \documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{columns=fullflexible, basicstyle=\...