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.

376 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13 votes
1 answer
11k views

How to increase the padding in the code snippet box when using `listings`?

So I am writing a book on Awk programming language, and I have enabled a single frame via \lstset{frame=single}. However, I would like the code within the snippet box to be further away from the frame ...
user avatar
12 votes
0 answers
874 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' ...
siracusa's user avatar
  • 13.4k
9 votes
0 answers
2k views

\inputminted: distinct file parts in one listing (equivalent to linerange in listings)

I want to include code from a file into my document. However, several distinct line ranges should appear in the same listing. Also, I want to use gobbling, and it would be nice to include some blank ...
Jenny's user avatar
  • 839
7 votes
0 answers
2k views

Formatting bash with listings

I writing a documentation in LaTeX about Linux Bash resp. Shell script. And I'm having some problems: How can I start a formatting at the beginning of a line? How can I format between two signs, but ...
Hur'q's user avatar
  • 71
7 votes
0 answers
209 views

Listings package and forcing inclusion of empty lines at end of line ranges?

By default, the listings package suppresses empty lines at the end of the file, and this behavior can be switched off with the option showlines. However, listings also suppresses empty lines at the ...
Tom Verhoeff's user avatar
6 votes
0 answers
674 views

Is there an easy way to correct apostrophes that are the wrong way around in a code listing?

