{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
1answer
68 views
+100

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 ...
2
votes
1answer
918 views

Code in \lstlisting breaks document (compile error)

I want to show a JSON object in my document. If I do the following, it works: \begin{lstlisting} { "id": "5", "key": "discardedCard" } \end{lstlisting} But if I extend the code to the ...
3
votes
1answer
118 views

showexpl not showing caption of a lstlisting within

How can I make the LTXexample environment to show the caption (like it does with other environments) of a lstlisting that is inside it. Consider the following code \documentclass{article} ...
6
votes
1answer
108 views
+100

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 ...
2
votes
1answer
34 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
21 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
38 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} ...
5
votes
2answers
4k views

\lstinputlisting will not continue to next page

So I have this LaTeX snippet: \section{Appendix} \listoffigures ... \begin{center} \begin{figure} \caption{MacroCell with 8 AND Gate Arrays} ...
3
votes
0answers
27 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 ...
6
votes
2answers
75 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 ...
8
votes
2answers
1k views

Emphasize word beginning with uppercase letters in code with lstlisting package

Hi I am using the lstlisting package to format my Prolog code within my tex file. In Prolog all variables begin with an uppercase letter. I would like to emphasize them. Is there a way to for example ...
4
votes
2answers
70 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
1answer
21 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
22 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", ...
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 ...
19
votes
1answer
237 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 ...
6
votes
1answer
170 views

Preventing line break at the start of a long name in `\lstinline`

This question has developed from How to deal with very long lstinline-phrases like long class names?. That question is about line breaking inside a \lstinline phrase. I have provided an answer which ...
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 ...
-1
votes
0answers
35 views

Listing using java problem with reference

\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
38 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 ...
4
votes
2answers
1k views

Undesirable highlighting of a keyword name (dh) occuring within an identifier (0dh)

I'm using the x86masm dialect of Assembler and register names are emphasized even when they occur inside of a label or a hexadecimal number. For example, dh is register, but 0dh is a number, yet the ...
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
19 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 ...
6
votes
1answer
10k views

Problem with special characters in listings

I'm having problems with my TeX document. I'm trying to import my java file in listings to get syntax colouring and stuff. My java files contains comments in Danish, which means they contain special ...
1
vote
1answer
41 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: ...
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
45 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 ...
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
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
97 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 ...
24
votes
5answers
14k views

Using \ttfamily with \bfseries (or how to enable bold in fixed-width font)

I'm using listings package, and I've added basicstyle=\ttfamily\footnotesize. However, when I do that, the keywords from the embedded source-code are not bold anymore. I figured that \ttfamily ...
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 ...
1
vote
1answer
38 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
582 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 ...
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} ...
4
votes
1answer
43 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
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
59 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
88 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 ...
2
votes
2answers
41 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
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
33 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{ ...