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
0 votes
0 answers
15 views

Highlighting a Keyword with a Red Rectangle in listings Environment (XML Language)

How can I highlight the keyword myINSTRUMENT with a red rectangle inside a listings environment (using language=xml)? Please see below MY CODE, MY OUTPUT and MY DESIRED OUTPUT. MY CODE: \documentclass{...
Marco Moldenhauer's user avatar
1 vote
1 answer
14 views

how to make the caption showup without caption text in `lstlisting` environment?

I found that only the non-empty caption text make the caption appear in outputed file, even a sapce character \ . Here's an example: \documentclass{article} \usepackage{listings} \lstset{ language=...
On_My_Way's user avatar
0 votes
0 answers
24 views

lstlisting and tcolorbox - line numbers margin

I want to get my code look something like this: but I have problems with the line number position, it's on the box line. \documentclass{scrartcl} \usepackage[a4paper,top=2cm,bottom=3cm,left=3cm,...
sp8cky's user avatar
  • 53
0 votes
0 answers
37 views

Is there any way to use code in lstlisting with utf8 characters?

I have code embedded in LaTeX containing a UTF-8 character like a greek letter. In many modern languages this is perfectly legal, but LaTeX hates it. is there any way to include a source code file and ...
Dov's user avatar
  • 1,481
0 votes
1 answer
63 views

From listing 1. to 1. listing in \autoref of a lstlisting

I'm using listings to display code in my document, and all is okay, or I was able to find a solution, except for one problem. When I autoref a listing, it references as "listing 1." in the ...
meszolym's user avatar
0 votes
1 answer
32 views

Highlighting on lists of strings and lists of numbers in a listing

I am following the format used by this answer to color a json listing on my document, but I noticed that in a list of strings and a list of numbers, only the first element gets colored properly. Is ...
nottelling's user avatar
1 vote
1 answer
32 views

Code listing with Title above it?

I recently checked one of my Professor's tests and saw that his questions involved some code blocks that that have title for it, with a box surrounding it and horizontal lines that do not extend to ...
Juan De Castro's user avatar
0 votes
0 answers
16 views

multiple lstlisting for commands and outputs [duplicate]

I wanted to have some commands and outputs in my document. Is it possible to have two seperate lstlistings? The command would be: \begin{lstlisting}[language=cl, caption = Command Caption, label=...
MSH's user avatar
  • 101
1 vote
0 answers
43 views

Coloring functions, methods and attributes automatically in lstlisting

I am currently working on some materials for my CS classes and since I work in VSCode my goal would be being able to reproduce the color theme used in VSCode faithfully in LaTeX. For that I have ...
b00n heT's user avatar
  • 166
1 vote
0 answers
65 views

tcolorbox locally change color of text in a code block

I've been working with \tcolorbox for a bit to get the desired output of my code blocks, see below for an example: and code: \documentclass[12pt]{report} \usepackage[letterpaper,margin=1in]{geometry}...
Matteo's user avatar
  • 163
0 votes
0 answers
14 views

Text overfull in listing

I'm encountering an overfull hbox issue with my LaTeX listings, and I need some assistance in resolving it. Here's a brief overview of my problem: Issue: When I include code listings in my LaTeX ...
sienimies7's user avatar
0 votes
0 answers
50 views

unknown issue with tcolorbox bash code

Hi there I've been recently, thanks to the help received in this post, updated all my code blocks to a much nicer and neat view using tcolorbox. Unfortunately, for some reason, two of them show the ...
Matteo's user avatar
  • 163
1 vote
1 answer
38 views

suppress Listing: # in code blocks with tcolorbox

Hi there I've been recently experimenting with code blocks in LaTex and I had the need to have my code blocks with captions and a label to catch them once clicked on the appropriate link in the ...
Matteo's user avatar
  • 163
0 votes
0 answers
23 views

Strange alignment in declarations with listing for JavaScript code [duplicate]

I'm trying to fine-tune my listing style for JavaScript and I can't understand why: Declarations like "let b = a+1;" shows like "let b =a+1;", so the space after the '=' symbol is ...
alescavo's user avatar
1 vote
2 answers
35 views

How to ignore some indentations or not to display indentation symbols in showexpl LTXexample?

Sorry for the basic question. I'm practicing how to use circuitikz, meanwhile I want to show the process of code and output. For the elegant of LaTeX source code in pdf what I want to do is to ignore ...
Jason Haynes's user avatar
1 vote
1 answer
38 views

Passing arguments to lstinputlisting using pgfkeys

I am writing a macro to put code and a figure side by side. There are three relevant files: main.tex, figure.tex, and ch1.tex. main.tex is roughly this: ... \usepackage{listings} ... \lstdefinestyle{...
onlycparra's user avatar
1 vote
1 answer
41 views

Can the space between elements of the "List of Listings" be changed, so that appears like table of figures/tables?

When adding the 'List of Listings' to the Table of Contents (as shown in the image where I have customized the title), I noticed that there was no space between the list elements when the chapter ...
Gvnn's user avatar
  • 13
4 votes
1 answer
137 views

How do I penalize an orphan brace in a code listing?

I want to prevent my code listing and my tcolorbox from page breaking and placing only a single brace on the next page. See the image for an example of this. The page break in and of itself is fine ...
TheProgrammer's user avatar
1 vote
0 answers
50 views

Copy code from lstlisting excluding line number

I have this latex code \documentclass{article} \usepackage[lmargin=2.5cm,rmargin=2.5cm,tmargin=1.5cm,bmargin=3.5cm]{geometry} \usepackage{listings} % Environment meant for source code (useful for ...
user69507's user avatar
7 votes
4 answers
304 views

LaTeX listings package: SQL comments defined by '--'

I am not able to both Change the color of comments marked by --, AND DO NOT replace hyphens (-) by the minus (−) sign. A MRE follows. \documentclass{report} \usepackage{xcolor} \usepackage{listings}...
Esteban Zimanyi's user avatar
0 votes
0 answers
54 views

v-type argument in \NewDocumentCommand ignores spaces

Consider the following code: \documentclass{article} \usepackage{listings} \NewDocumentCommand{\hey}{v}{\lstinline|#1|\ignorespaces} \begin{document} \hey|a |b \lstinline|a |b \end{document} Why ...
Gargantuar's user avatar
2 votes
1 answer
93 views

Hiding python comments with Listings

I want to include Python code to be formatted with listings but I just want the code neat and compact. No comments shall be printed at all, as well as no empty lines. The easy way would be to strip ...
Kyordhel's user avatar
  • 127
0 votes
1 answer
30 views

How can I redefine the style of the \lstlistoflistings title?

I am using a cls based on memoir and the package listings. I want an appendix chapter with all the lists (list of tables, list of figures, list of listings). The title style of these lists should be ...
Maoristirn's user avatar
0 votes
1 answer
31 views

lyx/latex adds the space symbol (␣) in the generated pdf file when importing some python code

I'm writing a document with lyx and I discovered that for a particular piece of python code, the pdf generated by lyx contains the "␣" instead of a space. Here the code: \documentclass[...
devnull's user avatar
1 vote
0 answers
45 views

What causes much emptiness at the right side of codeblocks?

I am trying to fill the codeblocks to almost all page as symmetrical as possible but something off with regular text and codeblocks placement to the page: Snippets from my code: \documentclass[12pt]{...
dev0023's user avatar
  • 11
4 votes
1 answer
74 views

Custom numberstyle for lines that are \ref'ed in a listing environment

Consider the following MWE: \documentclass{article} \usepackage{tikz} \usepackage{listings} \lstset{% basicstyle =\ttfamily, language = Python, keywordstyle = \bfseries, commentstyle = \...
cjorssen's user avatar
  • 10k
0 votes
1 answer
49 views

Compile LaTeX code in verbatim/lstlisting

For a presentation (in beamer) with the topic How to use LaTeX for your thesis at my university, I wanted to add lots of LaTeX code snippets and compile them. At the moment, I have a separate .tex ...
Gargantuar's user avatar
1 vote
1 answer
41 views

Is there a way to define a separate listings escape sequence?

MWE: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{ basicstyle=\small\sffamily, frame=tb, columns=fullflexible, escapeinside={`}{`}, escapebegin={\color{darkgray}\...
user41177's user avatar
  • 375
2 votes
2 answers
79 views

How to wrap rounded tcolorbox around lstinline?

I would like to have boxes around \lstinline. From another question I found the \xpretocmd trick with \Colorbox, but I cannot manage to apply it with \tcbox. Is there a way? \documentclass{article} \...
nowox's user avatar
  • 1,375
1 vote
1 answer
43 views

Spurious newline inserted by lstlisting when using the font BQN386 [duplicate]

I have a listing rendering problem with source code from the BQN programming language. I use lualatex (LuaHBTeX, Version 1.17.0 (TeX Live 2023)). I tested various fonts and the result is the same. The ...
Ludovic Kuty's user avatar
3 votes
1 answer
69 views

Color a single listings comment delimiter (shell transcript language style)?

I've wanted to have a sort of a shell transcript language style in with listings, where the shell prompt and actual commands are emphasized, and the rest of the text is a bit "muted". Best I ...
sdbbs's user avatar
  • 245
3 votes
1 answer
42 views

How to make left line of "lstlisting" block solid in the "acmart" document?

This is the code: \documentclass{acmart} \usepackage{listings} \begin{document} \begin{lstlisting}[frame=leftline] Hello, world! \end{lstlisting} \end{document} This is how it looks: Is it possible ...
yegor256's user avatar
  • 12.1k
1 vote
2 answers
37 views

Using \leftskip as xleftmargin

I am typesetting text with varying leftskip (some sections of the text are indented to the right). For some reason, listings does not take leftskip into account by default. However it has a ...
ysalmon's user avatar
  • 1,160
2 votes
1 answer
54 views

Mix of normal and darken tikz blend mode

I am trying to figure out how to highlight some part of the source code in the lstlisting environment in a Beamer presentation without affecting the syntax highlighting and spacing. The background ...
Daniel Langr's user avatar
1 vote
0 answers
30 views

Making lstinline make line break at any character (letters, digits, ...)

I have special data I want to include via lstinline into a floating text. The main problem is that the data does not contain certain characters you could define a line break on (like space, dot, dash, ...
Robert's user avatar
  • 652
0 votes
0 answers
36 views

Put code snippets in a rounded gray frame?

I would like to highlight code snippets in a grayish background with a rounded frame. I can achieve this partially with mdframed, but the caption is inside the frame. I also tried with codebox with: \...
nowox's user avatar
  • 1,375
2 votes
1 answer
59 views

Is there a way to format listings comments so that they are right-aligned & appear with a different symbol?

This post, defines a comment command which can be used via escape strings. Is there a way to get a defined comment string to be reformatted in the pdf output somehow? For example would it be possible ...
user41177's user avatar
  • 375
0 votes
0 answers
47 views

Problem in setting list reference

\documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[caption={Some Java code},label={lst:label},language=Java] // Code... \end{lstlisting} \begin{lstlisting}[caption={ ...
sara lee's user avatar
1 vote
1 answer
65 views

Huge white space problem after Solidity code: Package xcolor warning: Incompatible color definition on input line 73. Infinite glue shrinkage

I was using the Xcolor package in my latex document, but then I commented and even removed it, but I am still getting the Xcolor problem. I think its stored in the binary version of my document. Now I ...
user2994783's user avatar
0 votes
0 answers
31 views

Character Grid in Verbatim/Listing/Etc

I have a block of text in a framed listing. I want to draw a faint grid over the listing such that each character in the listing occupies a grid square. Is there a way to do this without more-or-less ...
Duncan W's user avatar
  • 101
1 vote
1 answer
97 views

Python code in two-column document

I want to put my python code in a two-column document. I am using the listings package with the following preamble: \usepackage{listings} \usepackage{xcolor} \definecolor{codegreen}{rgb}{0,0.6,0} \...
curious_direwolf's user avatar
0 votes
1 answer
28 views

How to get rid of the unwanted control information in Solidity listing displayed as figure

I am using dissertation template. Following is the link: https://www.overleaf.com/read/yyjwyqtvzfwt#ef4aff Can anybody get access to all my documents using the above link? I am trying to represent the ...
user2994783's user avatar
0 votes
1 answer
49 views

The listings package compilation

Hello Stack Exchangers I have been facing a problem in the successful compilation of the listings package's LaTeX Macros (.dtx) file into the local directory. The intention is not only to use the sty ...
alphabounce_1228's user avatar
0 votes
0 answers
56 views

Problem with lstlisting and LaTeX3 for exercises repository

First of all, sorry by the size of my MWE, I didnt know how to do it smaller. I was developing some kind of repository of questions for my classes. My purpose is to show one exercise in a pdf document ...
Lev's user avatar
  • 145
0 votes
1 answer
62 views

listing with background color broken with maths equation

This is a similar question to listings with background color and mathescape broken. Here is my code: \documentclass{article} \usepackage{graphicx} % Required for inserting images \usepackage{listings} ...
liaoming999's user avatar
1 vote
0 answers
23 views

How do I allow automatic page breaks within a listing?

I have some code inside tcolorbox environments defined by lstlistings, and I want to be able to have a listing automatically page break to avoid so much vertical space at the bottom after a listing. I'...
TheProgrammer's user avatar
0 votes
0 answers
35 views

Insert code source with listings and problem with special french characters [duplicate]

I'm having a problem using listings. Everything works fine until I want to insert special French characters such as é or è. From that moment on, I get an error message. However, I had specified in my ...
Alejd's user avatar
  • 1
1 vote
0 answers
61 views

Convertig latex to docx using pandoc

as a latex newbie I converted latex file via pandoc to docx. Itemized list with items a), b), etc. appears correctly in pdf but in docx it appears as bullet list. I tried different workarounds but ...
Thorsten_H64's user avatar
3 votes
1 answer
60 views

Trying to apply two different caption styles using \caption, but the styles won't get applied

Below is my full LaTeX document. My goal is to create two different caption styles. One style for the caption for the programming blocks (created with listings), where above the programming block, a ...
 kyarudata's user avatar
5 votes
1 answer
99 views

Create File Path for Listing with Macro based on Arguments

I am trying to make a macro that creates the path to a file from which a listing should be loaded based on its parameters. This fails very early. Here is a schematic of what I am trying to do: \...
Thomas Weise's user avatar

1
2 3 4 5
71