{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.
12
votes
2answers
1k views
How to insert code and graphic in textbox
I want to put a graphic and a little linux bash code in a textbox, like the picture blow...
with the follow in problem:
all in a textbox with yellow backgroud
left part is a graphic (a finger)...
...
8
votes
3answers
2k views
How to make listings code indentation remain unchanged when copied from PDF?
So I am using listings package for code examples. But there is a problem. When I copy the code examples from the final PDF document, they are usually not the same - the indentation is gone, there are ...
7
votes
2answers
499 views
Listing language for “screen session”
I am writing a set of tutorial documents on some command-line based tools. This tutorials need to show a "screen session". Something along the lines of:
$ git status
# on branch "master"
I want to ...
7
votes
2answers
837 views
Grouping the list of listings by chapter
I am using the listings package. I want to print out a list of listings, which I can do. The thing is that in the other listings the typesetter "groups" figures/tables by chapter. Is it possible to ...
6
votes
2answers
187 views
How do I prevent conflicts between accsupp and hyperref?
This question is related to the answer to the question Is there a LaTeX trick to prevent a PDF viewer from copying the line number?
Unless you turn hyperref off, the following MWE
...
5
votes
2answers
358 views
Position tikz pictures at left margin of a listing code block
I'm trying to finish my attempt at having good looking unlimited line annotations for the listing environments, using tikz. The original problem was that indentation caused shifts in the positioning, ...
5
votes
1answer
812 views
In listings, how to show referenced linenumbers instead of standard ascending linenumbers
I'm just writing on my master thesis and have a (specific) problem with lstlisting package in LaTeX.
I'm referring to the Random.class-file in Java and only want to print some specific line-ranges, ...
4
votes
1answer
115 views
How to accept three different languages on lstlisting
How to accept three language different?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{xcolor,tikz}
\usepackage{showexpl} % exibe ...
13
votes
4answers
4k views
Using \ttfamily with \bfseries (or how to enable bold in fixed-width font)
I'm using listings package, and I've added basicstyle=\ttfamily\footnotesize. However, when I do that, the keywords from the embedded source-code are not bold anymore.
I figured that \ttfamily ...
9
votes
1answer
246 views
Background images for code listings
I've been searching around but I can't find any info for adding an image background for my code listing using the listings package. Is there a way to do this?
8
votes
3answers
5k views
How to use different lstset settings for listings?
I would like to specify two different lstset settings in one latex file: one for java code, one for html. Is this somehow possible?
The solution of ...
8
votes
1answer
1k views
Package to indent and syntax highlight C++ code
I am looking for a package to have an environment for C++ source code, with options for syntax highlighting, automatic indentation, proper multipage behavior, etc.
I read something about the listings ...
7
votes
3answers
627 views
Problems with copy and paste from PDF using lstlisting
I'm using lstlisting to create course notes from which I am hoping that code can be copy&paste'd I've already implemented the suggestions in
Phantom spaces in listings (pdf) to make sure that ...
7
votes
1answer
400 views
How to make listings code correct copyable from PDF and with hyperlink
If I generate listings code with line numbers and copy the result from the PDF I can not use it again as tex code. First the line numbers are included which they should not, second spaces are included ...
6
votes
2answers
61 views
How to refer to the count value of number of lines in a lstlisting
I need to refer to to the count value of the number of lines in a listing. Is there a way to do that ?
\lstinputlisting[caption={SPARQL query used...},label={lst:sqry}]{codes/sparql_query.sparql}
...
6
votes
2answers
1k views
The 'listings' package and UTF-8
Please, do you know if there's any possibility how to use the listings package together with XeLaTeX? I have to use XelaTeX and therefore I have UTF-8 encoded files. This is not compatible with ...
5
votes
1answer
434 views
listings bug: space after literate replacement lost with spaceflexible/fullflexible columns
Problem with space being lost in listings immediately after a literate replacement when using columns=spaceflexible or columns=fullflexible (appears correctly with columns=flexible). A small example ...
3
votes
1answer
74 views
Multiple listings styles
In using the listings package, how can I have a distinct \lstlistingname value for each type of listing.
Lets say my document has C++, R and Pseudo listings, and I would like the \lstlistingname ...
3
votes
1answer
664 views
Showing only specific lines using the listings package
I am very new to TeX.
My source code is in an external file, let's call it source.java, and I use \lstinputlisting{source.java}.
How could I use only the lines 3-5 for my code listing? (and not the ...
3
votes
1answer
553 views
\newenvironment fails with special listings environment
I want to use the showexpl, but define a new environment with predefined settings. But all I get is an emergency stop.
\documentclass{scrbook}
\RequirePackage{showexpl}
...
2
votes
1answer
3k views
Package listings: Error “Undefined control sequence.” because of single-quote-symbol?
I'm using the package listings and came across a problem displaying an SQL statement within an java environment. This is the MWE.
\documentclass[]{report}
\usepackage{listings}
...
2
votes
1answer
3k views
Adding C++ code in Latex
So I am adding some C++ code snippets in my document using
\lstset {language=C++}
\begin{lstlisting}
for (int i=0; i<iterations;i++)
{
do something
}
\end{lstlisting}
My issue is that the font ...
1
vote
1answer
196 views
lstaddons: Dynamic linewidth calculation
I use the package called "lstaddons" (creator, initial question) to get colored line backgrounds on listings.
I want to color the whole line to the frame.
What I miss there is a dynamic calculation ...
0
votes
1answer
2k views
How to prevent beamer from removing the tab alignment of lstlisting?
I want to show my C# code snippet on the presentation slides using beamer.
Because the code is long, I set the frame to be breakable using the frame option allowframebreaks. The code now can be shown ...
8
votes
1answer
366 views
Listings package does not break
The following code does not break even though the breaklines and breakatwhitespace is set:
\lstset{
language=XML,
numbers=left,
numberstyle=\tiny\color{gray},
stepnumber=1, ...
7
votes
1answer
4k views
How to change code example font in listings?
Does anyone know how to change the font for code snippets in the listings package? I'd like to have a constant width font, rather the fancy variable-width looking font that it has by default.
6
votes
0answers
131 views
UTF8 for listings
With German umlauts I have to define these characters (Typesetting UTF8 listings with German Umlaute) and the following MWE is working:
\documentclass{article}
\usepackage[utf8]{inputenc}
...
6
votes
2answers
315 views
How to add numerical (ala No Starch Press) listing notes without XeTeX?
I've been following the instructions and code available at:
https://zuttobenkyou.wordpress.com/2010/12/05/latex-saner-source-code-listings-no-starch-press-style/
I would like to add notes (and style) ...
6
votes
1answer
201 views
How to emphasize within a listing two successive identifiers separated by a space?
I have this pgfplots code that I want to put in a lstlisting environment:
\pgfplotsset{
every axis x label/.append style = {
font = \small
},
every axis y label/.append style = {
...
6
votes
1answer
1k views
How can I ensure that a listing is not going to be split?
How can I ensure that a listing is not going to be split? If it is going to be split I want that the entire listing to move to the following page, effectively moving everything at pass. I mean any ...
5
votes
2answers
384 views
Increase space between listings env. and surrounding text
How can I set the space between a listing (lstlisting) and text that surrounds it? Is there a parameter I can set at the beginning of my document, that controls this? I tried framesep, but it just ...
5
votes
2answers
952 views
Background overflows when using rounded corners for listings (package: `listings`)
I'm using listings to list code in my document, and I want the code to be displayed in a frame with rounded corners and a grey background color. But the background overflows the frame, as if the frame ...
5
votes
1answer
723 views
Displaying two XML listings side by side.
I have two XML outputs from a program that I would like to include in a LaTeX document. I would like them to appear side-by-side each in its own box. So that a reader can compare the two outputs while ...
5
votes
3answers
306 views
How to skip both the first n rows & the last m rows simultaneously?
I am using showexpl.sty to display side by side the code snippet and its corresponding output.
Because of the paper size limit, I intentionally want to remove the "redundant" rows, i.e., the first n ...
4
votes
1answer
262 views
remove unwanted contents from list of listings
The following code adds a wrong line to the list of listings
\documentclass{scrbook}
\usepackage{listings}
\usepackage{filecontents}
\begin{document}
\begin{filecontents*}{democodefile}
...
4
votes
2answers
2k views
\lstinputlisting will not continue to next page
So I have this LaTeX snippet:
\section{Appendix}
\listoffigures
...
\begin{center}
\begin{figure}
\caption{MacroCell with 8 AND Gate Arrays}
...
4
votes
2answers
837 views
Fixed Width Font with LTXexample environment
Not sure why this problem has eluded me but I can't seem to get fixed width font in the code portion. I thought that this question on how to change code font would do the trick but it doesn't for me. ...
4
votes
1answer
849 views
`backgroundcolor` in `lstset` does not work
When I use the backgroundcolor option in lstset, all I get is a colored line above the listing:
\lstset{%
language=Matlab,
backgroundcolor=\color{blue}
}
and in the document:
...
4
votes
2answers
856 views
Listings alternative
Well like the title says I am asking if there is an alternative to the listings package. With more programming language definitions and the likes, and updated definitions for the current languages.
4
votes
2answers
2k views
Can I get a shadowbox with rounded corners? (using `listings` package)
I'm using the listings package as below:
\usepackage{listings}
\lstnewenvironment{pythoncode}[1][]
{\lstset{language=Python,
basicstyle=\ttfamily\footnotesize,
frame=shadowbox,
...
3
votes
1answer
92 views
odd displays of accentuated characters in lstlisting environment
when i try to write accentuated characters (éà...) in a lstlisting environment,
hence :
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
...
3
votes
1answer
529 views
Highlight language keywords in a paragraph?
While it is possible to highlight specific language keywords (such as public in C++) by using lstinline command from listing package as in:
Highlighting a C++ keyword \lstinline|public| in a ...
3
votes
2answers
394 views
How to avoid that listings are interrupted by floats?
And again I have another problem I just can't figure out. I defined a listing with some XML code:
\begin{lstlisting}[captionpos=b, caption=XML detection strategy for Refused Parent Bequest, ...
2
votes
1answer
108 views
Syntax highlighting for different programming languages [duplicate]
In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package:
\lstset{frame=tb,
language={[Visual]Basic},
aboveskip=3mm,
belowskip=3mm,
...
2
votes
2answers
179 views
listings: General settings for a language seem to be overwritten/not respected
I struggle with the following listings styles. I have code of two different languages
(R and LaTeX) in my .tex file. As some settings are the same for R listings and
LaTeX listings, I define the style ...
2
votes
1answer
828 views
cleveref + listings
\documentclass{scrbook}
\usepackage{listings}
\usepackage{cleveref}
\begin{document}
Ref: \ref{test}.
Cref: \cref{test}.
\begin{lstlisting}[caption={Test},label={test}]
test
\end{lstlisting}
...
2
votes
0answers
99 views
listings bug: space after quote collapsed when inlined with spaceflexible/fullflexible columns [duplicate]
Possible Duplicate:
listings bug: space after literate replacement lost with spaceflexible/fullflexible columns
I seem to have stumbled upon a minor bug in listings (version 1.4 as of ...
47
votes
3answers
986 views
Is there a LaTeX trick to prevent a PDF viewer from copying the line number?
A PDF output is obtained by compiling the following code.
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset
{
language={[LaTeX]TeX},
numbers=left,
...
15
votes
3answers
2k views
Preferred method for inline code samples
I tend to use the minted package for including code samples within my documents, which produces very nice output. However, because Pygments always produces a verbatim environment there's no way to ...
9
votes
2answers
174 views
Any way to show LaTeX example code *and* execute it? [duplicate]
In (La)TeX documentation and tutorials, it is common to show a snippet of code next to the output it generates. It might be two minipages side by side, or a code listing followed by boxed output, or ...
