{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

7
votes
2answers
176 views

Using listings with output

I wonder how to get the output of listings with code. Here is my MWE with output. Now I want to output of this listings too. Any help will be highly appreciated. Thanks Code ...
3
votes
1answer
74 views

lstlisting in landscape and heading in portrait

I am trying to include some code files in landscape mode into my document which is in portrait mode. I do this using the \usepackage{lscape} and \usepackage{listings} So far so good. The ...
1
vote
0answers
44 views

How can insert a full-width listing in a two-column document? [duplicate]

I'm new to LaTeX; I'm using IEEE format. How can I effectively add Java code snippets in one full-width column?
4
votes
1answer
109 views

Lstlisting: width of background box

I'm trying to modify my listing environment in a way that the background color for the listing is expanded over the whole width of the page. So no white border left. Is this possible? I tried doing ...
8
votes
1answer
64 views

Adding color package destroys listing centering

I am using @egreg's answer to make listings centered: \documentclass[a4paper]{book} \usepackage[T1]{fontenc} \usepackage[ hang, small, it, hypcap=true ]{caption} \usepackage{fancyvrb} ...
0
votes
1answer
54 views

Listings Character problem

Hi I want to define a string in Listings but I can not do it in Turkish. I want to write: int[] sayılar= new int[5];' but the output is int[] saylar= new int[5]; How can I write Ç,ç,ı,ö,ü,ğ?
1
vote
1answer
82 views

Listing linebreaking not working

got a listing where the code include a very long sequence of characters (letters, numbers & other). With linebreak=true, the sequence gets broken at non-letter characters. However I still got a ...
3
votes
1answer
53 views

Why don't those non-alphanumeric chars (*/_) get colored in blue, here?

Consider the following example: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{language=R, morecomment=[l]{>}, commentstyle=\color{blue}, alsoletter={*} ...
4
votes
1answer
134 views

What can I do if a listing is too wide to fit in my two-column document?

I am writing a IEEE document with a LaTeX template I downloaded from the IEEE webpage. I inserted some MATLAB code into the document through the mcode package. It looks something like this: ...
3
votes
1answer
110 views

How to copy/paste multiple spaces from lstlistings?

This is a continuation of a question that I asked already: How to copy/paste from lstlistings?. The solution presented there does not work if the text within the lstlistings environment contains ...
4
votes
1answer
93 views

How can I highlight JSON string values but not attributes?

example { "name" : "alan", "alias" : "nala" } If I use morecomment=[s][\color{red}]{"}{"}, How can I highlight JSON string values (on the right side) but not the attributes (left side)?
5
votes
1answer
110 views

Correctly highlighting custom html tags in listings

Problem statement I have several code listings containing HTML markup in my latex files. These listings contain multiple custom html tags (created in combination with corresponding AngularJS ...
0
votes
0answers
118 views

Pandoc: Markdown to PDF: select code without select number into code block

i want to generate the code block and i try example and it work. but when i try to select the code from the pdf, the number also get selected. how to generate code block that when select the code w/o ...
6
votes
1answer
69 views

How can I apply different styles to different classes of identifiers?

I am creating a custom style for the lstlisting package, with some custom colors for certain words. I am trying to define different "classes" of words, where each class has a certain property, like ...
4
votes
1answer
40 views

Color behind numbers in lstlisting

Currently, my listings use this style : \definecolor{lstgrey}{RGB}{217, 217, 217} \definecolor{lstback}{RGB}{246, 246, 246} \newlength{\numberlengthnormal} ...
3
votes
3answers
148 views

\lstlistoflistings title says “Table of Contents”

When I tried \lstlistoflistings to print the list of all my listing, the title says "Table of contents", and then it says chapter. Like if it was part of the TOC. I'm trying to get a list, like the ...
10
votes
2answers
304 views

How can I hide (or blur) some code in a listing?

I have a code listing to write in a report, but I'd like to blur or hide some code parts with a colored box (of same length as the hidden text), so that readers cannot see the hidden parts. (Another ...
0
votes
0answers
56 views

Layering/twocolumn conflict using tikzmark

LaTeX gurus, inspired by the ideas and code in Automatic background coloring in listings using tikzmark, I attempted to create my own macros for teaching programming. What I really wanted, just to ...
2
votes
1answer
74 views

How to only have similar font in latex to that of a Mathematica codes

After I used the answer posted to this question of mine: How to show similar display of codes of different programming languages in LaTeX, it seems that the package and styles I use have problems with ...
4
votes
0answers
51 views

Source code listings - proper indenting [duplicate]

I'm doing a project where I need programming source code printed throughout a PDF, with syntax highlighting and keeping the original spacing and indentation intact so copy/pasting works. Because I ...
1
vote
0answers
39 views

How can I add annotations at the end of each line of a listing? [closed]

(I'm new to LaTeX.) I'd like to annotate each line of a (Java) listing (typeset with listings) to specify the computation time associated with it. However, I can't simply edit the file and add the ...
3
votes
0answers
45 views

Define new command which insert environment [duplicate]

Am i able to do something like this: (without defining new environment) \newcommand{\code}[2] { \begin{lstlisting}[language=#1] #2 \end{lstlisting} } I don't want to write: ...
13
votes
1answer
220 views

Possible to have # start a comment that ends at EOL or at next #, whichever comes first?

I'm trying to create a listings language in which the # symbol starts a comment that ends at the end of the line or at the next # symbol encountered, whichever comes first. Of course, I'd like to ...
1
vote
1answer
52 views

Install listings package manually

How do I install the listings package manually ?. With other packages I used to download all the files needed and copied in the right folders and then refreshing the packages and it worked perfectly, ...
4
votes
0answers
97 views

(Clickable) cross-reference in lstlisting

To generate documentation for an 'application programming interface', I would like to have a syntax highlighted area (with the class declaration), which has clickable links to the documentation (which ...
4
votes
2answers
170 views

Saving language preferences for inputing source code

Using the listings package, I am trying to input a Java source file into my document using a specified, user-defined style. This works just fine if I have the specified style definition in the same ...
2
votes
2answers
95 views

embedding listing code into tables?

I want to create a simple table in this case with the first column having snippet of code, and the secon column describing it. The command \java is just defined as: ...
13
votes
1answer
637 views

How to show similar display of codes of different programming languages in LaTeX

I am very new to LaTeX and I am writing my thesis. In a chapter, I want to show my codes, which are in Mathematica. I use the listings package as follows: \documentclass{article} ...
4
votes
1answer
42 views

Inserting caption for listings in LyX

I'm using LyX 2.1.1 and want to put captions for listings. I can do this by using LaTeX code in ERT but would like to do by using LyX built-in capabilities of Insert > Program Listing. Any help ...
2
votes
1answer
80 views

Annotate insertions/deletions in listings

I'd like to annotate some lines in my lstlisting environment as having been added or deleted. To do this I'd like to put a (+) or (-) symbol next to the line numbers, like this: 1 function foo ...
5
votes
1answer
63 views

How to set the listings font for the whole document

How do I change the listing font size of the whole document? I am quite sure that it must be specified in Document->Settings->Listings but I do not know the input parameter for setting the font ...
2
votes
0answers
51 views

How to pass the option “listings” to examplep [closed]

I've been trying to pass the option listings to the examplep package. According to the documentation one can pass the options to activate the listing by doing listings=yes, listings={}. However, ...
2
votes
1answer
73 views

showexpl not showing caption of a lstlisting within

How can I make the LTXexample environment to show the caption (like it does with other environments) of a lstlisting that is inside it. Consider the following code \documentclass{article} ...
1
vote
0answers
33 views

Work around 'Dimension too large' using `framed` with `listings`

I'm including an external source code file as an appendix using the listings package. The framed package is being used to ensure multi-page listings frames are fully closed. The problem is if my ...
4
votes
2answers
134 views

Difference between fixed-width and proportional typewriter fonts in listings?

In the MWE below, I wonder why does the pcr (Courier) font align in both escaped and unescaped versions and for whatever column setting of {listing} - while the cmtt (Computer Modern Teletype) aligns ...
3
votes
1answer
47 views

Change Character Color in listing

I want to change some special character's color in listing for example all Parenthesis be red. I don't want to make them keywords they should have different color. is it possible?
6
votes
1answer
93 views

How can I prevent the background from overlapping the rounded corners in an \lstinputlisting?

I want to include listings of external files in my document. These listings should have a solid background and rounded corners. The problem is, that if I define a style with frameround and ...
2
votes
1answer
73 views

Highlight line numbers in listings, conflict with hyperref package

I want to highlight the line numbers of the lines of the Listing to which I refer. See the question Highlight line numbers in Listings for details about how to highlight one line number. Now I want ...
5
votes
1answer
91 views

How to use \pretocmd with \verb or \lstinline?

I write my document in other language, then I need to switch to English (switch font) when show code: \newcommand\code[1]{\lstinline{#1}} \pretocmd{\code}{\begin{otherlanguage}{english}}{}{} ...
2
votes
0answers
44 views

Listings - Keyword with Regex [duplicate]

I would like to colorize in a special color all my constant which are all in capital letters in my code and all my method variables which begin with an @. Is it possible to use Regex to define ...
1
vote
0answers
72 views

Code alignment using listings with proportional fonts is poor

I would like to typeset code using proportional fonts and the listings package, but no matter what I do, alignment is always off. Here is an example in Java (taken from Wikipedia): ...
4
votes
1answer
79 views

Formatting code into the style used in Stackoverflow

I know that there is minted and listings for displaying nice code in .tex documents. However, I'd like to use the style that is used for Stackoverflow code: example. Are there any packages for this, ...
4
votes
2answers
86 views

Latex listings package, issue with caption touching the frame and junk character instead of space

I am using listings package and facing two issues Following is the LaTeX code and output \lstset{language=Java, basicstyle=\small, frame=single, breaklines=true, ...
2
votes
1answer
35 views

XeTeX is printing explicit space characters inside quoted strings

I'm using XeLaTeX with this: \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{spanish} But when I write this listing \begin{lstlisting}[style=Pyshell] >>> print ...
2
votes
2answers
50 views

Latex create a second keywordstyle using listing doesn't work

I need to insert some code in my latex document, using listings. I create my own set, for a java language \lstset{ language=Java, aboveskip=3mm, belowskip=3mm, showstringspaces=false, ...
2
votes
2answers
108 views

Problem with 'é' character in listings

I have this MWE \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[frenchb]{babel} \usepackage{colortbl} \usepackage{lmodern} \usepackage{listings} ...
1
vote
2answers
64 views

Change space style using listings package

I'd like to make all space characters in the code gray. Is there an easy way to do this? Is there something like spacestyle (I've commented it)? \documentclass[a4paper, 10pt]{book} ...
4
votes
2answers
74 views

Aligning two minipages - one with lstlisting, one without - on top?

I'm already aware that two minipages with [t] align at the baseline of the top line, not at the top of their respective boxes/containers; however, this is somewhat different: when I use a small ...
4
votes
1answer
67 views

Using lstinline in caption of lstlistings with multicol?

Consider this MWE: \documentclass{article} \usepackage{multicol} \usepackage{listings} \begin{document} \def\extra{extra} \begin{lstlisting}[ multicols=2, caption={ [short] aaaa \extra, ...
3
votes
1answer
37 views

How to display a code using lstinputlisting that isn't separated with figures?

This is the code I used: \lstinputlisting[language=Python,breaklines=true]{seminar_ED.py} It works fine with displaying the code over multiple pages when I don't add other figures in the text. But ...