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

Copy paste mistakes while listing code

I have noticed that the lstlisting environment produces many errors that must be corrected if you try to copy-paste the code and compile it. Other environments such as minted produces way fewer errors,...
1 vote
1 answer
131 views

How to write Octave code on LaTeX?

Here is an exemple of code I would like to write: clear all; close all; clc; X = Y = 0:0.1:1; for i=1:length(X) for j=1:length(Y) Z(i, j) = X(i) + Y(j); endfor endfor mesh(Y, X, Z) The ...
1 vote
1 answer
61 views

Space before the "?", normally unbreakable with babel-french, breakable with listings' breaklines option

With babel-french, the space before the question mark is normally unbreakable. But, as shown by the MWE below (compiled with pdflatex, xelatex or lualatex), the breaklines option of the listings ...
0 votes
0 answers
42 views

Replicate eclipse screen for java code

Hi there is a method to replicate the eclipse screen with keyword colors for a java code like this I tried this but it doesn't work \documentclass[a4paper, 11pt]{article} \usepackage{geometry} ...
1 vote
2 answers
34 views

listings does not ignore comment character inside a string

I'm trying to insert a matlab code file in my tex document using listings but the output is messy because I'm using % inside a string with fprintf which is also a comment character. In the line ...
0 votes
1 answer
37 views

Error with `listings` and `tabularray` used together

I'm in the process of replacing tabular and array environments with tblr in some of my documents. It's already done for dozens of them, with no problem. But I hit a bump with the following MWE: \...
1 vote
1 answer
27 views

Only highlight keyword if surrounded by whitespace

