{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

4
votes
2answers
27 views

displaying ?? instead of the name of the lstlisting when using \cref

I change the name of the label of the lstlisting to Algorithm and it works fine for the caption. But when I use \cref, the instead of displaying algorithms 1 it shows ?? 1. \documentclass{scrreprt} ...
1
vote
0answers
36 views

How to insert sourcecode?

For my internship, I have to print all the source of my iOS application to a LaTeX file. Now I'd like to do this in a structured way by having sections, subsections and subsubsections for each nested ...
2
votes
2answers
22 views

Change `lstlistoflistings` numbering

I'm using the listings package to format program code in LaTeX and the list of listings at the end is numbered like this: 3.1 Code A 3.2 Code B 3.3 Code C 4.1 Code D 4.2 Code E It starts the ...
0
votes
1answer
30 views

lstlistings: Regexp quotation mark/apostrophe error

I am attempting to display a long Python Regexp in LaTeX lstlistings. When compiling I get the following error message though. ! Package inputenc Error: Unicode char \u8:�\lst@FillFixed@\lst@EC� not ...
4
votes
0answers
33 views

Delimit comment on special character

I have defined a new language in Latex (Clojure) but I'm having some issues with delimiting keywords. A keyword in Clojure is any alphanumeric string starting with a colon. E.g., :foo-bar-baz. So far ...
0
votes
0answers
25 views

Listings not showing in \lstlistoflistings

My document looks like this when at the listings page (i dont get any errors, its just empty): My document is like this: \documentclass[a4paper,12pt]{book} \usepackage{apacite} \usepackage{natbib} ...
2
votes
1answer
32 views

How can I show listings even when the class option 'draft' is set?

The question Is it possible to configure the listings package to show the content in the lstlisting environment even if the global option draft is set? Context When working on a larger document, ...
0
votes
0answers
24 views

Force figure to be a listing

To center my listings on the page I followed a tutorial on tex.se.com and that resulted in the following code: {\renewcommand{\figurename}{Listing} \begin{figure}[H] % the figure provides the caption ...
3
votes
0answers
29 views

minted or listings input a file between markers

Is it possible, using the minted or listings package to format a file between or till a certain textual marker automatically. E.g. consider a source file: code code //marker code ... //end marker ...
2
votes
1answer
46 views

Strategy for listings next to code comments

I'm looking for strategies to produce listings of code with comments on what's happening next to it. I've found other similar questions, but not quite what I'm looking for. See for example: Listing ...
1
vote
1answer
48 views

how to embed arbitrary code

I am using the listings package which does great things for C++, Java. but what about for a makefile, which isn't one of the supported languages? I just want the equivalent of listings, nothing ...
1
vote
0answers
64 views

How can I typeset PowerShell code with the listings package?

I'm currently creating my diploma thesis, and used PowerShell to do some of the described work. I'd like to also put some of this code into the thesis and would therefore like to have syntax ...
1
vote
0answers
49 views

Add caption and list of listings to own listings environment

With listings and caption packages I can set up caption for lstlisting with \captionsetup[lstlisting]{...} create list of lstlistings \lstlistoflistings I can also define my own environment ...
1
vote
1answer
45 views

Define starting line number when using mcode.sty to display Matlab code and referring to the code

I want to include parts of my Matlab code in my LaTeX document using mcode.sty. Here's a MWE: \documentclass[b5paper, 10pt, twoside, openright, dvipsnames,cmyk]{report} \usepackage{listings} % Is ...
0
votes
0answers
24 views

Latex list of listings wrong formatting [closed]

I have a problem with my list of listings in Latex. I have changed the title of list of listings with this command: \renewcommand{\lstlistlistingname}{Seznam zdrojových kódů} For printing list of ...
3
votes
1answer
45 views

Overfull \hbox in C++ code (listing-package)

I currently have a problem with writing C++ in latex. I have a very long string of text inside my code, that interferes with the space. So how do I fix this?? The code: ...
1
vote
1answer
37 views

XML code in a Box

Here is a minimal version of my code: \documentclass[12pt,a4paper]{book} \usepackage{listings} \lstset{ basicstyle=\ttfamily, columns=fullflexible, showstringspaces=false, ...
2
votes
0answers
20 views

Indentation marker for listings

I'm currently writing a document that contains several code samples. I included them as lstlistings and played around with the colors and everything, so they loot quite nice now. My only problem is ...
1
vote
0answers
38 views

lstlisting package indents code too much [closed]

I cannot figure out why this happens. I have been trying to figure it out for some hour now but I can't seem to find what is causing it. The lstlisting code snippet indents like crazy, which causes ...
1
vote
1answer
38 views

Python code block outside of margin

I want to include some Python code to my Latex document. I have read this Tex Stackexchange question and added the following code to get syntax highlights: \usepackage{color} ...
3
votes
2answers
28 views

Paragraph indentation after lstlisting environments

I tried to indent first paragraph after a customized lstlisting environment \documentclass{article} \usepackage{listings,lipsum} \lstnewenvironment{mycode}{}{\par} \begin{document} \lipsum[1] ...
2
votes
1answer
30 views

Listings “cannot load requested language” after newly-defined dialect

[Note that this is not a duplicate of ajeh's question] I have defined a new XSLT2 dialect of XML for the listings package which includes some extra keywords beyond XSLT, but I can't get it to ...
2
votes
0answers
25 views

How to highlight php code in a HTML document and the document itself?

how can I highlight php code in a HTML document and the document itself? Example: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8"> ...
5
votes
1answer
67 views

Referring with cleveref to a custom listing (\lstnewenvironment)

I use cleveref's \cref command for referencing, and \lstnewenvironment to create a new listing type. My document has multiple types of listings, each of them with their own counter. However, cleveref ...
2
votes
1answer
54 views

Problem with tcblisting at page break

I use a tcolorbox to display my listings and thats actually works pretty well. But if in my listing a page break occurs, then my predefined "basicstyle" property will be removed. And I have no idea ...
1
vote
1answer
24 views

Verbatim/listings in beamerposter?

I have prepared some nice posters using beamerposter, but now I came to a poster where I would like to add a few lines of code. By just adding [fragile] to the frame I get an error: File ended while ...
1
vote
1answer
21 views

References not working for \lstinputlisting

I may be doing something wrong but can't realize what... I want to set a label for a piece of code represented by: \lstinputlisting[language=Python, label={lst:control_os_call}, firstline=231, ...
3
votes
1answer
63 views

tikz/pgf upgrade and decorations

Since a major upgrade in pgf, my code does not compile any more. I am trying to make "decorated" source listing, where the decorations can be like highlighting some lines (see the MWE), balls on some ...
3
votes
1answer
44 views

Custom List of Listing Page Numbers Not Working

So I have been using this particular latex template for a while now and I keep adding and changing it to be what I want. Recently I tried reformatting to get rid of the leading dots in the TOC, LOF, ...
2
votes
1answer
54 views

How to make listings package break TeX code only after control sequences?

Package listings always likes to break TeX code after backslashes. How to make it always break before backslashes? \documentclass{article} \usepackage{listings} \begin{document} ...
2
votes
1answer
44 views

Colorful prebreak and postbreak tokens with listings package

I want to get colorful prebreak and postbreak tokens with listings package, but the following code doesn't work: \documentclass{article} \usepackage{xcolor,listings} \begin{document} ...
1
vote
1answer
84 views

Error compiling code matlab in latex

good morning, someone help me? MWE: \documentclass[preview]{standalone} \usepackage[latin1]{inputenc} \usepackage[spanish]{babel} \usepackage{latexsym,amsmath,amssymb,amsfonts} ...
4
votes
0answers
47 views

\inputminted: distinct file parts in one listing (equivalent to linerange in listings)

I want to include code from a file into my document. However, several distinct line ranges should appear in the same listing. Also, I want to use gobbling, and it would be nice to include some blank ...
7
votes
2answers
95 views

New Command For Inline Code

I am using the listings package to enter large blocks of code into my document, however I am trying to write a custom command that uses my current settings to do inline code. For example I want to be ...
0
votes
1answer
28 views

How to number listings by section number? [duplicate]

I want to include several listings in my document with sections. I also want each listing to have labels like Listing 2.1 where 2 is section number and 1 is number of given listing within that ...
1
vote
0answers
33 views

How to add function names to listings package

I have some MATLAB code in my tex file, which I am highlighting with the listings package. However, there are some functions, such as "vision.CascadeObjectDetector", "imcomplement", "bwboundaries", ...
1
vote
0answers
46 views

List Of Listings Overlapping Text

I'm attempting to generate a list of listings for my dissertation. The university doesn't have a standard LaTeX template, but there is a pretty good one generated sometime ago that does the trick. The ...
1
vote
1answer
54 views

Wrong string color in embedded code

My problem is that when I use the correct quotation marks ``'', lstset does not recognize strings in my code and thus does not color-code them. When I use standard double quotes "", the leading ...
3
votes
0answers
90 views

lstlisting escape ů [closed]

please how can I escape character ů? \documentclass[a4paper,10pt]{article} \usepackage[utf8x]{inputenc} \usepackage{listings} \lstset{literate= {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 ...
2
votes
1answer
29 views

How can I effect a line break in a listing's caption defined with \lstname?

I'm using the package listings and defined the caption as \lstname, so it shows the relative path and the filename when I use the input command of the listings package. However, sometimes, the ...
1
vote
1answer
26 views

Breaklines in lstset does not work sometimes

I am including some code into my tex file via \lstinputlisting[]{}. Unfortunately sometimes the breaklines=true-command does not work. Example: In line 65 the linebreak does not work, but in line 70 ...
1
vote
0answers
30 views

Use listing with automatic page break

I want to put some of my python-code in the appendix of my latex file. For that I use the following code: \begin{minipage}[c]{0.95\textwidth} \lstinputlisting[caption=Python script used for fitting ...
2
votes
1answer
37 views

bound width of a single lstlisting to one column inside a two column IEEE template

I use IEEE double column template and inside it I add a C++ code. I expect the code to be bounded within a single column however it infringes to the next column. How to fix this code? I would avoid ...
2
votes
1answer
66 views

Match font between \texttt and text inside lstlisting

I am trying to match the font between the line that says: reg [8:0] data_saved [0:3]; // memory declaration and the rest of the lines that are inside lstlisting. Here is what I get: My code looks ...
0
votes
0answers
36 views

Listings tcbinputlisting

This is a follow up question. Have a look at my comment on the answer to this one: Listings: line number separator rule How do I use the input and the environment of tcolorbox? I have created a ...
0
votes
1answer
35 views

Why does the simplest \newenvironment not work as expected? [duplicate]

\documentclass{article} \usepackage{listings} \newenvironment{hello}{\begin{lstlisting}[language=sh]}{\end{lstlisting}} \begin{document} \begin{hello} ls \end{hello} \end{document} The code ...
2
votes
0answers
42 views

How to mix LaTeX listings numbering with custom characters?

In order to display a command-line GAP session using the listings package, I need to distinguish between input and output. I tried to do this by appending a marker in front of every output line, so ...
1
vote
1answer
47 views

Error in some rare circumstances: babel with french option after listings, active character in moving argument, code in listing across pages

Edit: I have edited my question which initially wrongly focused on labels. This question is related to Code in \lstlisting breaks document (compile error). Let us consider the following MWE: ...
4
votes
1answer
32 views

newcommand with optional argument displays wrong text

I tried to set up a new command with optional arguments. The problem is that the command displays 'st:code'. What's wrong? Thanks in advance! \documentclass[a4paper,twoside,10pt]{report} ...
1
vote
1answer
51 views

Uncover listings code blocks

I am trying to highlight code lines in the listings package for a presentation. The following working example shows how I have been able to hack my way to a solution, however I am now at the point ...