{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

0
votes
1answer
87 views

saner listings monospace font size relative to surrounding text size [duplicate]

Is it possible to make listings and especially inline listings font size to be saner? It appears that the font size is chosen so that capital letters of the monospace font are full height of a line. ...
6
votes
3answers
474 views

Unwanted White Lines in listings environment

\documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{basicstyle=\ttfamily\footnotesize, ...
3
votes
1answer
1k views

Change caption style of listings package without “caption” package

Is there a way to change style of a caption in listings without the caption package (make it smaller and non-bold)? I am using \lstnewenvironment to create my own customized environment and then use ...
3
votes
2answers
108 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 ...
4
votes
1answer
1k views

listings: Set tabsize while using spaces for indentation in the loaded file does not work

I am writing a report where I want to include some source code. To do so I use the listings package to load the content of the source files directly. Because of coding standards I am using 4 spaces ...
4
votes
1answer
292 views

Placing listing and figure side by side in memoir

I am writing a document using the memoir class where I want to place listings (with the listings package) and figures side by side. My first approach was to save the listing in a box and use subbottom ...
2
votes
1answer
127 views

How to prevent the source code overflow over the frame in a listing? [duplicate]

I am trying to ident my source code in a frame using the listing package. An example code is given below: \documentclass[article]{llncs} \usepackage[english]{babel} ...
2
votes
0answers
111 views

Deciding whether to end a line with a character or not in lstlisting [closed]

I need to write a document where there are written inputs and outputs of unix command line interface software (through bash). For example I need to show something like: $ git log --pretty=format:"%h ...
3
votes
1answer
275 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.) ...
2
votes
2answers
859 views

How to preserve tabs and whitespaces in \parbox in latex

I am currently trying to insert a batch file programming code in my report. I am using the code listing. I am not able to preserve white spaces and tabs to format my code! I tried using \hspace but it ...
3
votes
1answer
207 views

Can't insert newlines in the code listing

I am currently trying to insert a batch file programming code in my report. I am using the code listing. I am not able to add new lines to format my code! I have following code example yet: ...
2
votes
1answer
357 views

Javascript string delimiter not escaped properly in listings

I am trying to use listings to display Javascript code. Following the replies to another question, I worked out the following code: \documentclass{article} \usepackage{listings} ...
3
votes
1answer
287 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
127 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 ...
6
votes
3answers
562 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
184 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 ...
2
votes
1answer
542 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} ...
4
votes
1answer
293 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 ...
5
votes
1answer
181 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
87 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: ...
2
votes
1answer
313 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 ...
5
votes
1answer
272 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
57 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
243 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: ...
5
votes
1answer
548 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{% ...
4
votes
0answers
220 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 ...
9
votes
2answers
14k 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 ...
1
vote
0answers
195 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: ...
11
votes
1answer
1k 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
361 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
281 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} ...
9
votes
2answers
208 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 ...
8
votes
1answer
134 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 ...
3
votes
2answers
2k 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: ...
7
votes
1answer
457 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: ...
15
votes
1answer
250 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
130 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
273 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
337 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
210 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
89 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, ...
1
vote
1answer
204 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
244 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} ...
2
votes
1answer
83 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
106 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
284 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
146 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 ...
5
votes
1answer
204 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
197 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? ...