Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
50 views

Listings: overloaded use of dash

In my language, I use the dash character - in three different contexts. As an operator, e.g., 5 - 1. As a minus sign, e.g., -10. As part of a keyword, e.g., some-keyword. I would like to have a ...
user avatar
  • 328
0 votes
1 answer
27 views

Word count stops functioning when $ character in lstlisting

I'm trying to have a lstlisting inside a longlisting, with some bash code. The bash code however ruins the word count function. The listing code is here: \begin{longlisting} \centering \begin{...
user avatar
  • 103
3 votes
2 answers
261 views

ů ř do not appear in the listings

How to include ů and ř to the listings, please? \documentclass[12pt,a4paper]{article} \begin{filecontents*}[overwrite]{myscript.txt} script.txt # hello í ů ř á hello \end{filecontents*} \usepackage{...
user avatar
  • 125
0 votes
2 answers
51 views

expand macro before using as param for listing in newcommand

I wanted to create a parametrized macro (using newcommand) for my listings: It works as long as I use text as input parameter. Once I switch to macros as parameter it doesn't work. I have the ...
user avatar
  • 207
1 vote
1 answer
48 views

A case of code plot in C++

I am entering some C++ files inside my LateX main.tex, and it appears that LateX "writes" the space symbol when there's a space in a string inside listing. (I am using listingsutf8 package) ...
user avatar
3 votes
1 answer
218 views

How can I write letters like ř, í, á to listings?

How can I write letters like ř, í, á to listings? Why is zero in the name of the section? \documentclass[12pt,a4paper]{report} \usepackage[total={7in, 9in}]{geometry} \usepackage{enumitem} \usepackage[...
user avatar
  • 125
2 votes
1 answer
94 views

Verbatim/Lstlisting environment with background color highlighting

Use case: Currently we are reporting security findings using MS Word. These findings contain large parts of code snippets, command outputs and HTML code. We highlight relevant parts of this code so ...
user avatar
0 votes
0 answers
29 views

Long CSV line not looping to next line

I have a problem with the lstdefinestyle. I'm not able to find a solution on why a long CSV line isn't looping to the next line. I have a basic lstdefinestyle that I've defined but I've also used ...
user avatar
0 votes
1 answer
41 views

Change reference name of listing

I would like to reference the listing like Codebeispiel 1. How can I do that? What I got is only ?? 1 \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{blindtext} \usepackage{titlesec} \...
user avatar
2 votes
1 answer
63 views

Listings + Tcolorbox page break resets color

I want to have a lstlisting environment in a tcolorbox. The problem is when there is a page break, with breakable, the colour component of the listings option basicstyle is reset after the page break, ...
user avatar
  • 3,566
0 votes
1 answer
31 views

Force line break on url in listings

I want to list some python code in a file, but I have the problem, that url's are not getting split properly, line break does not seem to work for them. Also, how can I remove the word 'file' from ...
user avatar
  • 201
1 vote
1 answer
42 views

Why is there a side effect of using `breaklines=true` inside longtable on the adjacent cell?

I noticed using breaklines=true option for lstlisting in one cell in a table, causes the text in the next cell in the same table row to shift down a little, even though the next cell does not use ...
user avatar
  • 18.1k
1 vote
2 answers
50 views

`\Block` does not accept `\lstinline`

I would like to typeset verbatim style commands from \lstinline in \Block command, but it does not seem to work \documentclass[a4paper,12pt]{article} \usepackage{nicematrix} \usepackage{listings} \...
user avatar
1 vote
1 answer
31 views

Listings show Quotation marks in italic - how to print them in Regular?

I use the listings package for showing source code. I just realized, that double and single quotation marks are printed in italic - they should be printed in regular instead ... Where is the issue? Is ...
user avatar
  • 151
0 votes
1 answer
45 views

How can I use \lstdefinestyle in a subfile?

Assume that main.tex is my main compiled latex file. The rest of them (as sub.tex) includes the list of def ones in order to arrange each chapter, subchapter etc. How can I use defined style in main....
user avatar
  • 160
0 votes
0 answers
48 views

How to get `\section` command to accept verbatim text with '\' inside it?

I am trying to define a verbatim style for LaTeX \lstdefinestyle{verbatim}{basicstyle=\ttfamily,language={[LaTeX]TeX}} Then I use the following command to typeset LaTeX commands as they appear in ...
user avatar
0 votes
0 answers
10 views

Redefine \lstinline{code} as \Colorbox{yellow}{\lstinline{code}} [duplicate]

I'm writing a cheat sheet where I'm using \lstinline{} for inline code. I want to highlight every inline code. I found a solution that I need to use \Colorbox{yellow}{\lstinline{code}} to highlight it....
user avatar
1 vote
2 answers
36 views

Tilda ups when use code cpp snippets

I use C++ code snippets with latex. I try to use verbatim, lstlisting and minted(imho which is the most beautiful). But they has one trouble. When I want to write code p->~T() I get tilda at the ...
user avatar
  • 113
1 vote
1 answer
31 views

listings package doesn't render brackets correctly

I'm trying to list some code using the listings package, however if use ttfamily font, brackets don't render correctly. This is what it looks like
user avatar
1 vote
1 answer
32 views

Remove emphasized spaces on lstlisting with bash

I have the following code that prints my bash code on the document \begin{lstlisting}[language=bash, caption=Comandi per l'installazione dell'engine di Docker,captionpos=b] $ sudo apt-get update $ ...
user avatar
  • 125
2 votes
0 answers
24 views

Remove spacing around lstlisting in beamer blocks

Consider the lstlisting in this MWE. (I have added normal text and itemize environment blocks for comparison.) \documentclass{beamer} \usetheme{Warsaw} \usepackage{listings} \begin{document} %\...
user avatar
0 votes
1 answer
40 views

Listing inside align environment doesn't work

I found a very specific formatting error: when I use lstinline[mathescape] inside an align environment, some of the basic math formatting like subscripting stops working. It does however work in e.g., ...
user avatar
  • 328
0 votes
0 answers
25 views

listings : How to parse character sequences into math symbols

I'm trying to format code snippets using listings. The language I'm targeting (typed template Haskell) features the equivalent of double square brackets brackets [|| and ||]. These look quite poorly ...
user avatar
  • 101
0 votes
1 answer
95 views

Put \lstinline inside \chapter, \section, etc. commands

How can I place \lstinline code inside commands like \chapter, \section, \subsection, etc.? Or it's a bad or tasteless practice?
user avatar
2 votes
0 answers
66 views

Put \lstinline inside a \item and automatically add \item content to glossary

I've implemented this solution to allow placing \lstinline code inside description \item command. I also want to automatically add the entire \item content as a glossary entry by placing it into name ...
user avatar
0 votes
0 answers
23 views

Highlight \lstinline, make it work with backtics

I have 2 related questions. In short, I want to make inline code snippets like in markdown: int c = 4;. The questions are: how to highlight text inside \lstinline (gray background)? is it possible to ...
user avatar
0 votes
1 answer
120 views

Indentation problem with wrapfigure and listings

I am having a problem with some indentation of paragraphs when displaying an image next to a block of lstlisting. I am using Overleaf online (and have found several weird quirks previously). Below is ...
user avatar
  • 1
0 votes
0 answers
15 views

How to make listings package recognize strings of a specific form

The listing package provides literate command which allows replacing specific fragments of code with something else, like: literate={)}{{\textcolor{red}{)}}}{1} replaces the right bracket with its ...
user avatar
  • 1,510