I defined a language as follows: \lstdefinelanguage{Z80}{ sensitive = true, keywords={a, hl, h, l, b, c, e, ix, sp, bc, af, d}, keywords = [2]{push, ld, and, pop, ret, sra, call, sla, cp, jp, ...
1 vote
1 answer
19 views

tex4ht does not see listings style using \lstinputlisting[style=style_name]{file}

I am using the code from how to make tex4ht work with listings styles for only basic decoration? (frame and background coloring)? thanks to Michal.h2 which works great except that the style defined ...
1 vote
1 answer
2k views

How to display colors of Octave code in latex with listings?

In my paper I include Octave code with \usepackage{listings} No I want that the text and numbers be written in the same colors as the are represented with in Octave. Everything is fine, except that ...
1 vote
1 answer
32 views

lstlisting stops file from compiling

I'm writing a Latex file. But when I try to add the following code to the file, it just can't compile anymore: \begin{lstlisting}[language=bash,caption={bash version}] btcd --txindex --simnet --...
1 vote
1 answer
23 views

How to use two styles for the same listings language?

At the moment I have two global options defined for my listings language: color and monochrome (I have bundled the language as a package and so these are package options). However, now I find that I ...
0 votes
0 answers
33 views

\lstMakeShortInline fails with some characters when luatex-ja and microtype are involved

The following MCE example: \documentclass{article} \usepackage{listings} \usepackage{luatexja-fontspec} \usepackage{microtype} \lstMakeShortInline! \begin{document} Foo !\foo! \fontspec{Latin Modern ...
0 votes
0 answers
19 views

autoref figure labels in tufte-book

This seems to be an issue with tufte-book figure labeling but I'm not sure whether it's something I can work around. \documentclass{tufte-book} \usepackage{listings}\lstloadlanguages{C} \usepackage{...
0 votes
1 answer
50 views

Conflict of between powerdot and listings packages

Please see my previous question: Conflict of \item indexes and \onslide in powerdot Playing with powerdot presentations, I realized one more awkward behavior. When listings package is in effect, \...
0 votes
1 answer
21 views

Listing moredelim producing double delimiters

I am trying to use the hack to highlight code between (but not including) two delimiters discussed in this question, but I am producing duplicate delimiters. My goal is to highlight in orange ...
0 votes
0 answers
331 views

How to include a caption to a Python code snippet

I am using a self-defined command to create an environment for my Python code that I want to show in my document. This command has been taken from redmode's answer to the following question: here. So, ...
0 votes
1 answer
26 views

How can I remove extra white space of a caption when listing wrap inside a figure?

I want to wrap listing inside a figure. But when I do that there is plent white space in between its caption. How can I remove extra white space of Figure's caption when listing wrap inside a figure? ...
1 vote
1 answer
185 views

How can I manually add italics or underlines to code listings using minted?

I'm a new user of minted, and I have a LaTeX fragment that looks like this: \begin{minted}{python} `s` = input(`prompt`) \end{minted} I was previously using the listings package: \begin{lstlisting} `...
0 votes
1 answer
44 views

How to render a long code listing in multiple pages with the package minted?

I'm using the package minted for formatting code in my paper. The package minted provides a "listing" environment, which treats the code inside it as a float. It works very well under most ...
0 votes
0 answers
23 views

nested use of listing options

The following code which is built by the lstlisting environment from the package listings, in my view, should typeset the text "aaa" with color red, but the real typeset remains black. I ...
1 vote
0 answers
49 views

<replace> of “literate” option still on in tcblisting environment of tcolorbox

I set @ and | as <replace> of the literate option(from the package listings), and use it in tcblisting(from tocolorbox). They work all right except that in the text part of tcblisting, @ and | ...
0 votes
1 answer
42 views

Syntax highlighting of numeric literals with the listings package

I'm working on a document that contains a lot of python code snippets, many of which have numeric literals in them. For example, something like: var_a = 3 var_b = 20000 var_c = 1.75e12 var_d = 0.1415 ...
0 votes
1 answer
39 views

Blank space after equal-sign in Python-Code-Section of LaTeX-Dokument-PDF by using packages "listings" and "pythonhighlight"

Does anybody know how to set the packages "listings" and "pythonhighlight" for displaying one blank space before (this already works) and after an "=" (and maybe other ...
9 votes
3 answers
23k views

Syntax highlighting in listings for C# that it looks like in Visual Studio

Community, I want to get my C# listings syntax highlighted like in Visual Studio but I did not get it so far. Here's an image of the syntax highlighting of Visual Studio: Here is the code I have: \...
1 vote
1 answer
29 views

listings lstdefinestyle not work with custom defined command

I defined a new command named '\showLineNo', and used in '\lstdefinestyle', got an error: Package Listings Error: Numbers none unknown. \lstset{style=customstyleone} sample code: \documentclass{...
2 votes
0 answers
29 views

Changing the color of numbers and special words in listings for a Python snippet

I'm using the listings package to write a report where I report some code in Python that I used. I am not very familiar with listings and am having several problems. Specifically: I would like to ...
2 votes
1 answer
178 views

Multicol listings and ntheorem rendering wrong

Given the quite long MWE: \documentclass{memoir} \usepackage[dvipsnames,table]{xcolor} %\usepackage[showframe]{geometry} \usepackage{mathtools} \usepackage{needspace} \usepackage{multido} \usepackage{...
0 votes
0 answers
28 views

emphstyle in listings

The following code comes from the manuel of package listings in which I add a "backslash" before "square" and "\color{red}" before "\underbar" in the first ...
1 vote
1 answer
26 views

Strange Autoref Countering of lstlisting

I made a new listtype called mycodes and want to autoref to them. The problem is, when using autoref to a lstlisting-block the number of the listing is wrong! The code \documentclass[]{article} \...
0 votes
1 answer
120 views

LstListing caption number setting

I am using \package{lstlisting} to display some matlab code in the latex. My codes are placed in the appendix with labels. Given below is excerpt of my code: % block of codes \clearpage \appendix ...
0 votes
0 answers
23 views

Page break in LaTeX only if a code block is split between pages

I'm writing a report in LaTeX that contains several code blocks of varying sizes. For example, a code block might be: \begin{lstlisting}[language=Python] dic = { "qwe": 0.2, ...
1 vote
1 answer
169 views

How do I customize Circuit_macros in listings?

MWE: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \definecolor{Others}{RGB}{0,110,40} % Green \definecolor{Character}{RGB}{146,76,157} % Purple \definecolor{Number}{RGB}{176,...
0 votes
0 answers
22 views

Increasing `minted` spacing

I've been switching my code environments from lstlistings to minted. However, in the process of switching, I noticed that all minted environments used smaller spacing between characters (the font ...
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....
0 votes
1 answer
235 views

How can I add code highlighting for listings with different colour lines?

How can I create a listing design in LaTeX, with numbers on the left, and each line separated with colours like in the picture? I could not find such listing style for LaTeX.
2 votes
2 answers
612 views

Custom styles for minted in Overleaf

So I just moved from listings to minted, as listings had super annoying problems with lines showing up when the background color is set to dark. Minted, on the other hand, is annoying as there doesn't ...
3 votes
2 answers
86 views

Listings Inside Macro

I am trying to figure out a way to have a macro where I demonstrate the output of a command then show the command via a lstinline command. I have read that I need to escape out the special char's (...
1 vote
1 answer
33 views

KOMA-script list of listings and LOF have unequal space below heading

I observed some unexpected behaviour with scrbook class (xelatex) and the list of listings from the listings package. The spacing between the chapter headings of the LOF and list of listings and the ...
0 votes
1 answer
28 views

Typeset python setter decorators with the listing package

I'm using the listing package to include my source files (Python) in my documentation but I'm having an issue with highlighting the setter decorators. Decorators such as @property or @dataclass are ...
8 votes
3 answers
6k views

How can I put lstlisting block into subfloat block?

I'm trying to compile my document but it's exploding. I've narrowed it down to this section: \begin{figure}[h] \caption{These are my awesome code snippets} \subfloat[This code runs every cycle.]{ \...
0 votes
0 answers
20 views

Listings Misses Coloring Words

I am trying to use \lstinputlisting to include a .tex file. When I use the \lstinputlisting to do it, the \includegraphics is not colored, however, when I use \lstinline with \includegraphics, it is ...
0 votes
1 answer
17 views

Listing background color is overflowing margins on broken lines

I'm using the code on Listing, zebra effect and broken lines as a base. However, when lines are indented by either spaces or tabs the margins of the listing are not respected and the background color ...
0 votes
1 answer
41 views

Disable LaTeX interpreting my Source File

In my Latex file: \lstinputlisting[caption={Pascal Quellcode HashFunctionsTest.pas}]{../source/HashFunctions.pas} Error: [{ "owner": "LaTeX", "severity": 8, &...
0 votes
1 answer
46 views

Numbering format for listings (lstlisting)

I'm writing a document with a lot of listings ini it. I need to index the listing with the following format: "Listing a.b" with: a the chapter (arabic) and b the order of occurence in that ...
0 votes
0 answers
53 views

Markdown -> Latex -> PDF: md inline code snippets going out of page bounds

Problem I have a bunch of changelog.md files for our software that use backticks for inline code. I pull them as part of the documentation build process and compile a PDF with latex. Latex seems ...
0 votes
1 answer
282 views

Break longer word into lines to fit the box (inputminted?)

I would like to fit the long string (as it is labelled url in the json file) inside the box without overflowing. As far as I understand, breaklines option only helps when strings consist of separated ...
0 votes
1 answer
17 views

Figure and Listings Produce Extra Page Break

I am trying to include a tex file directly after a figure environment. When I do, the listings ends up being on the next page even though a large amount of space exist on the previous page. How do I ...
0 votes
1 answer
153 views

Priority of page breaks between paragraphs in beamer slides with allowframebreaks

I have breamer slides with allowframebreaks which have some basic structure, e.g.: \begin{frame}[fragile,allowframebreaks]{Title} some text... \begin{itemize}...\end{itemize} other text \begin{...
1 vote
1 answer
33 views

Referencing a listing and getting two question marks

I'm using TexShop 4.69 and I'm using lstlistings. But now after inserting my 3rd lstlisting, I can't get an adequate reference number. I'm receiving now two “??" in my text. Can somebody please ...
28 votes
3 answers
14k views

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about double-...

1
2 3 4 5
69