{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
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
2answers
45 views

Listings: add vertical padding without abusing frame

I have the following setup for my displayed listings: \documentclass[a4paper]{article} \pagestyle{empty} \usepackage{listings,xcolor,lipsum} \lstset{ backgroundcolor = \color{yellow}, ...
5
votes
1answer
90 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 ...
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 ...
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 ...
5
votes
1answer
46 views

How to work around a bug in listings package for parsing (Java) comments

When using the listings package (v1.5e; though v1.3 exhibits the same behavior) to put some Java source code on slides, I run into the following weird problem (bug?). I minimized the files to help ...
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
74 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
203 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} ...
4
votes
2answers
71 views

How to create a custom environment with a listing inside it?

Well consider the following code: \documentclass[a4, oneside,openleft]{book} \usepackage{listings} \begin{document} \begin{flushright}\begin{minipage}{0.9\textwidth}\begin{lstlisting} for (i) { ...
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}
4
votes
1answer
44 views

Listings literate option breaks identifiers

I wanted to raise the _ char in code listings because the T1 font I am using places it too much below the baseline; this causes identifiers like bla_bla look horrible. I am using listings so I thought ...
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, ...
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] ...
3
votes
1answer
42 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 ...
2
votes
1answer
51 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?
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{ ...
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
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 ...
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 ...
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} ...
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
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 ...
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 ...
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
99 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} ...
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,}, ...
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 ...
1
vote
0answers
31 views

Problem in listings add to \\ [duplicate]

MWE: \documentclass[]{article} \usepackage{xcolor} \usepackage{color} \usepackage{listings} \definecolor{maincs}{RGB}{255,0,0} \definecolor{secondarycs}{RGB}{255,179,246} ...
1
vote
0answers
19 views

Breaking lines of code using using mcode [duplicate]

I am using the following code in the main tex file: \usepackage[numbered,autolinebreaks,useliterate]{mcode} and this code in the appendix file: \lstinputlisting{C:/path/function.M} Considering ...
3
votes
0answers
62 views

Can I use “moredelim” in package “listings” to fetch a regular expression?

I would like to know if it is possible to use the listings package to highlight regular expressions in order to make them look like a normal string object. Note: The syntax of a regexp is not context ...
3
votes
1answer
34 views

listing in minipage sucks content of previous page to the bottom

I'm working on a document that contains many listings (namely code samples) but not a lot of text. Most of these listings are only a couple of lines long, and a few span multiple pages. At the end of ...
2
votes
1answer
46 views

Setting Entries of List of Listings in LaTeX. Package Listings

I'm trying to put an hyphen after the entries of the "List of Listings" as follows: List of Codes Code 1 -- First Code ................................ 7 Code 2 -- Second Code ...
6
votes
1answer
92 views

Can I have a pipe character inside the argument of \lstinline?

I'm using the Listings package and I wanted to ask whether it is possible to use the pipe character | with the \lstinline command as it uses the pipe as beginning and ending character. ...
5
votes
1answer
61 views

How can I put a code listing in a tikzposter \block?

I'm trying to put a code listing in my poster, but I get the following error: TeX capacity exceeded, sorry [input stack size=5000] What am I doing wrong? \documentclass[portrait, a0paper, ...
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: ...
1
vote
0answers
33 views

Using xtable with listings package

I am the listings package as suggested by the following solution provided in this question: Getting Sweave code chunks to stay inside page margins? More specifically, I am using the following piece ...
3
votes
1answer
46 views

Using lstenvironment in another environment

The following simple latex code doesn't seem to work for me and there seems to be no reason why: \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{listings} ...
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 ...
2
votes
1answer
52 views

Use macros within listing

I would like to use I macro I have defined (including mathematical symbols) within a listing environment. However, the following code prints "\foo{x}" rather than "bar(x)". Is there any way of ...
1
vote
0answers
28 views

Listings - two word keywords [duplicate]

I use the OPL language for optimization and I’m writing some notes on Latex using "listings". I defined the language and the keywords, so far no problems. However I have a keyword “subject to” and a ...
3
votes
1answer
82 views

Context dependent keyword color (listings). Question regarding (ab)using “otherkeywords”

I found it difficult to phrase this question briefly. Therefore I will try to construct it in such a way that I at least ask it clearly. My question is specific to: "otherkeywords" in the LaTeX ...
6
votes
2answers
174 views

How to define macros in order to reuse key-value parameters?

I use the listings package to typeset code in my document. I have defined a new environment via \lstnewenvironment in which I use \lstset to set a large number of options through a list of key-values. ...
3
votes
1answer
123 views

Combining MATLAB and C++ code in Latex

I have included MATLAB code in my report with \begin{lstlisting} and \end{lstlisting} but, in the same report, I need to include C++ code. I want it to recognise the language and highlight with colors ...
6
votes
1answer
92 views

Highlight code with squared brackets

I want to show some .ini file in my work. The ini file works with squared brackets. I try to use \lstdefinelanguage but I can't handle it. That is what I try before and in my understanding it should ...
1
vote
0answers
43 views

use path with spaces in listings fails when \usepackage[dutch]{babel} is used

EDIT: I just discovered that it is not due to the spaces but the " ": {"E:/Cloud storage/GitHub/JS_PCI/afronden2.js"} this line works if Babel is disabled and this one: {E:/Cloud ...
2
votes
0answers
25 views

XeLaTeX Listings package tabsize not correctly shown

I'm using XeLaTeX and I used the listings package to display some source code. In \lstset I set the tabsize to 4: \documentclass[a4paper, 11pt]{article} \usepackage{filecontents} ...
3
votes
1answer
62 views

Change caption of lstlisting from file

I load some code to my document like this: \lstinputlisting{MergeSort.txt}. This works perfectly, however I would like to add a caption in footnotesize to the bottom of the source code (without any ...