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
1 answer
86 views

How to show a LaTeX command in lstlisting? [duplicate]

I code this in a .tex file. \begin{lstlisting} % This is the syntax for inserting code. \begin{lstlisting} \end{lstlisting} \end{lstlisting} And this is what I expect: % This is the syntax ...
DaydreamHippo's user avatar
2 votes
1 answer
39 views

How to affix a file-name in a box to the corner of a listing environment?

I'm writing a series of lecture notes and, because I'm working with multiple source files, I'd like to affix the current file name in the top-right of my listing environments. Here's an example of ...
Joshua Crotts's user avatar
0 votes
2 answers
54 views

How to include a listing with `#` in the filename?

Given the following files: book.tex \documentclass{memoir} \usepackage{listings} \begin{document} \lstlistoflistings \chapter{Hello, world!} \lstinputlisting{C\#/hello.cs} \end{document} C#/hello.cs ...
Christian Hujer's user avatar
1 vote
2 answers
96 views

lstinline in mathmode with correct font size

I often typeset mathematical formulas about computer programs (loop invariants, etc.). I typeset them in typewriter font, saying in my preamble \lstset{basicstyle=\ttfamily}. I could say $\frac{\text{\...
ysalmon's user avatar
  • 1,072
1 vote
1 answer
52 views

Automatically label line numbers in minted enviornment

I've recently swapped from the listing package to the minted package for my code listings. When I used lstlistings, I was able to redefine \lst@Key to automatically place labels of the format \lst@...
candr's user avatar
  • 21
0 votes
1 answer
32 views

Automaticly listing definitions at the end of document

I'm writing latex notes for mathematics. I use \newtheorem{definition}{Definition}[section] as an environement for definitions. I would like to have a list of definitions at the end of the document, ...
Philipp's user avatar
  • 103
0 votes
1 answer
84 views

Controlling listings `lstlisting` vertical spacing with paragraph breaks ( `aboveskip`, `belowskip`?)

When we have a blank line between text in the LaTeX source, we have a paragraph break. The fact of the paragraph breaking itself seems to be respected with a lstlisting environment. Specifically, if ...
geometrian's user avatar
0 votes
0 answers
40 views

Not enough space between label and title when using \lstlistoflistings

I'm using the \lstlistoflistings command to generate a list of my listings. Unfortunately there is not enough space between the label and the title (caption). \documentclass[12pt,oneside,titlepage,...
mbenkert's user avatar
0 votes
2 answers
57 views

lstlisting environment doesn't compile because code comments

I am trying to put a Verilog code listing in my document, but it returns a Latex error when processing the comment lines, here is the MWE: \documentclass[12pt,letterpaper,twoside]{book} \usepackage[...
Jacob Morales Gonzalez's user avatar
0 votes
1 answer
35 views

How can I reduce the all lines height in \lstinputlisting

I want to reduce all lines' height (empty space between each line) in \lstinputlisting, is it possible? Original code is taken from https://tex.stackexchange.com/a/660320/127048 , only \usepackage[...
alper's user avatar
  • 1,256
1 vote
1 answer
35 views

Renumber listing

I am using listings to add some codes, as shown in the image For this I use the following: \lstset{language= python, breaklines=true,basicstyle=\footnotesize} \lstset{numbers=left, numberstyle=\tiny,...
Luis Alexandher's user avatar
1 vote
0 answers
56 views

Zebra effect in minted and tcolorbox? [duplicate]

I am using Sickboy's answer to this and was wondering how i could manage it to get the alternating color lines like shown here. I already tried it with that lstlinebgrd-package and then did \lstset{...
Oliver Hihn's user avatar
0 votes
0 answers
30 views

Alignment of caption name in listoflistings

The caption name of my code is not aligned. I have tried to fix it with commands similar to \cftlistlistindent or \cftlistnumwidth but they don't exist. Please could you suggest me how can I align the ...
AIpython's user avatar
0 votes
0 answers
36 views

How to parse parameters from GCode with listings package and \lstdefinelanguage?

as the title says I'm currently working on a (incomplete, but sufficient) definition of the Gcode language within the listings package. This is my progress so far: \documentclass[11pt, oneside]{report}...
imax10000's user avatar
0 votes
0 answers
21 views

Inputting Matlab/R Code and Output Files

I placed a +50 reputation bounty on my question at Classifying Matlab Code and Pseudocodes under List of Codes and Matlab and R Output under List of Output. However the bounty is about to expire and I ...
itc's user avatar
  • 602
1 vote
1 answer
192 views

How to use listing, tikz and tikzmark packages together to annotate source code listing?

I'd like to annotate code listing something like this: Below is what I've attempted so far. I am a little worried about having to use raisebox so that the arrow tip doesn't point to the base of the ...
Pyi Soe's user avatar
  • 151
1 vote
0 answers
45 views

Overlining text in listing environment without changing the font

In short, I would like to place a line over some characters in a listing environment. I am aware of this answer, but am trying to achieve something a bit different. The following: \documentclass{...
Clément's user avatar
  • 5,091
3 votes
1 answer
70 views

Spaces missing in Greek text in listings

I have the following xelatex document: \documentclass{article} \usepackage[cm-default]{fontspec} \setromanfont{FreeSerif} \setsansfont{FreeSans} \setmonofont{FreeMono} \setmainfont{FreeSans} \...
user000001's user avatar
0 votes
1 answer
260 views

LATEX - How to write \lstdefinestyle for the YAML language

Starting from the answer to this question YAML Syntax Highlighting. If I wanted to have "- name:" colored blue and not black, and "test" colored in blue, how is this possible? spec:...
andreYLLI's user avatar
1 vote
0 answers
26 views

escape environments inside listing environment reduce horizontal space between characters

Why escape environments reduce horizontal space between characters? I tried both escapechar and escapeinside. See my code below. \documentclass{article} \usepackage{xcolor} \usepackage{listings} \...
Marco Moldenhauer's user avatar
0 votes
1 answer
42 views

How to add file name to the top-right of a listing environment?

I have several different lstlisting environments and was wondering if it were possible to add a box in the top-right corner of the environment that displays a string with the file name? For instance, ...
TheProgrammer's user avatar
2 votes
1 answer
201 views

Classifying Matlab Code and Pseudocodes Under List of Codes and Matlab and R Output under List of Output

I am kindly requesting for assistance on how to put the headings Matlab Code and Pseudocodes under List of Codes and headings Matlab Output and R Output under List of Output using the below MWE. In ...
itc's user avatar
  • 602
1 vote
1 answer
340 views

a good python ambient for my latex code

I am looking for a latex preamble in order to have a good python script. Here I found this \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} % Default fixed font does not support bold ...
Stefano Fedele's user avatar
0 votes
0 answers
17 views

using initial line numbering with listings package in latex

Is there the posibility to use the initial line numbering from the code I want to list in my latex file? So the code should be numbered like in the picture: But using the following code, the ...
Markus's user avatar
  • 31
1 vote
1 answer
95 views

How to use \labelformat for lstlisting (with listings package) so that \vref (of varioref package) gives "Listing 1.1 on page x"?

I want to reference listings (with listings package) via \vref (from varioref) analogous to figures. So I'm looking for the analogue to \labelformat{figure}{Figure~#1}. What is the name of the ...
Pyi Soe's user avatar
  • 151
1 vote
1 answer
35 views

How to left-align code in listing package?

I am working on some slides in beamer about the R language. I use the listing package to show some code. The problem is if I use the autogobble option to remove the unnecessary space, the source code ...
Ramiro's user avatar
  • 75
1 vote
1 answer
47 views

Why does `\pageref` give incorrect page number when a `lstlisting` starts on a new page?

I noticed neither \pageref nor \vpageref gives me the correct page number when a particular listing starts on a new page and there also is an underfull vbox on the previous page. I think if I fill ...
Pyi Soe's user avatar
  • 151
0 votes
0 answers
126 views

listings - breakautoindent doesn't work with keepspaces

I am using the listings package, and I can't get the breakautoindent option to work with keepspaces=true. Example: \documentclass[12pt]{article} \usepackage{listings} \lstset{ basicstyle=\ttfamily, ...
Jasmine's user avatar
  • 26
0 votes
0 answers
22 views

Listings with colors, realtive width and no line break

I am looking for a straightforward way to get a listing environment that follows this specifications: Specific colors can be set on specific parts of the listing. No linebreaks, including for colored ...
Welgriv's user avatar
  • 275
0 votes
0 answers
40 views

Lstlisting/Verbatim inside tabularx environment?

I noticed that a \lstlisting inside a tabularx doesn't work: \documentclass{article} \usepackage{listings} \usepackage{tabularx} \let\code\lstinline \begin{document} % It does work \begin{tabular}{|*...
nowox's user avatar
  • 1,315
1 vote
1 answer
37 views

Issue with color in listings and line breaks

In the following example, the listing line break at the first space when the text is colored while it does not when the text is in black: \documentclass[dvipsnames]{report} \usepackage[utf8]{inputenc} ...
Welgriv's user avatar
  • 275
1 vote
1 answer
31 views

Underscore in listing color

How to make this code works: \documentclass[dvipsnames]{report} \usepackage[utf8]{inputenc} \usepackage{xspace} \usepackage{xcolor} \usepackage{listings} \lstdefinestyle{s}{escapechar={|}} \begin{...
Welgriv's user avatar
  • 275
3 votes
1 answer
40 views

behaviour of the option multicols in listings

I think the following two codes saying the same thing. However, the second code causes error. My question is: how to make the second code workable same as what the first code does. That is to say, how ...
lyl's user avatar
  • 2,667
4 votes
1 answer
63 views

How do I automatically exclude the comments from the listings?

While using the listings package, I would like to automatically exclude the comments from the input code file. This answer suggests whitening the comments. But that is not exactly what I am looking ...
Masroor's user avatar
  • 17.5k
1 vote
1 answer
270 views

Jupyter In/Out style using minted instead of listing

In Jupyter In/Out without Overflowing the solution provided is excellent. I'm implementing it using the minted option in tcbuselibrary and I'm getting this extra whitespace at the beginning of my ...
Elias George's user avatar
1 vote
1 answer
60 views

Listings package: Color code from certain character until next whitespace

I‘m using the listings package to style my code snippets in my current project, and I’m running into a problem I haven’t been able to wrap my head around. The programming language I’m using is SCL (...
Jakob Dannel's user avatar
3 votes
1 answer
126 views

Follow-Up to "Higher Asterisks in lstlisting environment"

In the answer to this question, the following solution is suggested to raise an asterisk: \documentclass{scrbook} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{listings} \usepackage{color}...
Hermi's user avatar
  • 225
2 votes
1 answer
49 views

Can you reference lines from source code when using `\inputminted`?

I wanted to know if there were any methods that would allow me to reference lines in source code that was imported with the \inputminted macro from the minted package? My assumption is that this is ...
LightninBolt74's user avatar
4 votes
2 answers
172 views

listings package line-breaking issues, with Unicode characters

When I use listings, to display code with Russian comments, in a literate block, I obtain invalid line-breaking, on whitespace characters. Please refer to the below MWE, for an example, which compiles ...
Youra_P's user avatar
  • 978
0 votes
2 answers
57 views

Use of multicols in listing causes unexpected alignment

The sole difference of the following two codes is the use of multicols=2. And this causes the alignment of parbox in Code 1 wrong -- though alignment t is given, the typeset seems like alignment b. ...
lyl's user avatar
  • 2,667
1 vote
0 answers
133 views

How to have fixed, consistent and uniform whitespace around captions

Problem Description I want to have my tables, figures, and listings have the same amount of white space above or below captions. At the moment space is different for tables, figures and listings. ...
itc's user avatar
  • 602
1 vote
1 answer
89 views

Missing Listing number in caption

My problem is that I don't have automatic listing numbers in the caption. (I thought they would be included by default and can't seem to find a way to include them) \begin{lstlisting}[caption={test}, ...
tom201's user avatar
  • 13
2 votes
1 answer
29 views

Curly quotes in lstlistings get moved to the start of words

I have a code snippet that uses the unicode character ’ (u2019), also known as right single quotation mark in the middle of a word. Unfortunately, it seems the lstlistings environment causes this ...
pouli's user avatar
  • 31
1 vote
1 answer
76 views

How do you automatically wrap text in the \verb||-like environment -- that is, in-line, and without requiring a line break before and after?

This is my first question on any StackExchange site, so please bear with me. I am writing code for a paragraph of normal English with little bits of code spliced in. Initially I wrote something like: ...
Noah J's user avatar
  • 129
1 vote
0 answers
359 views

Arabic text in python code in listings at latex

I'm writing python code in my latex file, but it contain some Arabic texts when I write it using listings in python the Arabic words don't appear! \documentclass{article} \usepackage{listings} \begin{...
Eng.sh's user avatar
  • 69
1 vote
0 answers
43 views

subscriptcorrection in newtxmath + listings + subscript in literate = 🗲

Feeding \documentclass{article} \usepackage{newtxtext} \usepackage[subscriptcorrection]{newtxmath}% subscriptcorrection not really needed for this minimal example but is helpful in general \usepackage{...
user avatar
0 votes
1 answer
67 views

Main font of the fontspec package interfering with the escapechar in the listings environment

Output Before Setting Main Font Before setting the main font using the fontspec package, the escapechar was working properly. Below is the output picture: and below is my MWE: \documentclass{memoir} ...
itc's user avatar
  • 602
1 vote
1 answer
66 views

lstlistoflistings for different counters

I'm using the lstlisting environment to show code, ubuntu terminal inputs and outputs. I have them defined as in the code example, using different counters named Code, TerminalIn and TerminalOut. When ...
Siebolic's user avatar
1 vote
0 answers
43 views

Same literate defination causes different behaviour

The code of following two examples has the same literate defination. The literate A! is used to emphasize some code by color and size. The literate !A is used to restore the color. In the first ...
lyl's user avatar
  • 2,667
3 votes
2 answers
237 views

Troubles with listings and polish characters (lualatex)

How I can display properly polish characters in code of programming language using listings package and lualatex compiler? main.cpp: //Zażółć gęślą jaźń #include <iostream> int main() { std::...
constantin_d's user avatar

1 2
3
4 5
72