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

Float package screws up list of listing format/style

Can anyone explain the following behavior: MWE: \documentclass[12pt]{report} \title{List of listings problem} \author{Gerjan} \date{June 2016} %\usepackage{babel} % Use dutch, british or english \...
1
vote
0answers
11 views

Adjusting the text width of R listings in LaTex

Hi I have R codes that I am listing in my LaTex file with \begin{lstlisting}[language=R] R code \end{lstlisting} I have no specific listing setting in my preamble. My R code is very wide and ...
2
votes
1answer
44 views

How to automatically adjust font size for listings, so it fits gives amount of textwidth?

For code listings, I often change the listings parameter basicstyle to adjust the font size so that listing fit within the container it is in. I mainly use a cell in a table to display small listing ...
4
votes
1answer
28 views

Categorizing Listings

Is it possible to group listings by type? I have a document with two types of listings, namely one for source-code and one for series of shell-commands (and their outputs). So is it possible to have ...
3
votes
2answers
38 views

List of listing space before title

I know I can control the space of my listing titles with: \setlength{\cftbeforetoctitleskip}{35pt} % TOC: Table of Contents \setlength{\cftbeforeloftitleskip}{35pt} % LOF: Listing of Figures \...
3
votes
1answer
31 views

some corruption using \tcbinputlisting after repeated use

I could not make a smaller MWE than the following. I noticed at random places in the document, the listing comes out corrputed, then it becomes ok for a while, then it goes bad. I am basically using ...
0
votes
0answers
33 views

How to create a specific code listing macro

I am trying to reproduce a macro in latex that would allow to insert code in this format: So there is a header with listing number that is starting from the left side of the document. It is between ...
1
vote
0answers
28 views

Changing multiple properties within lstlisting in annimations

Currently I am in the process of preparing a C++ training with the beamer package. So far everything is great! From the answer to How can I highlight some lines from source code I grabbed a nice ...
1
vote
1answer
32 views

using \tcbinputlisting shows first page only when hbox is set

I'd like to use the hbox option with \tcbinputlisting since it automatically adjust the background color and the box to the width of the code listing. The problem is that if the code listing is more ...
4
votes
1answer
31 views

Number listings the same way as figures and tables

For numbering figures and tables with 1 depth level like this: Figure 1.2 Table 3.13 I use the package: \usepackage{chngcntr} \counterwithin{figure}{section} \counterwithin{table}{section} \...
4
votes
1answer
40 views

error using tcblisting inside tabular when numbers is set

tcblisting gives error when adding numbers=left, but it does this only when inside tabular or longtable. This compiles OK \documentclass{article} \usepackage{amsmath} \usepackage{listings} \...
2
votes
0answers
58 views

Code crashes on Mac OSX, not linux?

Using TexWorks. 2 people using Mac OSX, one El Capitan, one Yosemite. 1 person using linux. The following code works on linux: \begin{tabular}{|l|l|l|} \hline Scalar form & Meaning & ...
0
votes
1answer
47 views

Space difference between list of figures and list of listings

See attached gif You got any clues how to fix that? I’m using a Koma class.
0
votes
0answers
16 views

Listings - collisions between literate and comment delimiter

