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.
3,689
questions
1
vote
1
answer
92
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 ...
2
votes
0
answers
268
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 ...
1
vote
1
answer
217
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}
\...
0
votes
2
answers
163
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
...
8
votes
1
answer
219
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 ...
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 ...
2
votes
1
answer
85
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 ...
1
vote
2
answers
203
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]{...
2
votes
0
answers
54
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 @ ...
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 ...
1
vote
1
answer
72
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 ...
0
votes
1
answer
37
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, ...
0
votes
1
answer
71
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 ...
0
votes
1
answer
233
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?
0
votes
0
answers
38
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=...
0
votes
1
answer
31
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 ...
4
votes
1
answer
269
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}
\...
0
votes
1
answer
96
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} % ...
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}
\...
0
votes
0
answers
20
views
How can minted (or something similar) work with automatic alignment of code? [duplicate]
I typeset Lisp code in a proportional typeface, and it relies on alignment. An example of the typesetting can be seen here:
If I ignore font selection, it was typeset using this code:
\begin{tabbing}
...
0
votes
3
answers
318
views
`latexmk`can include files created during the `latexmk` run, except with `lstinputlistings`
My latex file looks roughly like this:
...
\usepackage{listings}
...
\lstinputlisting{F4_01fig2dev.ptx}
...
and the file F4_01fig2dev.ptx is to be created.
In fact I want to build with latexmk.
...
1
vote
1
answer
95
views
Correct Elixir Syntax Highlighting
I am currently writing a thesis in which I frequently need to add Elixir code snippets. I am not very experienced with LaTeX, but after a bit of searching I found this solution.
The problem is that ...
1
vote
1
answer
131
views
Continue code on the next page with line numbering (minted, tcolorbox)
Here is my code:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins}
\tcbset{...
1
vote
0
answers
58
views
LaTeX: how to make a well-formed TikZ rectangle with mono-space code that is partially coloured?
I want to make a rectangle in TikZ, which has code in it.
But, some part of the code should be coloured in e.g. blue.
My current best solution is:
\documentclass{article}
\usepackage{xcolor} % ...
1
vote
1
answer
85
views
How to make caption above minted listing?
I am using minted package for my code:
\begin{listing}[htbp]
\begin{minted}[baselinestretch=1,
linenos,
xleftmargin=1.5em,
breaklines]{solidity}
...
0
votes
0
answers
67
views
How can I align code listing with a propotional font?
I'd like to typeset some code with a proportional code with alignment. How can I do it? The capabilities of listings to align are limited, and I was using tabbing, but it causes problems because every ...
0
votes
1
answer
51
views
Best way to indicate that some lines are left out
Assume I wrote a class myclass in Matlab with many properties and methods, and now I want to display
its most important properties (foo and bar),
the headers of its most important methods (myclass ...
0
votes
0
answers
31
views
Why does adding a listing above another mess up the formatting of the original
The following Latex produces about what I expect:
\documentclass[a4paper,11pt]{article}
\usepackage{listings}
\usepackage{color}
\usepackage{tcolorbox}
\title{test}
\begin{document}
\maketitle
\...
0
votes
1
answer
39
views
Half of my lstlisting is not shown in latex
I have used a big equation in latex. Half of my code is not shown in latex. Here is my equation:
\begin{center}
\begin{equation}\label{HammingTappering}
AF = \exp^{-j\dfrac{N-1}{2} \Psi} \...
3
votes
2
answers
115
views
Problem with \lstinline in the caption of lstlisting environment
With
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
backgroundcolor=\color{gray},
emph={FMD},
emphstyle={\color{orange}},
emph={[2]RAW},
emphstyle={[...
0
votes
0
answers
31
views
Use '<' character in lstlistings comment [duplicate]
I have an issue where the '<' character in lstlistings appears as '¡' in the comments
How can I fix that please?
1
vote
0
answers
43
views
How do I highlight C libraries in listings?
I am using the listings package to typeset the following C code in Latex
#include <stdio.h>
#include <stdlib.h>
int main ()
{
printf("Hello World!\n");
return 0;
}
Here ...
3
votes
1
answer
58
views
Prevent highlighting of keywords in strings starting with square brackets
I have the following MWE in pdfLaTeX.
\documentclass{article}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0....
2
votes
1
answer
94
views
How to exclude line numbers in code listing from being copied?
How to make lines code numbering uncopiable and white (or any other color)?
% arara: pdflatex: {shell: 1}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\...
0
votes
1
answer
101
views
How can I modify my tcblisting to show input code and the expected output side-by-side?
I have a code listing and tcblisting defined as follows.
\lstdefinelanguage{MyScheme}{
basewidth=0.5em,
morekeywords=[1]{define, cond, lambda, else},
alsodigit=!\$\%&*+-./:<=>?@^_~,
...
1
vote
1
answer
150
views
How to display the value of a variable inside a listings environment
I assigned the value 42 to the variable \xVar. Is it possible to display the value 42 using the variable \xVar inside a listings environment \begin{lstlisting}...\end{lstlisting}?
My Code:
\...
0
votes
1
answer
72
views
Automatically break a very long line, shown with monospaced font (code-like display)? [duplicate]
I have seen but there is no answer there ...
I would like to show a very long line, composed of only digits and comma, as code in Latex - and have Latex automatically break it, as I do not want to ...
0
votes
2
answers
139
views
lstlisting and newcommand conflict
I would like to make a document that displays figures and the corresponding code, and want to cut down on repeating myself. MWE below. I think there is something wonky about lstlisting in a ...
1
vote
1
answer
76
views
Problem of coloring with listings
I'm looking for reproduce the color scheme of sublime text for my latex document. Here is my attempt:
\documentclass[10pt]{report}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}
\...
1
vote
1
answer
58
views
Rewriting non float code listings Pandoc compatibility
In a previous question I asked whether it would be possible to create a listing in LaTeX using fancyvrb and fvextra satisfying the following requirements:
Allowing for page breaking (non-float)
Line ...
1
vote
2
answers
120
views
How to apply captions to non-floating Listings
One way to add captions to code listings is as follows:
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{fvextra}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{float}
\newfloat{...
1
vote
0
answers
58
views
How can I list code with alignment and syntax highlighting?
I would like to effectively typeset code in a proportional font with syntax highlighting and horizontal alignment. How can I do that?
The package listings offers syntax highlighting but not alignment. ...
1
vote
1
answer
50
views
How to include nested captions for listings
I Want to recreate the nested Listing captions like in the image below, I tried doing this:
\documentclass{article}
\usepackage{listings}
\usepackage{subcaption}
\begin{document}
\lstlistoflistings
...
2
votes
1
answer
424
views
LaTeX is not letting me add spaces in strings in lstlistings
I am trying to add some code to my document, but whenever there is a space inside a string in the code, it shows up with a bucket(?) thing. I have provided the code and the output below:
\...
0
votes
1
answer
158
views
tabularray and listings combability
The following MWE (borrowed from @Celdor answer}, where is used tabular table, works fine:
\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{listings}
\lstset{language=sql,
...
0
votes
1
answer
210
views
Position lstlisting below text
I'm running into issues when using lstlisting to highlight code. In the latex code I have intended the listing to appear below the text, but it disregards the way the code is structured and puts it ...
0
votes
1
answer
156
views
How to quickly change spacing of lstlisting to use two spaces instead of four?
I'm working on some LaTeX code listings and have decided to change my spacing from four to two. The problem is that there are a ton of listings in my document (which is ~500 pages)... is there any way ...
6
votes
1
answer
496
views
How to typeset Japanese ascii art in latex?
I am thinking about creating a package, which provides an environment that uses MS PGothic to typeset some fancy Japanese ASCII art.
MS PGothic is the default font for Japanese ASCII art.
My thinking ...
0
votes
0
answers
52
views
Does anyone have an idea to recreate this code format using listing or with another option?
I tried to recreate this code format with \usepackage{listingsutf8}. I made this code using Inkscape.
My code in LaTex is:
\documentclass{article}
\usepackage{listingsutf8}
\usepackage{xcolor}
\...
1
vote
1
answer
58
views
Align frame with surrounding text
In the following minimal working example, the text of the listing is aligned with the surrounding text, thus the border on the left protrudes into the margin.
I prefer to have the frame align with the ...