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.

0
votes
0answers
5 views

lstinline with breaklines=true conflicts with wrapfig, causing warnings

The following MWE shows a warning, printed below: \documentclass{article} \usepackage{listings} \usepackage{wrapfig} \lstset{breaklines=true} \begin{document} \begin{wrapfigure}{r}{0.5\linewidth} ...
2
votes
1answer
24 views

Highlight all identifiers starting with an underscore

The first answer to this question describes a method for highlighting all identifiers starting with an at sign. I want to do the same thing, just with an underscore instead. I've modified the code ...
2
votes
1answer
28 views

Adding similar operators to listings

I'm trying to create a new language definition with operators => and >. Highlighting both => and > doesn't seem to work. I have tried putting them in otherkeywords in both orders. ...
0
votes
0answers
34 views

Extra }, or forgotten error when using `\textcolor` [duplicate]

I am trying to highlight lines in my listing and I keep getting an error that says: Extra }, or forgotten $. ... I am trying to highlight : \begin{lstlisting}[language=Java, numbers=none] (*@ \...
0
votes
0answers
27 views

\lstset colorize numbers in code [duplicate]

I defined a syntax highlighting for my code like so: \lstdefinelanguage{CSharp}{ sensitive = true, keywords={assembly, class, method, field}, keywords=[2]{public, private, family, ...
1
vote
0answers
25 views

How to change numbering of listings [duplicate]

My listings have the numbering 1.1, 1.2, 1.3 - 2.1, 2.2, ... I need them to be continuous regardless of the chapter or section, being 1, 2, 3, 4, 5, 6, ... The commands i used on listings: \...
1
vote
1answer
36 views

Using minted inside listing causes Problems

I am farly new to LateX, so please be kind ;-). I am using minted to show off some code I wrote. I want the code to have a caption and label so i can refer to it from the text and have it appear in ...
2
votes
1answer
40 views

tcolorbox adds fragments of listing to list of listings

I'm writing a report due to tomorrow night but I have a problem that I can not resolve. The code is the following, the problem is that in the list of listing appears also a fragment of the listing ...
3
votes
0answers
29 views

Alignment of an un-numbered multicolumn tcolorbox listing

Consider the following code: % Preamble \documentclass[letterpaper, 10pt]{article} \usepackage{calc} \usepackage{xcolor} \usepackage{listings} \usepackage{multicol} \usepackage[most]{tcolorbox} \...
0
votes
0answers
37 views

Inserting a device tree in a Latex Doc [closed]

all. I'm trying to insert a device tree in my undergrad thesis, but the listing package doesn't support the device tree syntax. Any suggestion?
0
votes
1answer
36 views

How to convert text/listing into images

I would like to ask is there any way to covert some texts/listings to images so that they could not be copied? I would appreciate any suggestions.
0
votes
0answers
34 views

Listing: Start number as set for each listing [closed]

In my document I'm using lots of listing to include certain lines of my Matlab File in the documentation. \documentclass[a4paper,12pt,headsepline]{scrartcl} \usepackage{listings} % Fuer ...
3
votes
1answer
38 views

Fitting code and formulas together and aligned

Here is a slide from a presentation I'm preparing: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[fragile]{Example} \begin{tabular}{ l r } \begin{lstlisting}[mathescape=...
2
votes
1answer
26 views

Prevent keyword syntax highlighting within moredelim

Code: \documentclass{article} \usepackage{parskip} \usepackage{listings} \usepackage{textcomp} \usepackage{xcolor} \lstset{ basicstyle=\ttfamily, columns=fullflexible, keepspaces=true, ...
0
votes
1answer
26 views

Using lstlisting inside a macro fails: Text dropped after begin of listing

My first code example below runs fine. It does conditional compilation based on whether \flag is defined or not. \documentclass{article} \usepackage{listings} \begin{document} \ifdefined\flag \begin{...
5
votes
1answer
39 views

The listings package highlights “e3” in “20e3” as identifier

LaTeX code: \documentclass{article} \usepackage{listings} \usepackage{textcomp} \usepackage{xcolor} \lstset{ basicstyle=\ttfamily, columns=fullflexible, keepspaces=true, upquote=true, ...
2
votes
1answer
72 views

Combining multiple listings styles in a single \lstdefinestyle command

Here is my code: \documentclass{article} \usepackage{listings} \usepackage{textcomp} \usepackage{xcolor} \lstdefinestyle{style1}{ basicstyle=\ttfamily, columns=fullflexible, keepspaces=...
0
votes
1answer
93 views

E-mail in LaTeX

I have been trying to include contents of an e-mail in a latex document, similar to how there are packages to include source code, for example (using the listings package, for example). These are ...
2
votes
0answers
29 views

Listing different background color [duplicate]

I want to use a different text color in a listing, for example red to highlight a word or a sentence. I use \textcolor{} but if it's over more than one line the background gets white and not grey. Is ...
0
votes
0answers
23 views

Keep automatic numbering in listings [duplicate]

I have the following MWE \documentclass{article} %-> Package for font (and other elements) color: \usepackage{color} \definecolor{semigray}{gray}{0.5} %-> To hyphenate long url addresses: ...
2
votes
3answers
36 views

How to insert text with special characters and automatic line breaks

I want to insert a Readme file into my latex code, which contains some special characters. First i tried to use a verbatim environment, but this did not work because there were no automatic line ...
0
votes
1answer
16 views

Otherkeywords option causes listings to break

I'm trying to make a simple language definition for typesetting regular expression. The otherkeywords option that the listings package provide seems pretty convenient for that. However, it just doesn'...
1
vote
1answer
18 views

Why is identifierstyle used for lstlisting with no language?

Here is my code: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstset{ keywordstyle=\color{blue}, identifierstyle=\color{red}, } \lstnewenvironment{algol}{\lstset{...
2
votes
1answer
17 views

How to specify language dialect in \lstline option?

First, here is some code that works fine: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \begin{document} \lstinline[language=algol,keywordstyle=\color{blue}]{int a} \end{document} ...
7
votes
1answer
59 views

Why doesn't \lstset{escapeinside={((}{))}} work as expected?

Here is my code: \documentclass{article} \usepackage{listings} \lstset{basicstyle=\ttfamily,columns=fullflexible} \begin{document} \lstset{escapeinside={((:}{:))}} \begin{lstlisting} foo ((:\textit{...
1
vote
1answer
51 views

Two listings side-by-side in TColorBox

I have two requests: I am trying to compare two codes side by side using tcolorbox. The problem is that I am not able to put them both with code format (i.e., one is in plaintext and the other is in ...
0
votes
0answers
24 views

listing, gray background white space problem [duplicate]

I used the following link to implement code listing: https://www.overleaf.com/learn/latex/Code_listing It works generally fine, but whenever I write math and do power of something for example it ...
0
votes
1answer
42 views

Centering lstlisting using tcolorbox Inside Enumerate Environment

I am trying to center a lstlisting environment using tcolorbox (as suggested here). The method does work normally but doesn't render as expected in enumerate environment as shown below: I have tried ...
0
votes
3answers
34 views

Interaction between SASnRdisplay and Tufte book class

SASnRdisplay is a package to display SAS and R code and results. It appears to have some bad interaction with the Tufte book class. The code below produces very odd text (letters with a variety of ...
1
vote
2answers
32 views

Problems when defining a general inline code command with listings or verb

I am trying to define an inline \code command (not language specific, just a smarter \texttt{} without the need to escape underscores or tildes, for example). I tried the three versions below based on ...
0
votes
0answers
21 views

Trouble with the listings package command \lstnewenvironment [duplicate]

Consider the following example: \documentclass[oneside,article]{memoir} \usepackage{listings} \usepackage[lining]{ebgaramond} \usepackage[cmintegrals,cmbraces]{newtxmath} \usepackage{ebgaramond-maths}...
1
vote
1answer
42 views

Change color of numbers in listings but not inside of identifiers

I want to write C++ code in LaTeX using the listings package. The problem is that I want to change the color numbers in code (integers, doubles...). The only solution I found was this: \...
0
votes
1answer
35 views

minted code samples more “condensed” than lst-listing

I want to switch to minted over listings for the superior syntax highlighting, especially for C++. But I can't get the font to look as nicely as with listings. Somehow the font is heavier and more ...
1
vote
0answers
9 views

Extra dash inserted by listings package in text mode [duplicate]

The code below is rendered to this: location/- counter. Code: \documentclass[a4paper]{article} \usepackage{listings} \begin{document} \hspace{0.85\linewidth} location/counter \end{...
0
votes
0answers
44 views

Incomplete \iffalse, all text was ignored

What is wrong with this code please? When I delete second, third and forth mylisting it works fine. Error: ! Incomplete \iffalse; all text was ignored after line 18.\fi<> ./xxxxx1.texThe file ...
0
votes
1answer
53 views

Listings - How to extend the indentation of lines

Is there an opportunity to extend the indentation of lines in a listing? My MWE looks like that: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[fragile] \begin{...
0
votes
1answer
22 views

Listings - Adjust different indentations to the same look

I have a bunch of code snippets and they look like these guys: \documentclass{beamer} \usepackage{listings} \begin{document} \begin{frame}[fragile] % snippet 1 \begin{lstlisting} List list = ...
2
votes
0answers
29 views

Proper usage of otherkeywords option in listings

I'm trying to understand how listings' otherkeywords option really works. The documentation says about it: Defines keywords that contain other characters, or start with digits. Each given 'keyword' ...
1
vote
1answer
93 views

Listing - invalid UTF-8

What is wrong with this please? The error is: ! Package inputenc Error: Invalid UTF-8 byte sequence.See the inputenc package documentation for explanation.Type H <return> for immediate help.... ...
0
votes
0answers
47 views

Caption setup for package Minted

When using minted, the spaceing below and above the code is too high. In comparsion when using a new created environment (mintedlisting) with the package caption, the spaceing seems to be right but ...
0
votes
2answers
58 views

Listings with color OR tilde, not both

Trying to get a listing block with a command prompt that has both color and a proper formatting. I can get the proper format with a simple black typeset, but not with color...the tilde (signifying ...
3
votes
2answers
110 views

Is it a listings package bug?

I use listings package (the newest version 1.8b), but in the following case it doesn't work correctly: \documentclass{article} \usepackage{listings} \begin{document} \section{Title} \begin{...
1
vote
0answers
25 views

How can I use Fira Code with ligatures in pdflatex?

Basically, I've come to really like Fira Code and its ligatures while coding, and I'd like to use it for my code listings in LaTeX, too. Specifically, I am looking for a way to use Fira Code with ...
0
votes
0answers
22 views

Are there any existing setups for Listings to provide syntax highlighting for Antlr4 (.g4) grammar files in LaTeX?

I have been using the Listings package for C and Java highlighting and I also need to highlight my Antlr4 grammar code, which is of the .g4 format. Are there any existing setups for this, preferably ...
1
vote
2answers
50 views

How to influence line breaks in lstlistings?

Latex breaks lines at odd positions in code listings, for example, before a comma or after opening quotation marks. Is there any way to influence the line breaking strategy or to suggest where a line ...
2
votes
1answer
29 views

Escape listings but keep colour formatting

Getting bold typed text I have been using listings to format my code, and have occasionally been using the following solution to make some typed text bold: \DeclareFontShape{OT1}{cmtt}{bx}{n}{<5&...
1
vote
0answers
59 views

Suppress line numbering for specific lines (including blank ones) in listings package

My question is exactly the same as this one, but in my case some of the lines for which I would like to suppress line numbering are blank, and the accepted answer for that question produces an ...
4
votes
1answer
180 views

How to replace the “space symbol” (squat-u) in listings?

Instead of this output with a "squat-u" space symbol I would like to replace it with e.g. $\cdot$. It is no problem to replace the default symbol for tabs but not for spaces?? \documentclass{article}...
1
vote
1answer
44 views

Class tufte-book and R listings code box width problem

When I run the following MWE: \documentclass{tufte-book} \usepackage{Sweavel} \usepackage{amsthm} \usepackage{mathtools} \usepackage{soul} %%%%%%%%%% % R example %%%%%%%%%% \newtheoremstyle{rex}{}{...
4
votes
1answer
45 views

Changing a tcolorbox listing option based on the number of lines of its listing

Consider the following code which produces listings: % ---------------------------------------------------------------------------- % % Preamble \documentclass[12pt]{article} % -----------------------...