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
14 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
22 views

Automatically break a very long line, shown with monospaced font (code-like display)?

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 ...
  • 193
0 votes
0 answers
16 views

Custom Environment for Multi-Part Question that Appear in Frontpage in Article Class

I want to do a multi-question environment in LaTeX. I'll share my current setup and would lie help to achieve my goal. I have the following: \documentclass[12pt]{article} \usepackage{thmtools} \...
0 votes
2 answers
45 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 ...
  • 5
1 vote
1 answer
21 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
24 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,534
1 vote
2 answers
65 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,534
1 vote
0 answers
27 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. ...
  • 109
1 vote
1 answer
29 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
141 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: \...
  • 23
1 vote
1 answer
47 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, ...
  • 277k
0 votes
0 answers
17 views

Captions throws error when used with fancyvrb/fvextra

Suppose I have a file verbatim.py with the following contents: def f(x): s = "908df0sdfdsfsd78g89f7g98fd7gh98fdhfd7h98df7h98dfh99h8dfa897hf9d7h98fd7hf98dh" return x def f(x): s = ...
  • 1,534
0 votes
1 answer
25 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
50 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 ...
5 votes
1 answer
252 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
30 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
27 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 ...
  • 462
0 votes
1 answer
21 views

How to escape to LaTeX inside \lstinline? [duplicate]

The escape character works inside lstlisting environment but not inside \lstinline \documentclass[aspectratio=169, xcolor={x11names}, t]{beamer} \usetheme{Dresden} \usefonttheme{professionalfonts} \...
0 votes
0 answers
26 views

Pass a listing as an argument to a command?

