{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

0
votes
1answer
8 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} ...
3
votes
0answers
24 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
68 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
20 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
21 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
37 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
33 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
37 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
23 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
18 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
29 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
31 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
40 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
27 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
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 ...
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
92 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
37 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 ...
3
votes
0answers
43 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 ...
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 ...
5
votes
1answer
77 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 ...
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
230 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
62 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
57 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
30 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
39 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
50 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
47 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
63 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} ...
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
1answer
87 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
17 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
31 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 ...
0
votes
0answers
13 views

Wrapping text in lstset based on number of characters [on hold]

Is there a setting to instruct lstset to break a line of code after exactly n characters? TIA Vinod
4
votes
2answers
73 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 ...