I understand that for quotation marks ` is required to open a quote, however I am listing a long code copied over from Python where some comments are written 'comment' or """comment""". Is there an ...
Matt Bradley's user avatar
5 votes
0 answers
210 views

How to preserve trailing blank lines in lstinputlisting with linerange option?

Here is my code in foo.tex: \documentclass{article} \usepackage{listings} \begin{document} \lstinputlisting[linerange={1-2,7}]{foo.tex} \end{document} This code in foo.tex reads itself and ...
Lone Learner's user avatar
  • 3,226
5 votes
0 answers
229 views

Listings caption alignment in list environments

I'm having trouble with the alignment of captions of lstlisting inside environments like description or enumerate. I'm using the listings and caption packages. As soon as I try setting the caption ...
Bruno K's user avatar
  • 51
5 votes
0 answers
219 views

How can I use scintillua lexers to replace minted or listings with luatex?

Scintilla is a text editor. Scintillua adds dynamic Lua LPeg lexers to Scintilla for multiple languages. According to the documentation, Scintillua can be used as a library: Using Scintillua as a ...
cjorssen's user avatar
  • 10k
5 votes
0 answers
2k views

How to fix "Dimension too large" error with lstlisting

I use listings as the verbatim enviroment. However, I get the "Dimension too large" error with very long lines. The following is a sample code. \documentclass{article} \usepackage{listings} \begin{...
cqdjyy01234's user avatar
5 votes
0 answers
487 views

Code alignment using listings with proportional fonts is poor

I would like to typeset code using proportional fonts and the listings package, but no matter what I do, alignment is always off. Here is an example in Java (taken from Wikipedia): \documentclass[...
Håkon Marthinsen's user avatar
4 votes
0 answers
216 views

Have accented letter in keywords with listings

How can I have an word with accented latter that is also a keyword using listings? I found a solution to have accented letters here, but if the keyword contains an accent, it is not recognized as a ...
sayanel's user avatar
  • 141
4 votes
0 answers
86 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} \...
Vincent's user avatar
  • 5,257
4 votes
0 answers
246 views

How to remove lines and characters from listings / tcolorbox?

Consider this MWE \documentclass{ltxdoc} \PassOptionsToPackage{final}{listings} \usepackage[% ,listings ]{tcolorbox} \lstdefinestyle{mystyle}{% style = {mystyledef}, } \lstdefinestyle{...
lukascbossert's user avatar
4 votes
0 answers
567 views

'lstlisting' inside a table cell ignores line breaks

I am trying to put code listings within a tabulary cell. It works fine for the most part except that lstlisting is merging all lines into a single line. The MWE shows the problem. Any idea how it can ...
Priyshrm's user avatar
  • 173
4 votes
0 answers
344 views

Listings and Restructured Text

Background I'm trying to define a style/language for linting Restructured Text (rst) using the listings (lst) package. This is largely for a few notes I was making but I'll submit the language ...
Carel's user avatar
  • 988
4 votes
0 answers
2k views

Excessive vertical space after lstlisting

I have created a macro \piece to structure longer sections into smaller, numbered pieces. (I am using the macro in a set of lecture notes where I try to introduce one concept per piece.) The code, ...
Marco Kuhlmann's user avatar
4 votes
0 answers
803 views

fancyvrb + listings inside a list

I'm trying to put Verbatim environment from fancyvrb package, with activated interface to listings package, inside enumerate environment. When Verbatim environment is first element in \item, item's ...
jkuczm's user avatar
  • 1,391
4 votes
0 answers
4k views

listings: How can I highlight Makefiles?

I am trying to typeset a makefile using listings. Now I would like some differential highlighting, e.g. for variables and ordinary commands in the target body. In this snippet, want to have different ...
oarfish's user avatar
  • 1,419
3 votes
0 answers
157 views

Fix space for the punctuation (like comma and period) by using listings.sty

My tags are follows: \documentclass{book} \usepackage{listings} \lstset{ language=java, emph={}, mathescape=false, escapechar=`, % backgroundcolor=\color{lightgray}, commentstyle=\color{...
MadyYuvi's user avatar
  • 13.7k
3 votes
0 answers
183 views

gobble option of listing when used via tcolorbox

I use tcolorbox + listings to display code in a box. I pass a gobble option to listings, which seems to be plainly ignored: \documentclass{article} \usepackage[listings]{tcolorbox} \begin{document} ...
Michel Charpentier's user avatar
3 votes
0 answers
1k views

How make a LaTeX document that generates a PDF from which copy-paste works correctly for empty lines and leading space indentation?

We are writing a PDF document in LaTeX that contains various installation instructions and other technology text. Our idea is that the user reads various instructions in Serif font and then there's ...
Geek's user avatar
  • 31
3 votes
0 answers
369 views

underfull hbox when using caption+listings in enumeration

I'm getting a weird underfull hbox linked to the caption when having a listing inside an enumeration : \documentclass[a4paper,11pt]{article} \usepackage{caption} \usepackage{listings} \lstset{...
Emmanuel's user avatar
3 votes
0 answers
89 views

Importing code files with unicode using listings

I've written a program in python, about 2500 lines in total, that I wish to include segments from into my report. Normally I use listings to do that but in this case, the .py files include many ...
Kajsa's user avatar
  • 677
3 votes
0 answers
283 views

Syntax highlighting broken on multiline macros of C code listing

Using the listings and color packages, I can get syntax highlighting on a C code listing quite easily: \documentclass{article} \usepackage[usenames,dvipsnames]{color} %% Allow color names \...
GnP's user avatar
  • 131
3 votes
0 answers
984 views

Syntax highlighting of (Cisco) terminal

I want to highlight a complete terminal flow, mostly for the Cisco CLI, but Bash would be nice, too. As for now, the result achieved with the package lstlisting looks as follows: I achieved that with ...
user avatar
3 votes
0 answers
396 views

Using \lstinline inside an \item in beamer class in case of incremental overlay specifications?

The answers of Using \lstinline inside a \item work rather nicely with the beamer class. But, as pointed out by the following MCEs when \beamerdefaultoverlayspecification{<+->} is uncommented, ...
Denis Bitouzé's user avatar
3 votes
0 answers
231 views

side-by-side inputlisting in landscape over multiple pages

I'm pretty new to (la)tex, and working on a document right now in which I wanted to have two inputlistings side-by-side in landscape mode. The problem now is that with this code: \documentclass{...
hansOlaf's user avatar
3 votes
0 answers
480 views

listing with color and strike-through remaks

I want to show a code listing with some block in green (code additions) and other ones in red and strike-through (code removed). This is what I have until now: \documentclass{article} \usepackage{...
pasaba por aqui's user avatar
3 votes
0 answers
123 views

Displaying a copy-pastable and well structured BibTeX key in my document

Context: I want to insert the BibTeX entry of my document at the beginning thereof. I thus want this code snippet meet two criteria: Be easily copy-paste-able (code seen = code copy-pasted) Looks ...
ebosi's user avatar
  • 11.7k
3 votes
0 answers
144 views

How to Mimic Line Breaks from listings in minted

I'm like the syntax highlighting of minted but cannot get it to mimic the "more pleasing" line breaks for long code strings found in listings. In the example below, I have three snippets: the first ...
Erich Peterson's user avatar
3 votes
0 answers
108 views

Listing auto indentation of custom language

Using listing a custom language is defined and auto indentation is defined. The MWE does not do the indentation \documentclass{book} \usepackage[formats]{listings} \usepackage{xcolor} % Define ...
Johan's user avatar
  • 433
3 votes
0 answers
233 views

Listings clean background

I am using the listings package to display code in a document. Now I noticed that there are lines in the background. Does someone know how to remove them? Config: \lstset{ basicstyle=\scriptsize\...
Phill93's user avatar
  • 55
3 votes
0 answers
107 views

Lstlisting - define other color for pre-postfix names

I am using the listings package and try to define my own XML style. It looks like this: \lstdefinestyle{webxml}{% language=XML, tagstyle=\color{purple}, keywordstyle=[1]{\color{red}}, keywordstyle=[2]...
dokukaefer's user avatar
3 votes
0 answers
1k views

Listing cut and paste in PDF

I am trying to get good copy-n-paste'able text from a LaTeX generated PDF using the listings package. I have three listings that all behave not as I'd like: Long lines are broken using breaklines ...
jamtur01's user avatar
  • 281
3 votes
0 answers
2k views

Swedish letters ÅÄÖ do not show using listings package

Problem I am using the listings package to produce HTML-code and everything works except that the letters åäö do not format in accordance to the defined colors. Minimal Working Example \...
kexxcream's user avatar
  • 2,815
3 votes
1 answer
1k views

Latex highlighting error for lstinline

it has been quite a while that I have this problem and I have searched everywhere online and couldn't find a solution. The problem is latex syntax highlighting doesn't work after this line: \...
Sam Gold's user avatar
3 votes
0 answers
3k views

Syntax Issues with lstdefinelanguage

I have some issues defining a new language for the lstlisting package. The source code shall look like this in the end: And my latex definition looks like this atm: \documentclass[]{article} \...
Avinta's user avatar
  • 165
3 votes
0 answers
152 views

tex4ht and listings: lines don't break when using escapeinside

This is the first I'm posting a question. So, I hope I don't do anything wrong. I've tried to get HTML from my latex document by using tex4ht. For cross-referencing within the lstlisting environment, ...
Daniel's user avatar
  • 31
3 votes
0 answers
419 views

minted or listings input a file between markers

Is it possible, using the minted or listings package to format a file between or till a certain textual marker automatically. E.g. consider a source file: code code //marker code ... //end marker ...
Pieter Stroobants's user avatar
3 votes
0 answers
139 views

Unicode and listings - still no luck

Although there are already some discussions on this issue, I can't get any of the proposed solutions to work for me. Take this document and compile it with xelatex: \documentclass[12pt,a4paper,parskip=...
Matthias's user avatar
  • 365
2 votes
1 answer
71 views

How can I extend properties of \lstdefinestyle?

I am importing multiple python scripts into my tex file. I previously had one huge \lstdefinestyle definition which included options for all the specific functions, variables, etc across all my ...
DavidG's user avatar
  • 21
2 votes
0 answers
140 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 ...
bruno cuconato's user avatar
2 votes
0 answers
44 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 @ ...
Bermudes's user avatar
  • 121
2 votes
1 answer
215 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
  • 657
2 votes
0 answers
125 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 ...
Gianni Spear's user avatar
2 votes
0 answers
218 views

Remove spacing around lstlisting in beamer blocks

Consider the lstlisting in this MWE. (I have added normal text and itemize environment blocks for comparison.) \documentclass{beamer} \usetheme{Warsaw} \usepackage{listings} \begin{document} %\...
Olivier Cailloux's user avatar
2 votes
0 answers
211 views

Put \lstinline inside \item[] description and automatically add \item[] content to a glossary

I've implemented this solution to allow placing \lstinline code inside description \item command. I also want to automatically add the entire \item content as a glossary entry by placing it into name ...
Alberto López's user avatar
2 votes
0 answers
187 views

Code highlight in ltxdoc documentation

I wish to add LaTeX code highlight in a package documentation. Usually I use the following code to highlight LaTeX code (copied from classicthesis documentation): \usepackage{listings} \definecolor{...
Jinwen's user avatar
  • 8,528
2 votes
0 answers
251 views

How can color of a default parameter in call, be changed like PyCharm?

I am working on a document that contains some Python codes. I use the following template in Overleaf. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \usepackage{xcolor} %...
Loghman's user avatar
  • 121

1
2 3 4 5
8