1 vote
2 answers
32 views

Set vertical spacing of custom new environments

I defined a code environment in which minted environments are put in order to span in multiple pages. The problem is that captions are too close to the text next to the code frames. How can I increase ...
user avatar
1 vote
1 answer
81 views

How can I add additional spacing between some lines in `minted`?

I would like to add a little separation between some lines of code for readibility. Consider this MWE: \documentclass{article} \usepackage{minted} \begin{document} \begin{minted}[linenos]{python} ...
user avatar
  • 595
0 votes
1 answer
48 views

Listing too wide for colour box

I have the Latex code below to represent listings of C++ code, however the C++ code seems to be too wide for the greyed out box in the background. I would also like the listing too fit as it was ...
user avatar
0 votes
0 answers
130 views

Compilation in TeXworks: "LaTeX Error: File `listings-python.prf' not found."

I'm working on a collaborative LaTeX project. While compiling the pdf with Windows 10 and TeXworks, I noticed this issue: ! LaTeX Error: File `listings-python.prf' not found. Type X to quit or <...
user avatar
0 votes
1 answer
86 views

Custom new environment positioning and margins

How can I place the following custom new environment at the top of every page like figures (options [ht])? \usepackage[newfloat]{minted} \newenvironment{code}{\captionsetup{type=listing}}{} \...
user avatar
0 votes
0 answers
93 views

lstlisting collection of styles

