Skip to main content

Questions tagged [listings]

{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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
88 views

Hack 'minted' definition with NewTCBListing und RenewDocumentEnvironment

A colleague and myself are trying to hack the minted environment by assigning the original meaning to oldminted using \NewEnvironmentCopy and then use this saved version in a redefinition of minted ...
lukeflo's user avatar
  • 1,597
0 votes
1 answer
68 views

Substitute text between delimiters (listings) [closed]

I want to format code within the lstlistings package via \lstdefinestyle. The goal is to substitute the text after the regex 'C:\ up to the regex .eps' with PATH. How can I realize this? The solution ...
FixFox's user avatar
  • 45
2 votes
1 answer
122 views

Caption outside tcolorbox

\begin{tcolorbox} \begin{lstlisting} [caption = {C Code}, captionpos=b, label = {Listing3}, abovecaptionskip=12pt] int a ,b; int value = 20; \end{lstlisting} \end{tcolorbox} I am using the above code ...
sara lee's user avatar
0 votes
1 answer
82 views

Adjusting line break indentation with listings package

I'm using listings package for listing various text tables. I prefer to use this package as the look and feel of text and line numbering is similar to my other code listings. Below is a sample table: \...
Milhouse Vanhouten's user avatar
1 vote
1 answer
25 views

How to Fix spacing that produce weird symbol inside Code Environment?

I want to know why there are weird symbols of spacing like this (at the left side for the GLSL code) : This is the code that you can check and reproduce: \documentclass[twoside]{book} \usepackage{...
Freya the Goddess's user avatar
0 votes
0 answers
23 views

Is it possible to use environments from existing packages when defining my own custom environment? [duplicate]

I'm trying to define a new environment for my own needs, and I'm trying to use the lstlisting environment from the listings package in the definition of my new environment, but whenever I try to ...
Daaaaaaaavid's user avatar
0 votes
1 answer
38 views

How to reference labels within lstlisting?

My code is as follows, and I want to reference a Tikz image within the lstlisting environment instead of it being displayed as is. This kind of situation often arises in code comments. \documentclass{...
licheng's user avatar
  • 795
0 votes
0 answers
17 views

How to define a special escape sequence for a listings block which bold italicizes the text it surrounds?

I currently have a listings set up which uses !> and <! as an escape sequence. The main purpose I use this for is to make the text in a listings stand out by bold-italicizing them when writing ...
user41177's user avatar
  • 375
0 votes
0 answers
21 views

Background for Listings with TeX escape, but caption outside

Listings does not play well with backgrounds and included math formulas (using mathescape) - there are white horizontal lines because Listings doesn't know how tall the lines are meant to be. You can ...
Alasdair's user avatar
  • 5,267
2 votes
1 answer
161 views

How to set monofont to Source Code Pro Light

I would like to know how to go about setting the monofont to Source Code Pro Light. With the code given below, the ttfamily gives this result: This is the code that I currently have: \documentclass{...
Joe's user avatar
  • 9,080
0 votes
0 answers
31 views

Integration of a Jupyter Notebook to Beamer [duplicate]

For my teaching efforts, I want to integrate some Jupyter-Notebooks to my Presentation, which is written in LaTeX. These Notebooks contain examples and assignments. And these examples/assignments I ...
Rivas's user avatar
  • 1
0 votes
0 answers
15 views

Custom lstlisting command changed verbatim font size

I've copied a custom lstlisting command that makes it look like Mathematica code. This is that code below: \usepackage{babel} \usepackage{beramono} \usepackage[T1]{fontenc} \usepackage{color} \...
Michael Adrian Javier's user avatar
1 vote
1 answer
30 views

Issues with making lstnumber two-digit with hyperref and tcolorbox

I'm trying to use tcolorbox and make all lstnumbers two digit. It seems like there is an error with hyperref. I've attached a working example below. \documentclass{scrartcl} \usepackage[utf8]{...
user41177's user avatar
  • 375
2 votes
2 answers
108 views

listings package in tex4ht. How to prevent listing code from wrapping long lines

This issue is for tex4ht only. Summary of the current problem I'd like to make the HTML page smaller width (so easier to read) using say max-width:700px; but at the same time, I do not want to have ...
Nasser's user avatar
  • 20.3k
1 vote
0 answers
33 views

Caption alignment issues with lstlistings environment inside lists

The alignment of the caption of the my lstlistings environment for code is not correct when inside lists. The code to generate the image is given in the working example... \documentclass{article} \...
user41177's user avatar
  • 375
0 votes
1 answer
82 views

How can I restyle the listings caption to a tcblistings environment?

I am trying to define a tcblistings environment that should work under the following syntax... \begin{code}{TITLE}{LANG}{CAPTION}{OPTS} code here \end{code} Everything but the language should be ...
user41177's user avatar
  • 375
0 votes
1 answer
47 views

problem with the trasposition symbol '

I'm new to latex and I should do an assignment with some matlab code. I wrote the latex file but when I make it into pdf there's a problem with the symbol ' which is the symbol of trasposition in ...
federica's user avatar
0 votes
0 answers
38 views

"Issue with Line Breaks in URLs within lstlisting Environment

The line breaks within lstlisting environments do not function properly for URLs, even though breaklines and breakatwhitespace are both set to true. The URLs are not being broken, and the text exceeds ...
anas's user avatar
  • 1
-1 votes
1 answer
118 views

Listing error on overleaf [closed]

I have copied below code in my source file. Code does not appear in proper format(as it is). All text mix up (without any gap). No caption at the bottom. Getting error message "environment ...
pian ke's user avatar
3 votes
1 answer
46 views

How do I cross reference an equation in lstlisting?

Suppose we have the following code: \documentclass[reqno]{amsart} \usepackage{geometry} \geometry{margin=2in,top=3cm} \usepackage{microtype} \usepackage{listings} \usepackage{hyperref} \begin{...
Arbuja's user avatar
  • 251
0 votes
0 answers
22 views

How to load keywords from two languages in lstlisting? [duplicate]

I know how to define two different styles for two different languages in lstlisting package. I want to include keywords from Lua as well as LaTeX in the same style. Is it possible? \lstdefinestyle{...
user61681's user avatar
  • 1,769
0 votes
0 answers
81 views

lstlisting: Configuring it to support Julia type code

I was writing my report, which uses notations from Julia, specifically Catlab.jl. This contains a lot of category theory related symbols. I read the documentation for lstlisting and it does not ...
Nikit's user avatar
  • 1
0 votes
0 answers
37 views

Prevent LaTeX listings from line breaking before comas and dots

I have a PostgreSQL script that I insert in article using the listings package and I constantly run into two problems trying to format the style of the code: Line breaks before dots and comas or ...
Tristan Benoit's user avatar
0 votes
0 answers
33 views

latexdiff produces non-compilable file in presence of \lstMakeShortInline

I'm using latexdiff on a file that uses the listings package, and more specifically its lstMakeShortInline macro, that allows writing inline code in a concise way. If I start with the following orig....
Virgile's user avatar
  • 235
1 vote
0 answers
72 views

Wrapping inserted code from MATLAB

I am attempting to insert a very long code that I wrote in MATLAB into my thesis document written on Overleaf. Several of the lines have long equations or comments that extend beyond the page and I ...
Jah's user avatar
  • 11
0 votes
2 answers
162 views

How to fix spacing after multicols with lstlisting?

When combining lstlisting with multicols inside a minipage or tcolorbox, the vertical spacing of lstlisting changes. The spacing on top can be fixed by using \topskip = 0pt (see this answer with a ...
Sam's user avatar
  • 310
0 votes
0 answers
45 views

How to get the specific line on LATEX to show properly for copy and pasting?

How can I show this line properly for my Latex document? I am trying to put in code statements but when I try to copy from LATEX and post in the terminal, it does not paste the whole line. The code ...
NevMthw's user avatar
1 vote
0 answers
31 views

How to set program outcomes like listings and algorithms

I have the following settings for the listing package and need to print program outcomes in the same manner, but with its own numbering and removing "Listing" in a caption), i.e., "...
vua72's user avatar
  • 11
1 vote
1 answer
48 views

Using lstinputlisting with tex4ht hides all ASCII characters in the caption?

I'm using tex4ht to build my LaTex source to EPUB. Currently I'm having problems with lstinputlisting, where the caption (in Vietnamese) isn't showing up correctly. \lstinputlisting[float,language=C++,...
Giang's user avatar
  • 13
0 votes
0 answers
30 views

How to print quotation mark glyphs inside the verbatim, minted, listings & texttt?

Assuming the desired quotation marks in the code are called glyphs, how to print the left & the right quotes as desired, as it's printed in `monster' inside the verbatim, minted, listings ...
Lars Malmsteen's user avatar
4 votes
1 answer
2k views

Does lstlisting support Rust?

When I define the Rust language in TeX Live 2023’s lstlisting like this: \begin{lstlisting}[language=Rust] let config_redis_string: String = env::var("REDIS_URL").expect("redis url ...
Dolphin's user avatar
  • 895
1 vote
1 answer
83 views

Cannot List documentclass Using the Listings Package

I'm using XeLaTeX and Overleaf as my editor. I want to use the listings package to list my LaTeX codes. I can properly list most normal codes using the my style below, but when I try to list some ...
E. Huang's user avatar
  • 201
2 votes
0 answers
211 views

Argument of � has an extra } error from listings + hyperref

I'm merging two previously working documents and came across this error (several instances of it, actually). I've reduced it into the following MWE, and it seems to be caused by some interaction ...
bruno cuconato's user avatar
1 vote
1 answer
175 views

color of string in lstdefinelanguage

I have a latex document like this, where I define my own lstlsting language: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \definecolor{backcolour}{rgb}{0.95,0.95,0.92} \...
Maarten-vd-Sande's user avatar
0 votes
2 answers
158 views

How to mix markup for straight apostrophes and accented letters in a lstlisting environment?

I have a document, formatted with luatex, beginning \documentclass[b4paper]{article} \usepackage{expl3} \usepackage{hyperref} \usepackage{listings} %Requires luatex engine to handle UTF-8 ...
shmuel's user avatar
  • 1,459
8 votes
1 answer
198 views

Creating a `regex` language for listings

A coworker is currently writing a long document with a focus on regular expressions. We would like to be able to format the regular expressions as a listings language, with syntax highlighting and ...
olirwin's user avatar
  • 295
0 votes
0 answers
44 views

How can I make an \if conditional reusable?

This is related to a previous question of mine, how to use listings in conditionals. I'm using the answer kindly provided there to include different code snippets when their library of origin is ...
serval's user avatar
  • 107
2 votes
1 answer
80 views

How can I use listings in conditionals?

I have a library that contains code snippets formatted with the listings package. This library is used in two different documents, with slight variations depending on the document. I've been using ...
serval's user avatar
  • 107
1 vote
2 answers
174 views

Undefined control sequence. \begin{lstlisting} when using custom cls file

when I compile this document in texstudio using xelatex: \documentclass{dolphinbook} \usepackage{xeCJK} \usepackage{subfiles} \usepackage{listings} \usepackage[bookmarksopen,bookmarksdepth=4]{...
Dolphin's user avatar
  • 895
2 votes
0 answers
51 views

Set Python's decorators in some colour but keep @ as an operator unchanged

I am using listings for code formatting and colouring in a document I'm working on, including a lot of Python code. I would like for decorators to be displayed in a specific colour but for the @ ...
Bermudes's user avatar
  • 121
0 votes
0 answers
18 views

Custom font size for listing [duplicate]

I have a listing as follows: \begin{lstlisting}[basicstyle=\scriptsize] ... \end{lstlisting} The listing is quite long (71 lines + caption), and I want it to fit on a single page. However, I ...
bys1's user avatar
  • 1
1 vote
1 answer
60 views

\lstnewenvironment does not work with \minipage

I am writing a document with loads of code snippets, and page breaks make it hard to read. I would like to prevent those if possible. I saw in Avoid page breaks in \lstlistings that one of the ...
Aisteru Firë's user avatar
0 votes
1 answer
35 views

How do I change the formatting of listing captions to follow the structure of figure/table captions?

I need to add a lot of listing environments to a report, and I want to have the numbering of the listing captions to follow the same structure as the captions of figures or tables (eg Listing 1.1, ...
sg37's user avatar
  • 13
0 votes
1 answer
64 views

Error between microtype, hyperref, and listings when setting oldstylenums for listings

I am using the listings package for displaying source code, and want to reformat the numbering to use the oldstylenums. The problem comes when using microtype, as it throws errors for every line of ...
asbjos's user avatar
  • 43
0 votes
1 answer
204 views

Justify text lstlisting

I would like to justify text in lstlisting. If the line gets too long, there doesn't seem to be any way to automatically add a new line. Is there a way to justify text?
Dunno's user avatar
  • 329
0 votes
0 answers
37 views

In lstlisting, how to forbid the upper/lower frame bars on another page?

Running pdflatex on \documentclass{article} \usepackage{listings} \begin{document} \vspace*{121ex}% writing 122ex instead of 121ex leads to breaking just after the upper bar. \begin{lstlisting}[frame=...
user avatar
0 votes
1 answer
26 views

The listings package is rendering an empty frame

The markup \documentclass[draft]{article} \usepackage{fontspec} \usepackage{hyperref} \usepackage{listings} \begin{document} \lstset{language=Rexx, extendedchars=true, frame=trbl} \section{Statement ...
shmuel's user avatar
  • 1,459
4 votes
1 answer
268 views

Curly brace with arrows pointing to specific code

I would like to use horizontal brackets within a code environment like in the following example: That's as far as what I have. \documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta} \...
wayne's user avatar
  • 685
0 votes
1 answer
87 views

breakline is not working for lstlisting package while none option in hyphenat package used

The below code is the tex file content, which has listings package. \documentclass[12pt,a4paper]{report} \usepackage{hyperref} \usepackage[english]{babel} \usepackage{xcolor} \usepackage{listings} % ...
Nandy's user avatar
  • 33
0 votes
1 answer
48 views

Use arrows to point to specific blocks of code and assign background colors to keywords

How do I get background colors assigned to certain words and punctuation marks? I want it like in the following picture: Here is my code: \documentclass[a4paper]{article} \usepackage{tikz} \...
wayne's user avatar
  • 685

1 2
3
4 5
74