I have a custom listing defined as follows: \newtcblisting[auto counter, number within=chapter]{MyCListing}[2][]{% enhanced, frame hidden, breakable, borderline north = {0.5pt}{0pt}{...
0 votes
1 answer
26 views

Adding Labels and Referencing Modified Listing Environments

I want to label and reference the modified listing environments namely Matlab Code and Matlab Output. However, when I add the \label command and try to reference the labelled modified listing ...
  • 590
1 vote
0 answers
52 views

Is there a way to use \( \) inside a listings environment as math delimiters

I have the following code \DeclareCaptionLabelFormat{algocaption}{Algorithm} % defines a new caption label as Algorithm x.y \lstnewenvironment{algorithm}[1][ { \captionsetup { ...
2 votes
1 answer
33 views

How do I use a section counter inside a tcblisting?

I'd like to add the current figure/section number to the title of a tcblisting. Right now, my hacky solution is to just use the section number and increment it manually every time I want to use my ...
0 votes
1 answer
30 views

Customizing the location of a caption on a lstlisting?

I'm working on some code listings and would like to have my caption be top-left aligned with the file name (optionally) in brackets. The default settings appear to center the caption, and I can't find ...
1 vote
1 answer
25 views

cref on lslisting elements only translates to two questionmarks and the index of the element

I am rather new to working with LaTeX and so far I have not found the solution to following problem: Using \cref or \Cref gives me the desired output whenever I use it with tables or figures. When I ...
  • 13
0 votes
1 answer
42 views

LyX, listings, cannot get return to the line in the last part of a code [closed]

Reformulation: I am starting from the Julia code as follows (in VS-Code): fout = open("harmoniques-spheriques_l3_m1.dat","w") for θ in 0.00:0.02:6.50 for φ in 0.00:0.02:6.50 ...
0 votes
0 answers
21 views

Adding captions to matlab code and output environments and coloring of comments

I have the following matlab.stycode: \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{matlab} \RequirePackage{verbatim} \RequirePackage{fancyvrb} \RequirePackage{alltt} \RequirePackage{upquote} \...
  • 590
0 votes
0 answers
31 views

Spacing for typewriter font looks off without fulflexing option in lstlisting [duplicate]

I'm trying to get the spacing and font to look clean in my lstlisting output window. Right now, if I enable the columns=fullflexible option, it makes the font truly monospaced and it perfectly aligns ...
0 votes
1 answer
40 views

Using .\ inside lstlisting causes issues crashes

I want to produce MATLAB prettified code with MATLAB code. Using .\ causes error. alsoletter={.\\} in \lstdefinestyle does not seem to work \documentclass[aspectratio=169, xcolor={x11names}, t, ...
0 votes
0 answers
34 views

Using .\ inside tikzpicture causes issues crashes

I want to produce MATLAB prettified code with MATLAB code highlighted with tikz background. The environment itself works. Using .\ causes error. alsoletter={.\\} in \lstdefinestyle does not seem to ...
0 votes
0 answers
22 views

How to customize the color of ) in matlab-prettifier?

I want to customize the color of the closing brace ), but it does not seem to work. I tried passing the following to literate option {)}{\textcolor{IndianRed1}{)}}{1} This issue arises when using ...
1 vote
1 answer
30 views

How to get listings to identify \ as letter?

With listings, it is possible to identify \\ as letter using the following literate entry {\\\\}{{\textcolor{IndianRed1}{\textbackslash{}\textbackslash{}}}}{1} However, I want to do the same thing ...
1 vote
1 answer
39 views

Amsbook + Paracol pagebreak broken with mdframed

I am trying to typeset some code and some commentary side-by-side using paracol and listings with the amsbook document class. It mostly works but I encounter a bug, when there is a pagebreak the ...
  • 1,040
0 votes
1 answer
47 views

How to add referrable numbered circle symbols to code listings?

I'm using \lstinputlisting to include sections of source code. Instead of adding line numbers to be able to refer to some specific parts, I'd like to include unique symbols that are visibly not part ...
1 vote
0 answers
128 views

Nicely typeset SMILES in LaTEx [closed]

I am currently trying to include SMILES notation of molecules into my thesis. They are strings which look something like this: CC1=C(C(=O)C[C@@H]1OC(=O)[C@@H]2C@H/C=C(\C)/C(=O)OC)C/C=C\C=C Is there ...
  • 11
0 votes
0 answers
42 views

How to configure cwl to provide verbatim highlighting for custom code?

I am trying to customize cwl file to provide verbatim highlighting. I am trying to get assistance from TeXstudio : User manual, and my cwl file contains the following \basoom{verbatimSymbol} This is ...
4 votes
2 answers
96 views

Error with % and & despite using verb option

I am new to tabularray and I have a problem typesetting tables with code in it. I see the option verb must be given to environment tblr to allow verbatim text, but even then, characters % and & ...
  • 1,062
0 votes
1 answer
22 views

Invalid character error: Listings with unicode chars with pdflatex and xelatex

The following code works fine with xelatex. It gives an invalid character error ^^00 with pdflatex. If I comment the line out it works fine. Probably an input encoding problem but can not find the ...
  • 19.2k
0 votes
1 answer
21 views

How to get lstdefinestyle to accept a custom command with an argument?

I want to customize the style of Matlab-editor in matlab-prettifier package. What I want is to produce background for MATLAB styled commands, but it does not seem that basicstyle key accepts commands ...
1 vote
0 answers
28 views

lstinputlisting ignores showlines=true

I am trying to display some code in my document using lstinputlisting. I want to display code written in Stan. I have a separate Stan file which I then call in my Latex document. Below is a working ...
  • 184
0 votes
1 answer
73 views

how to add such a footnote to the code listing

Recently I saw a manual for working with glossaries, source code on page 14 there is a footnote with: opening the source code downloading it from the server by downloading the finished pdf file I ...
  • 13
0 votes
0 answers
36 views

Math mode in wrapped lstinline

I am writing text that should be displayed as a code block with some fancy math mode characters. \documentclass{article} \usepackage{listings} \begin{document} \lstinline[mathescape=true]{Integer $\...
0 votes
1 answer
84 views

Can't display Δ in a lstinputlisting: LaTeX Error: Invalid UTF-8 byte sequence (�\lst@FillFixed@)

I have an external JSON-File that contains the character Δ. A document can be built but I get the error: LaTeX Error: Invalid UTF-8 byte sequence (�\lst@FillFixed@). As it's external I am using: \...
  • 113
0 votes
0 answers
22 views

How to make wider lstlistings

This is my LaTeX document containing some Java code: \documentclass[12pt, oneside,titlepage]{book} % add a4paper \usepackage[italian]{babel} \usepackage{geometry} \usepackage{color} \definecolor{...
  • 103
0 votes
0 answers
38 views

How to bold or highlight specifc text in Verbatim, Is there any other method?

I am trying add some code in my article, And I need to bold and highlight some code words in Verbatim section (in Code). Or atleast highlight words. I couldnt find any method in verbatim to highlight ...
2 votes
1 answer
112 views

All caps text is crammed in lstlisting

I'm using lstlisting for command line documentation. The problem is that anything written in all CAPS is poorly spaced inside lstlisting but normal outside of it. I observed the same issue with ...
  • 123
2 votes
1 answer
44 views

How can I remove semicolon after Figure caption and make its number bold, when listing caption changed into Figure

I have applied in combination of following two solutions. How to make figure and listing share their counter and How to change listing caption?. I was able to combine them and make it work but I just ...
  • 1,175
2 votes
1 answer
77 views

\sys_get_shell:nnN seems to strip newlines from shell output

Goal: run a shell command and \input its output as LaTeX code. See related: How to protect \input shell command args with backslashes When using expl3's \sys_get_shell:nnN, newlines from the shell ...
1 vote
1 answer
35 views

How to create a new environment with mdframed and lstlisting? [duplicate]

I want to create a new environment that wraps mdframed and lstlisting together as shown below, however that does not work for me as it does not compile. Any ideas what the issue is and how to define a ...
  • 1,144
0 votes
1 answer
20 views

How to define custom code listing?

I have the following custom listing but it throws error for lstset part that the keys are undefined. Any ideas how to fix this? \documentclass{llncs} \pagestyle{plain} \usepackage[utf8]{inputenc} \...
  • 1,144
2 votes
1 answer
36 views

\lstinputlisting always parses entire source file

I'm using a lot of \lstinputlisting commands to display snippets from a large source file. For example: \lstinputlisting[firstline=8244,lastline=8250]{source.c} \lstinputlisting[firstline=9244,...
  • 23

1
2 3 4 5
69