I'm looking for a collection of different styles for the lstlisting package. I know there are some good ones for examples of tikz pictures and templates, but I couldn't find one for lstlistings. Does ...
user avatar
  • 366
6 votes
1 answer
314 views

How to Assign the Numbers Automatically in This Enumerate Environment

Consider \documentclass{book} \usepackage{tcolorbox} \newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners, colframe=black, colback=black, top=4pt, left=5pt, right=...
user avatar
0 votes
1 answer
43 views

\surroundwithmdframed does not sourround \lstinputlisting

I need to surround code listings with a customized gray mdframed. To do this I use the very convenient macro \surroundwithmdframed[options]{environment} to instruct that all lstlisting environments ...
user avatar
  • 1,307
0 votes
0 answers
33 views

Multiple horizontally stacked side-by-side listings

I am using acmart. They define a full-text (two-column) listing environment listing*. If I put multiple minteds inside it, they are stacked vertically. I would like to have them side-by-side. Is that ...
user avatar
  • 141
1 vote
1 answer
38 views

How to add color to numbers in the Listings package?

I am using the Listings package in Lyx. I can change the color of whatever word I want using \lstset{emph={word}} and \lstset{emphstyle={\color{green}}}. However this does not work with numbers. \...
user avatar
  • 11
0 votes
2 answers
101 views

Highlighting code snippet in lstlisting with colorbox changes the character and breaks the border

I am using Texstudio with texlive 2021. To highlight some lines of the following code snippet in lstlisting, I am using colorbox \begin{lstlisting}[style=listing1] |\colorbox{yellow}{...
user avatar
  • 139
1 vote
0 answers
30 views

How to color second words in blue with matlab-prettifier

I'm using the Matlab-prettifier package quite happy with it. Even if it can mimic almost perfectly the Matlab style it just doesn't color second words in blue (like MATLAB does). Somebody know how to ...
user avatar
  • 337
2 votes
1 answer
47 views

How to add text before/to the left of \begin{lstlisting}?

I want to write exercises where the student must explain numbered pieces of code. To the left of each piece of code, I would like to add a letter, like a), or a number. I prefer to use \begin{...
user avatar
  • 21
1 vote
1 answer
25 views

Unable to use listing with toptesi

Everytime I open a new listing the compiler complaints about it. Try to compile the following example % !TEX options = -shell-escape \documentclass[% corpo=12pt, twoside, oldstyle, tipotesi=...
user avatar
1 vote
1 answer
35 views

Why does the page number slightly move its position to the bottom line when a listing code is written on two pages?

I noticed that whenever I add a source code to my latex file, the numbers of the page where the code is added look displaced. I do not know if there is a reason in the listing configuration that ...
user avatar
  • 83
0 votes
1 answer
28 views

How to align reference code?

I want to add reference to my c++ project, but it doesn't seem quite right. The code doesn't has any alignment, and it get cropped with the paper. It look like this: I use this to link my code to ...
user avatar
1 vote
0 answers
52 views

Listings - ignore keyword within String

I'm using Listings, and want keywords to be ignored if they are within Strings. For example, the code in my example highlights if within the String: \documentclass{article} \usepackage{listings} %...
user avatar
  • 125
1 vote
2 answers
41 views

Can't get listings to behave at line endings despite use of breaklines parameter

I'm having trouble with getting listings to behave at line endings and respect the page margins. Consider the following code: \documentclass{article} \usepackage{listings} \usepackage[showframe,margin=...
user avatar
  • 1,382
0 votes
0 answers
39 views

Unusual code listing box that's semi-split

I've been trying to figure out how to get LaTeX to make a rather unusual "code list" box. I was initially looking at the listings package, and then at tcolorbox. (minted also showed up in ...
user avatar
1 vote
1 answer
94 views

Putting a Code to the Right of an Item in a New Enumerate Environment

Consider I would like to present the string of 12 colored bullets a little to the right of the enumerated tcolorbox and vertically centered. The code which produces the above picture is \...
user avatar
  • 4,997
0 votes
1 answer
52 views

No minted listings TOC page break when many listings

I am currently experiencing a problem with the toc for the minted package. I have so many listings, that the toc should split up onto two pages. However it does not do it. Now I need a solution on ...
user avatar
4 votes
1 answer
29 views

Problem when inserting an url inside lstlisting and compiling with make4ht

The following examples shows an error when an URL is inserted inside a lstlisting caption. \documentclass{article} \usepackage{listings} \usepackage{hyperref} \begin{document} \begin{lstlisting}[...
user avatar
  • 656

1 2
3
4 5
69