Scenario: I want to get the listings environment to perform line breaks at forwards slashes "/" so that it will wrap long paths, which I can do by using the 'literate' option as follows: literate={/}{...
0
votes
1answer
22 views

Correct numbering of figures/tables/listings in Appendix

In my thesis I have several appendices, which are defined via \section{First Appendix}, \section{Second Appendix}, etc. latex statements. The appendices have the following titles (hence, appear like ...
1
vote
1answer
24 views

Listings numbering in Appendix

Currently, I have an issue that in my thesis the numbering of listings in the appendix is not as desired. I currently only get Listing 1 as the numbering of the first listing in the first Appendix, ...
9
votes
2answers
66 views

Inline links in code listings

I would like to include links inside source code listings by providing URLs within the listing source text. That is, I would like to be able to generate something that looks like the following: ...
3
votes
1answer
35 views

Conditionals work, Listings work, but when put together, no [duplicate]

In an earlier question I learned the following code to define conditionally compiled text (for a teacher guide) \newtoggle{teach} \toggletrue{teach} \NewEnviron{teachr} {\iftoggle{teach}{\BODY}{}} \...
3
votes
1answer
81 views

“Table of Figures” Title and “Table of Codes” Title not in the same line

Hello! I have the following problem: the title of my table of listings (codes) is not in the same position as the title of my table of figures is. You can see the 2 pages of the tables in the pic. I ...
0
votes
0answers
18 views

Getting package error when importing source file

I have a problem with import source code into my tex document. The source code is in language C with lots of comments like "\" and "* *\".
7
votes
1answer
52 views

Colorize symbols with lstdefinelanguage in latex

I want to put some symbols in green color with lstdefinelanguage in latex, but it seems that symbols are not recognized. The symbols I need to be colored are =, > and <. Is it possible? How can I ...
2
votes
1answer
31 views

Multiline Matlab comments in package Listings

I am using the package listings to include some Matlab code in my report. It works well with comments beginning by % but does not recognise multiline comments %{ ... %}: \usepackage{listings} \lstset{...
3
votes
1answer
19 views

Semantic nesting error from underscores with `listings` while `syntax` is loaded

I use XeLaTeX and have TeXLive 2015 installed. I want to use both the listings package for printing code and the syntax package for printing grammars. For code, I also want to expand certain symbols ...
6
votes
3answers
135 views

How to only show text?

I have a document for a student research project and want to know how many pages content without figures, listings and tables i have. My university does differentiate between content and figures,... ...
0
votes
0answers
34 views

Use python as data source for Latex and DOxygen

I have python code where the comments contain latex code. Will it be possible to parse the code with doxygen and display the latex code as latex symbols. include the same code in latex (using ...
2
votes
1answer
28 views

\lstdefinelanguage cannot handle keywords #if, #endif,

I need to insert C-code snippets in my LaTeX document. Therefore I define a C-code language syntax highlighting: \usepackage[utf8]{inputenc} \usepackage{listings} \usepackage{color} \definecolor{...
2
votes
1answer
38 views

How to insert listing inside frame and between enumerate?

I'm creating a presentation and I want to add a one line code in the presentation between each itemize element. You can see below what I want to achieve. \documentclass{beamer} \mode<presentation&...
3
votes
2answers
35 views

An error appears saying that utf8 and listing are not compatible

If I compile the next code the following error appear. ! Package inputenc Error: Unicode char \u8:�\expandafter\lst@FillFixed@\fi not set up for use with LaTeX. See the inputenc package ...
1
vote
0answers
20 views

If I use listing package, i can not use listing environments, how could I use both?

If I use listing package, i can not use listing environments, how could I use both? In the next code Im using UTF8 and listing, but an error appear. This is my code. \documentclass{article} \...
2
votes
0answers
26 views

How can I get rid of indentation before my code? [duplicate]

My Javascript code has a large amount of whitespace in its block in the output pdf file. How do I get rid of this without un-indenting my latex code? Thanks in advance. \documentclass{article} \...
3
votes
1answer
39 views

error using tcblisting inside longtable, no error inside tabular.

I was testing a nice solution provided in this answer how-to-crop-background-color-in-listings-to-the-longest-line-in-the-code However, I happened to be using longtable and not the standard tabular. ...
9
votes
2answers
95 views

Listings for plain tex

Is there a package to produce syntax-colored blocks of source code in plain TeX ? A listings equivalent ? Or (maybe) some macro to produce a colored tex input for some given source code ? Is it ...
3
votes
0answers
41 views

Latex complains about missing $ from listing of source code

This is the smallest example I can come up which shows this problem. Latex complain about missing $ and the error is pointing to a line in code listing ! This problem can be resolved by doing 3 ...
5
votes
1answer
95 views

how to crop background color in listings to the longest line in the code?

listings package allows one to put background color to the code listing. The problem is that the background color extents to the as large as the text area the code listings happened to be in. This can ...
4
votes
1answer
40 views

Square brackets in listings caption

How to add square brackets as a caption in a listing? I tried putting caption inside of "{}", but then the output is quiet weird. \documentclass{article} \usepackage{listings} \begin{document} \...
3
votes
1answer
16 views

listoffigures not working properly

I have noticed that in my document the \listoffigures and probaly \listoftables are not working properly. There is no space in between the number of the figure and the text in the list. Also, if the ...
5
votes
1answer
34 views

Inline escaping {{ myVariable }}

How to escape Mustache notation inline for example: This is a Mustache placeholder {{ myVariable }} that will output myVariable. This seems to be causing errors: \lstinline{ {{#if}} ... {{else}} ... ...
0
votes
1answer
27 views

lstinputlisting shows wrong number in reference

I'm pretty new to LaTeX, so please be a little patiently with me. So here is my problem: I got some text and there i want to reference a little bit code shown in the next line. What i tried so far: ...
2
votes
1answer
30 views

adding frame=none to lstlisting options in \lstdefinestyle gives error with tabular

lstlisting has an option called frame= But when I use the frame=none in \lstdefinestyle and put the lstlisting command inside tabular or longtable I get an error Forbidden control sequence It ...
4
votes
2answers
38 views

Single character keywords/operators with no spaces with listings package

I want to add a very simple macro language to listings. It uses single-letter keywords/operators, with no whitespace between. I can't see how to make keywords that don't require some kind of separator ...
4
votes
1answer
28 views

Why making program listing with ACM style produces extra narrow caption?

I want to prepare a manuscipt for an ACM journal. The program listing appears with extra narrow caption, see at bottom. It is hard to believe, I found incompatility with package 'listings', in an ACM ...
4
votes
1answer
26 views

How to set macrocode using the listings package

When writing a dtx file, is it possible to typeset the code samples (i.e., everything enclosed in a macrocode environment) using the listings package? For completeness, here's Joseph Wright's model ...
5
votes
1answer
42 views

Using Bash listings to bold variables and functions

I am using the listings package to show some sample bash script lines; however, the otherkeywords argument is giving me trouble. As the listings documentation states: If one keyword is a ...
2
votes
1answer
32 views

why is adding subdepth package makes lstlisting give Matlab error loading file?

If I have a dollar each time I find a conflict between Latex packages I would be a rich man. I added \usepackage[low-sup]{subdepth} and now I am starting to get errors from matlab-prettifier when ...
3
votes
2answers
27 views

Source code listing using \lstinputlisting - prevent other floats splitting it up

I am using the listings package to take an external PHP file and display it as a code listing in my document. It spans several pages (fine) but unfortunately there are other floats which end up being ...
3
votes
1answer
32 views

How can I make a reserved word loose its special formatting in listings?

Consider the following example. \documentclass{minimal} \usepackage{listings} \begin{document} \begin{lstlisting}[language=sh] cat foo.c cat.c bar.c echo The cat ate the cheese \end{lstlisting} \...
0
votes
1answer
28 views

Listings titles in List of Listings

I have a question analogous to this one, but for listings instead of figures. In my TeX file, I have multiple listings defined as follows: \begin{lstlisting}[caption={A really, really, really, ...
3
votes
1answer
37 views

How to number program listings like figures

Is there a way to number program listings like figures and reference them? I have the following mwe: \documentclass{article} \usepackage{hyperref} \usepackage{listings} \begin{document} \autoref{...
2
votes
1answer
26 views

How to make Latex recognize individual keywords in lstlisting without delimiter?

I want to add a few lines of G-Code (used for 3D-printing) to my latex file using the listing package. Unfortunately, g-code is not supported as a language and therefore has no highlighted commands. I ...
5
votes
0answers
21 views

lstlining changing font in moredelim

lstlisting is not using the identifierstyle font inside of the moredelim that makes the identifier name red. In the example, the first varname is in tt font but the second is in roman. I want the ...