{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.

learn more… | top users | synonyms

2
votes
1answer
37 views

showexpl not showing caption of a lstlisting within

How can I make the LTXexample environment to show the caption (like it does with other environments) of a lstlisting that is inside it. Consider the following code \documentclass{article} ...
2
votes
1answer
68 views

Difference between fixed-width and proportional typewriter fonts in listings?

In the MWE below, I wonder why does the pcr (Courier) font align in both escaped and unescaped versions and for whatever column setting of {listing} - while the cmtt (Computer Modern Teletype) aligns ...
0
votes
1answer
37 views

Proper way to indicate code change in lstlisting

[Since the question was not clear] I have a piece of program code I would like to describe in my thesis. My problem is that the part I would like to explain is surrounded by simple code pieces not ...
9
votes
0answers
376 views

TeXLive and MikTeX behave differently in handling BOM

It is a followup of my answer that has been converted to comment (click) posted several decades ago. Shortly speaking, MikTeX does not remove leading BOM but TeXLive does as shown in the following ...
7
votes
0answers
38 views

Adding color package destroys listing centering

I am using @egreg's answer to make listings centered: \documentclass[a4paper]{book} \usepackage[T1]{fontenc} \usepackage[ hang, small, it, hypcap=true ]{caption} \usepackage{fancyvrb} ...
5
votes
0answers
52 views

Listings package - distinguish between […] and \[…\]

The listings package provides the option moredelim, allowing for custom styles for words enclosed by given delimiters. I would like to give $...$, \[...\] and $$...$$ custom colors. \[...\], however, ...
5
votes
0answers
36 views

How can I make a custom environment that wraps listings?

Thanks to this answer, I know it is possible to float and wrap text around a listing. I would like to setup an environment for mini-code snippets that always floats and wraps the same way. I can ...
5
votes
0answers
130 views

Preventing line break at the start of a long name in `\lstinline`

This question has developed from How to deal with very long lstinline-phrases like long class names?. That question is about line breaking inside a \lstinline phrase. I have provided an answer which ...
4
votes
0answers
61 views

(Clickable) cross-reference in lstlisting

To generate documentation for an 'application programming interface', I would like to have a syntax highlighted area (with the class declaration), which has clickable links to the documentation (which ...
4
votes
0answers
69 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: ...
3
votes
0answers
28 views

Using lstinline in caption of lstlistings with multicol?

Consider this MWE: \documentclass{article} \usepackage{multicol} \usepackage{listings} \begin{document} \def\extra{extra} \begin{lstlisting}[ multicols=2, caption={ [short] aaaa \extra, ...
3
votes
0answers
42 views

Relatives/absolute path for listing with subfiles

I have problem with path management. Let me explain you: I work with subfiles that are arranged in this way: REPORT --Main.tex --lab1 ----Matlab ------CodeLab1.m ----Report ------Report_P1_1.tex ...
2
votes
0answers
55 views

Different colours for each argument and value in listings

This recent question (Print blue brackets in one language and black in another) made me come up with (up to) two more questions regarding the listings package: Is there an option similar to opstyle ...
2
votes
0answers
66 views

\usepackage]{listings} - Overfull \box problem - Smaller characters/font?

I am using this LaTeX code to implement some Python code in my LaTeX generated pdf document. I am using \lstdefinestyle because I have multiple styles for different code that I want to implement in ...
2
votes
0answers
79 views

How can I apply different custom caption styles to different listings?

In the MWE below, is it possible to define different caption formats for the two listings? In the example the first listing should use a blue caption background (like it is now) while the second ...
2
votes
0answers
37 views

Line breaks inside inline code break syntax highlighting. Any workaround?

I want to have both code snippets ABC and ABC_DEF in red (in both cases only ABC is red). If I remove the literate line it works but I also want to have automatic line breaks at underlines. How can I ...
2
votes
0answers
60 views

penalize page breaks in \lstlistings

I have a document with some rather lengthy \lstlisting's (source code snippets). It looks really bad if there is a page break within a listing/snippet. Thus I tried to avoid page breaks in listings by ...
2
votes
0answers
371 views

Make arrows inside lstlisting

Inside my lstlisting environment I want to make the assignment symbol an arrow instead of =. How can I do that? Adding just \leftarrow doesn't work, because then the whole word is displayed.
2
votes
0answers
121 views

Show vertical line for indentation of LaTeX code listing

Is it possible to enable a continuous vertical line on code to show indentation? I am trying to use the following code from a stackoverflow question. Originally, the documentation suggests using ...
2
votes
0answers
217 views

How to make listings display characters special characters

I am trying to show a directory structure of a tree using the listings package like so: ├── controllers │   ├── application_controller.rb what I get looks like this: controllers ...
1
vote
0answers
36 views

Using listings to display regexes

Is there any way to use the listings package (which I already use for Python) to highlight regexes? I.e. the regex appears in the document as if it were source code, but with some form of ...
1
vote
0answers
34 views

Aligning listing frame width between two listings

I'm trying to get two listings side by side. One is shorter than the other, but I would like to have them aligned, meaning that the frame height of the short one should be longer to reach the baseline ...
1
vote
0answers
20 views

Work around 'Dimension too large' using `framed` with `listings`

I'm including an external source code file as an appendix using the listings package. The framed package is being used to ensure multi-page listings frames are fully closed. The problem is if my ...
1
vote
0answers
53 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): ...
1
vote
0answers
27 views

How to display a code using lstinputlisting that isn't separated with figures?

This is the code I used: \lstinputlisting[language=Python,breaklines=true]{seminar_ED.py} It works fine with displaying the code over multiple pages when I don't add other figures in the text. But ...
1
vote
0answers
41 views

List of Listings (LOL) multiple entries with the same name

I splitted some source code into various listing all with the same name "Company ontology" (to use the firstnumber=auto), now in my LOL I have multiple repeated entries, is there a way to solve, maybe ...
1
vote
0answers
65 views

How to include program listings in C# with custom font and syntax highlighting in LyX?

I'm rather new to LaTeX and use LyX editor to create my documents. There are similar questions but none of them answer how to do that in LyX. I am wondering, how to include a program listing in ...
1
vote
0answers
44 views

Center code in a lstlisting float

Out of pure laziness, I decided to create lstlisting floats with the option offered by the package: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \begin{document} ...
0
votes
0answers
66 views

Pandoc: Markdown to PDF: select code without select number into code block

i want to generate the code block and i try example and it work. but when i try to select the code from the pdf, the number also get selected. how to generate code block that when select the code w/o ...
0
votes
0answers
36 views

Layering/twocolumn conflict using tikzmark

LaTeX gurus, inspired by the ideas and code in Automatic background coloring in listings using tikzmark, I attempted to create my own macros for teaching programming. What I really wanted, just to ...
0
votes
0answers
43 views

How can I mimic the style of 'algorithm' in an 'lstlisting' environment?

In my LaTeX document, I have an algorithm added using algorithm and algorithmic: \documentclass{article} \usepackage{graphicx} \usepackage{apalike} \usepackage{setspace} \usepackage{amsmath} % ...
0
votes
0answers
97 views

interference listings styles in tcolorbox

I'm trying to create a package to encapsulate pstricks examples using tcolorbox and showexpl. Defined a new environment PSTexample and style for listings (mystyle) that does not interfere with ...
0
votes
0answers
78 views

Don't break lines at certain characters in lstlisting

Is it possible to configure lstlisting such that it doesn't break lines at certain characters? In this example, a line break is inserted after the opening parenthesis: public void someMethod( ...
0
votes
0answers
206 views

How to replace (unicode) characters by ü,ğ,ş etc.?

\documentclass[11pt,a4paper]{article} \usepackage[utf8x]{inputenc} \usepackage{ucs} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage[T1]{fontenc} ...
0
votes
0answers
122 views

multiple listing styles with hyperref and caption packages

This is a follow-up question to Multiple listings styles. The MWE from the accepted answer works fine. Unfortunately, when I add the hyperref package OR the caption package (or both of them), the ...
0
votes
0answers
75 views

How to undo the feasible breakpoints of `lstlisting`?

Is there a way to prohibit pagebreaking at the beginning/end of an lstlisting environment? I'm trying to keep together the following two pairs of lines: the first line of lstlisting and the line ...