{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

1
vote
1answer
26 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
11 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
14 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, ...
0
votes
0answers
46 views

Packages for programming documentation

I am writing an exercise in school in which I've done some programming. I need to document and explain my design choices in my programming. Aren't there any suitable packages to create some kind of ...
0
votes
0answers
24 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
34 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
38 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
25 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
44 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
30 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
80 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
23 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
23 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
38 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 ...
0
votes
0answers
47 views

Listing using java problem with reference [on hold]

\definecolor{MyDarkGreen}{rgb}{0.0,0.4,0.0} % This is the color used for comments \lstloadlanguages{Java} % Load Perl syntax for listings, for a list of other languages supported see: ...
1
vote
1answer
43 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
25 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
25 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
25 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
20 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
55 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
30 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
32 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
34 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
42 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
28 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
47 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 ...
1
vote
0answers
20 views

Box of listing starts one page too early [duplicate]

I have the problem, that the box of a listing starts one page too early: Is it possible to allow the listing spreading over two pages, but not if there is an "empty line"? MWE: ...
4
votes
2answers
100 views

Specify delimiters in lstlisting to get some text in bold

I know the question has been asked several times, but I was trying to specify some text in bold in my lstlisting environment. While this was working perfectly with ...
1
vote
1answer
40 views

How could I write a Latex tag in source form in section name?

I tried to use \verb|| and \lstinline[language={[LaTeX]TeX}]{} and they failed. I just want to write a name of latex tags in section names for internal purposes. For example, I couldn't compile a ...
4
votes
1answer
81 views

How to handle box creation inside a question of AMC when shuffled

I am doing a follow up on How to expand a macro to use it inside a question in AMC?, as suggested by @Steven B. Segletes, so the question can be answered. Context I'm trying to use AMC to produce an ...
4
votes
1answer
584 views

Why can't I compile the simplest TeX file of only 6 lines?

\documentclass{article} \usepackage[adobefonts]{ctex} \usepackage[os=win]{menukeys} \usepackage{listings} \begin{document} \end{document} The simplest TeX file above cannot be compiled with ...
7
votes
1answer
128 views

Automatic creation of lstlistings in AMC questions

Context I'm trying to get an automatic exam where I can generate random numbers (using pgfmathrandominteger) in the AMC package to create different questions using code (listings) and inputing these ...
3
votes
1answer
65 views

Listings: line number separator rule

Here I found a similar question with horizontal rule, which answer I don't understand to a degree I could use it to solve my problem: Adding a horizontal rule between caption and lstlisting inside a ...
3
votes
1answer
49 views

Listings: recognize numbers and `1e-3`

This is a follow up question. Have a look at this one: Listings: syntax for literate with the solution by karlkoeller %Minimal \documentclass[]{report} \usepackage[utf8]{inputenc} ...
19
votes
1answer
240 views

How can I color parentheses depending on the nesting level (like emacs' rainbow-delimiters)?

Is it possible to have a custom setup for lstlistings for LISP-like languages and have matching parentheses coloured with a same colour taken from a palette? What I am looking for is something like ...
3
votes
1answer
63 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
60 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
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 ...
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
40 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
50 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 ...
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
48 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 ...
4
votes
1answer
85 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 ...
4
votes
1answer
67 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 ...
2
votes
1answer
22 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} ...