{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
64 views

Listings: syntax for literate

In the documentation for the listings package it says: literate = [*]<replacement item>. . .<replacement item> First note that there are no commas between the items. Each item ...
3
votes
0answers
61 views

Drawing arrows using tikz package (fine tuning coordinates)

I am making some lecture slides for my class and sometimes I need to label the different components of the C/C++ program. For this I have referred to the post How can I draw arrows within a listing to ...
5
votes
1answer
89 views

Not colored digits after characters in lstlisting code

I am writing a LaTeX document with Verilog code and I would like to have colored digits in these occasions: simple digits (for example # 30) bus (for example [3:0]) binary or hex representation ...
5
votes
0answers
51 views

Source code explanation in LaTeX [duplicate]

I was just wondering if it is possible to create source code explanations like the image below using LaTeX (listings or minted it doesn't matter). I'm Sorry I'm kind of new to LaTeX. Thanks in ...
8
votes
2answers
3k views

Which package to use for writing algorithms?

I am looking for a package that will allow me to write pseudocode of algorithms. The pseudocode may include mathematical symbols, like \forall, \in and subscripts. But I would like also to "talk" ...
1
vote
0answers
13 views

\lstinputlisting with source file containing logic symbols [duplicate]

I have a source code file that I want to include in my LaTeX document with \lstinputlisting. However, this source file contains logic symbols like ∃ (it's encoded in UTF-8), which produce errors. I ...
2
votes
1answer
36 views

Adding keywords to multiple languages in `listings` package

I have a pdflatex project where I need both Python and SQL listings. The listings package works great, I was able to add and reformat the extra keywords for Python with the following code: \lstset{ ...
1
vote
0answers
41 views

Verbatim vs Listings for Thai Font

I have a problem about verbatim and listings. I need write some codes by using Thai font but it shows in picture \documentclass[12pt,a4paper,oneside]{book} \usepackage{verbatim} \usepackage{listings} ...
3
votes
1answer
51 views

How to emphasize a part of a line in listing?

With the package listing I can use emph= to emphasize specific identifiers in the whole listing. \begin{lstlisting}[style=towi, title=Functions,emph={add}] void print(int arg) { /* ... */ } int ...
8
votes
1answer
129 views

microtype, listings and lrbox: What in the world is going on here?

The image says it all: I'm not sure what's going on, but it seems that microtype "breaks" the lrbox hack for coloring \lstinline. The code is here: \documentclass[a4paper]{article} ...
1
vote
1answer
51 views

Boxed text inside tcolorbox tcblisting?

I am writing a text which includes lots of programming snippets which I've put into environments which use tcolorbox/tcblisting: \usepackage[pdftex]{xcolor} \definecolor{vlgray}{gray}{0.9} ...
1
vote
0answers
49 views

Listings, coloured VBA with backslash [closed]

I'm currently writing my master thesis and have some extensive Visual Basic codes which I want to include in the appendix. The template I'm using for my thesis is "classicthesis" (from ...
10
votes
3answers
343 views

Fixing lstlisting inside exsheets question and solution environments

I am trying to use exsheets to prepare the tests for Foundation of Programming exam. I need to include snippets of C code in some question and solution and I am going to use listings (with the options ...
8
votes
2answers
2k views

How to make a box containing LaTeX output?

I am writing a short introductory book on LaTeX and I would like to implement nice looking code example boxes. Using this answer: Source code listing with frame around code? I made the boxes with the ...
4
votes
1answer
68 views

Why do I get this error when using listings' Algol language, and how can I fix it?

Using the listings package, I am trying to extend an existing language definition (Algol) with an additional keyword. It seems to be working (I get a desired result), but it produces an error during ...
4
votes
2answers
2k views

How to reduce Program-Listing line spacing in LyX

Using LyX 2.06. I have a standard document with 1.5 line spacing, but I want my program listings to use 1.0 line spacing. Is there a simple way to do this?
4
votes
1answer
86 views

italic font in lmodern-lighttt

In a search for a good monospaced font for my code listings I found the lmodern fonts. I really like the lighttt variant of those. The difference between normal and bold version is clearly visible ...
2
votes
1answer
23 views

Listings space -error

I get a strange symbol when i compile symbol on line 36 of this code: I am not sure what you press to get that nice box where you can write the code. Please dont downvote me. Edit the post. I have ...
3
votes
1answer
36 views

Width of caption larger than width of listing

Consider the following working minimal example take from here: \documentclass{report} \usepackage{color} \usepackage{xcolor} \usepackage{listings} \usepackage{caption} ...
2
votes
0answers
22 views

Listings package and forcing inclusion of empty lines at end of line ranges?

By default, the listings package suppresses empty lines at the end of the file, and this behavior can be switched off with the option showlines. However, listings also suppresses empty lines at the ...
1
vote
0answers
19 views

How to get listings package line number behavior of v1.3 in v1.5?

In the listings package v1.3, when including lines from a file, the numbering is that from the file, even if lines are omitted (absolute numbers). But in v1.5, the numbering ignores the location in ...
0
votes
1answer
37 views

Lstlisting inside minipage aligned to bottom

I'm trying to create a beamer presentation with latex. I have to show a few code snippets on a single slide so thanks to this site I created them using minipages and columns. I have created a minimal ...
4
votes
2answers
73 views

T1 vs LY1 behavior of lstlistings

I am writing a document with listings in it, which are typeset in Courier. When I changed the main font of the document, the package for this font (installed with autoinst) decided that it should ...
4
votes
1answer
198 views

Why am I getting an 'Illegal parameter number' error, here?

I have following text MWE: \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[color=red,opacity=0.1,contents={}]{background} \usepackage{hyperref} \usepackage{indentfirst} ...
5
votes
1answer
795 views

avoid linebreak in \lstinline if possible

By using \lstinline{mysourcecode} I put some code within my document. I would like to avoid that this code is broken to a new line, if possible. so, if the codeline itself is less long than a full ...
1
vote
1answer
90 views

Adding a horizontal rule between caption and lstlisting inside a tcolorbox

I have example listings for a book. I'd like a horizontal rule the width of the tcolorbox between the caption and the listing. The code used to produce it: ...
5
votes
3answers
2k views

How to get autoref working with different counters for different listing environments?

In my document I want several different custom listing environments. The solution from fraktalek works like a charm, except for one thing: \autoref doesn't work for me. I have tried the following: ...
1
vote
1answer
39 views

listing linux file /etc/fstab in latex document

In some document I have an /etc/fstab linux file listing with following MWE: \documentclass[12pt,a4paper]{article} \usepackage{listings} \begin{document} \begin{lstlisting}[language=bash] ...
6
votes
1answer
5k views

Adjust bottom margin of a listing environment

I use the following settings for code listings. \usepackage{listings} \usepackage{textcomp} \lstset{language=Java, keywordstyle=\color{RoyalBlue}, basicstyle=\scriptsize\ttfamily, ...
0
votes
0answers
30 views

Center a .txt listing [duplicate]

How can I center a text file that I insert with this code? Or is there an easier way to insert it? \lstinputlisting[label=output, caption=Output File]{output.txt}
3
votes
1answer
67 views

Spacing issues with T1 libertine and listings

Consider the MWE \documentclass{article} \usepackage[T1]{fontenc} \usepackage{libertine} \usepackage{listings} \lstset{ columns=[l]flexible, breaklines, % fontadjust, keepspaces, ...
2
votes
1answer
50 views

Lyx code tag with highlighting for C

I just installed Lyx and when I try to insert the program I observe that there is no syntax highlighting. What is the best way to allow for syntax highlighting in LYX?
3
votes
1answer
40 views

How to remove # keyword from a listing style?

I have a snippet of code I'm putting into a paper written in LaTeX. I don't want it to highlight any of the keywords that start with a # sign, such as #define, or #pragma. Here is a MWE of what I ...
15
votes
2answers
12k views

Source code listing with frame around code?

I'd like to make my code listing looking more sexy. I found a good example on SO, but one problem is remaining: I would like to not only have a horizontal line at the bottom of the listing but also ...
5
votes
1answer
54 views

Listings, keywords with backslash in them

This probably have an answer on here somewhere... Here is an MWE: \documentclass[a4paper]{memoir} \usepackage{listings} \usepackage[svgnames,dvipsnames]{xcolor} \colorlet{level1}{red} \lstset{ ...
1
vote
1answer
171 views

lst include has first line indented [duplicate]

When I'm including a source file, by way of \lstinputlistings{file/path/to/file} However, This results in the following below: Why is the first line not being formatted correctly? And how do i fix ...
4
votes
2answers
760 views

Listings with rule above caption to look like \floatstyle{ruled}

I am using the listings package. I would like my listings to have a heavy rule above the caption, so it looks like the \floatstyle{ruled}. So it would look like: a bold line === caption ...
1
vote
0answers
30 views

Inserting a stand alone code file using lstlisting

I am in the process of writing a report on a project and need to include the final code used in an appendix. The final code while not yet complete, is lengthy enough that I would like to just use ...
3
votes
0answers
39 views

How to use same font-style with escapechar in lstlisting?

Original Question I want to highlight something inside a C++-comment in a code-listing. \documentclass[a4paper, 12pt]{article} \usepackage{color} \usepackage{listings} ...
0
votes
0answers
11 views

Make listing look normal (ttfamily and character spacing) [duplicate]

listings seems to like protrude characters. Every time I see that I have this strange urge of killing a kitten. How can I get rid of it? \documentclass{article} \parindent0pt ...
1
vote
1answer
66 views

Problem in listings, colored split command

MWE: \documentclass[a4paper,11pt]{book} \usepackage{color} \usepackage{listings} \lstdefinelanguage{mytex}[LaTeX]{TeX}{ alsoletter={\\}, morekeywords=[3]{\\mbox,}, ...
1
vote
1answer
28 views

Listings doesn't recognize Pascal // comment

listings doesn't seem to recognize the Pascal comment syntax '//' ({...} works fine). The text isn't formatted correctly. A minimum example to reproduce: \lstdefinestyle{pascalstyle}{ ...
2
votes
2answers
63 views

Caption above and legend below environment listings

I want to know how to put a legend below the frame of a listings environment, such that it do not break the settings for the other two kind of lists that i have. Legend must be without number, aligned ...
2
votes
1answer
36 views

Code caption with listing without title, only numbers

I'm writing a book in spanish which has R code in it. I need some of the code listings to have a caption but I don't really need a title. I want the caption to show also the number of caption and ...
8
votes
4answers
2k views

Problems with copy and paste from PDF using lstlisting

I'm using lstlisting to create course notes from which I am hoping that code can be copy&paste'd I've already implemented the suggestions in Phantom spaces in listings (pdf) to make sure that ...
0
votes
0answers
20 views

lstinputlistings mark parts of the code [duplicate]

I am including my source code with the listings package and \lstinputlisting[options]{path/to/code.c} Now I want to mark some parts of the code with a different background, or a different text ...
3
votes
1answer
47 views

Can I have a listing with fixed column code and full-flexible comments?

MWE \documentclass{article} \usepackage{listings} \usepackage{lmodern} \lstset{ language=C, basicstyle=\ttfamily, commentstyle=\rmfamily } \begin{document} \begin{lstlisting} int a; // a ...
5
votes
2answers
98 views

Problem in listings, hyphenation not correct

MWE: \documentclass[a4paper,11pt,twocolumn,openany]{book} \usepackage[left=1.5cm,right=1.5cm,top=2.5cm,bottom=2.5cm]{geometry} \usepackage{color} \usepackage{listings} ...
3
votes
1answer
50 views

Not enough emphasis on some symbols

I'm trying to write some text in bold font but some symbols are not set in bold properly. The emphasis is set with \bfseries and is correct for :: and = but not enough for > and -. See below image for ...
2
votes
0answers
79 views

linewrap included Javafile with lstinputlisting

I've spent few days already trying to properly include a Java source file dynamically in a tex file. The text is included. However the lines don't wrap. The following is the "srinked" project ...