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
130 votes
2 answers

How to change font size for specific lstlisting

I have a java lstlisting and it is too big and does not mach a single page. Is there any way to specify font for specific listing, not all listings in document?
Korniltsev Anatoly's user avatar
119 votes
4 answers

What can I use to typeset MATLAB code in my document?

This question led to a new package: matlab-prettifier Does anybody have a quick and easy way to typeset some relatively long MATLAB code in the appendix? I looked up a few methods, and the mcode ...
suzu's user avatar
  • 1,917
111 votes
4 answers

How to highlight Python syntax in LaTeX Listings \lstinputlistings command

I am using package listings to import my Python source code into my LaTeX document. I use the command \lstinputlistings. I have a Python source like class Child(Parent): def __init__(self, *args, *...
fmonegaglia's user avatar
  • 1,724
101 votes
2 answers

lstlisting line wrapping

How is it possible to let lstlisting wrap lines? I've troubles with following block: \begin{lstlisting}[language=java] public class MeasureStationControllerV0Test { MeasureStationControllerV0 ...
MemLeak's user avatar
  • 1,247
94 votes
3 answers

Avoid page breaks in \lstlistings

I'm trying to avoid page breaks in my lstlisting (seen in section 0.0.2) I know I can remedy this by floating my lstlisting, but it adds some unwanted white space (seen in section 0.0.1). Is there ...
blitzvergnugen's user avatar
88 votes
4 answers

How to format an inline source code

I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options ...
Steves's user avatar
  • 1,013
87 votes
3 answers

Using \lstinputlisting to include a file but only certain lines or line ranges

I wanted to tidy up a TeX document and was curious if you can use \lstinputlisting or a similar function to include a certain part of a source-code file. Example, I have a 500 or so line source file ...
Supernovah's user avatar
  • 1,036
87 votes
2 answers

Reference to a listing returns wrong number

I'm using the following code to create a listing with sourcecode: \begin{lstlisting}[caption={caption_text}\label{lst:a_label},language=Java] // Code... \end{lstlisting} Unfortunately, a \ref{lst:...
alapeno's user avatar
  • 973
86 votes
3 answers

set the font family for lstlisting

I have the following set up for my listings : \lstset{basicstyle=\footnotesize,breaklines=true} \lstset{framextopmargin=50pt,frame=bottomline} I would like to change the font family to Courier. How ...
tugberk's user avatar
  • 4,127
83 votes
7 answers

Having problems with listings and UTF-8. Can it be fixed?

I'm having some problems with listings and UTF-8 in my document. Maybe someone can help me? Some characters work, like é and ó, but á and others appear at the beginning of words... \documentclass[...
KramerTheCat's user avatar
76 votes
1 answer

How to put the caption below the listing?

When I use a simple caption, tex puts it above the listing \begin{lstlisting}[caption={My Caption}] \end{lstlisting} If I use \captionof, caption goes below the listing, but paragraph for next line ...
Rostislav Shtanko's user avatar
74 votes
4 answers

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, ...
kiss my armpit's user avatar
68 votes
2 answers

minted vs. texments vs. verbments

Regarding the typesetting of syntax-colored source code, I know that listings is inferior because it doesn't utilize a full lexer. Instead the Python-based solution is recommended. It seems there are ...
marczellm's user avatar
  • 11.7k
62 votes
5 answers

XML syntax highlighting

I use the following code to include some XML code: \lstset{language=XML} \begin{lstlisting} <?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" ...
RoflcoptrException's user avatar
62 votes
6 answers

Syntax Coloring in LaTeX

Is there any way to include Python code in a LaTeX file and automatically color its syntax? Is it possible to do syntax coloring with any other language? If yes what packages can I use to do that?
Mark's user avatar
  • 1,276
58 votes
5 answers

Extend a language with additional keywords?

I'm using listings and I want to extend a language with additional keywords for highlightning. I know there is an option morekeywords available, but that only works for a particular lstset declaration ...
gablin's user avatar
  • 16.9k
58 votes
6 answers

\autoref does not capitalize initial character in sentence when referencing label in listings environment

I have defined the following \providecommand*{\lstnumberautorefname}{line} and within my text \begin{lstlisting} |\label{sdd_1}|<sqlCallStatistics>YES</sqlCallStatistics> \...
user9131's user avatar
  • 865
58 votes
1 answer

Can't insert code in my beamer slide

I want to put some PHP code in my slide with the package listings but I have this error message: Argument of \frame has an extra }.<inserted text>\par } My latex code : \documentclass{beamer}...
Juanwolf's user avatar
  • 683
57 votes
5 answers

How can I highlight some lines from source code?

I am preparing a presentation (using beamer) and I'll need to include many snippets of source-code. For including source code, I'll probably use listings package. (I know there is also minted package, ...
Denilson Sá Maia's user avatar
56 votes
1 answer

Creating a zebra effect using listings

This question led to a new package: lstlinebgrd (lstaddons bundle) Friends, consider the following example using the listings package: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{...
Paulo Cereda's user avatar
  • 44.1k
54 votes
5 answers

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 ...
Denilson Sá Maia's user avatar
54 votes
2 answers

minted vs. listings: pros and cons

While I'm switching from minted to listings, I would like to ask you for this comparison. The following is what it comes to my mind till now: minted needs Pygments to work, listings does not (this ...
CarLaTeX's user avatar
  • 61.2k
53 votes
2 answers

How to improve listings display of JSON files?

I was wondering if there is a good way for JSON files to be listed with the listings package. The only language definition I could come up with, is this: \lstdefinelanguage{json} { morestring=[b]...
polemon's user avatar
  • 3,525
52 votes
5 answers

language option supported in listings

I am afraid that listing doesn't support javascript. \begin{lstlisting}[language=javascript] ... \end{lstlisting} What am I doing wrong?
user1592714's user avatar
51 votes
1 answer

How to use mathematical symbols in listing?

I want to use math mode in lstlisting. How do I do that? How to put tab in this mode? \begin{document} \begin{lstlisting}[frame=single] % Start your code-block module main() ...
tikzlearner's user avatar
  • 4,487
50 votes
5 answers

Has the time come for a LaTeX3 successor to 'listings'?

I'm currently looking for a nice and challenging open-source project to work/collaborate on after my thesis. I don't have a Comp. Sci. background, but I'd like to learn more about compiler ...
jub0bs's user avatar
  • 58.5k
49 votes
1 answer

listings: Copy to clipboard feature?

I was just wonder if it would be possible to have a "Copy to Clipboard Button" next to each listing which would just copy the verbatim content of the lstlistings environment to the clipboard. An ...
arney's user avatar
  • 2,003
45 votes
2 answers

How to change listing caption?

I have some listings that contain pseudo-code of algorithms. And I use this: \lstset{caption={Descriptive Caption Text},label=DescriptiveLabel} to add captions to them. My problem is that the ...
foobar's user avatar
  • 913
45 votes
1 answer

How do I add syntax coloring to my C++ source code in beamer

I have just learned how to insert source code into beamer with the listings package. However I dont know how to go about adding any syntax coloring on the C++ source code. How do I do that? Here ...
smilingbuddha's user avatar
44 votes
1 answer

Listings caption [duplicate]

I'm using the listings package with this \begin command: \begin{lstlisting}[caption=blabla, label=amb] This yields a nice code listing with a caption like "Listing 1.1 blabla". Is there a way to ...
user avatar
43 votes
2 answers

How to center a listing?

I'm trying to get some console output in my homework. I put it in a listings environment but I want it to be centered horizontally on the page. The only thing I get centered is the caption ;-/ \...
paraa's user avatar
  • 433
42 votes
1 answer

Lstlistings reference to line number

How can I place a 'label' marker inside a lstlisting environment (external file imported and formatted via the listinputlisting command) so that I can cross-reference a particular line number? In ...
Nicholas Hamilton's user avatar
41 votes
4 answers

How to prevent lstlisting from splitting code between pages?

Is it possible to prevent lstlisting from splitting a code between pages if it does not fit on one page? Instead splitting I would like to have the code on the next page. I tried to put all ...
czuk's user avatar
  • 563
41 votes
2 answers

How to have straight single quotes in lstlistings

All single quotes in code samples are displayed as backticks and the copy-pasted code can't be compiled without fixing the quotation. Is it possible to prevent this? for example: \documentclass{...
perreal's user avatar
  • 679
40 votes
2 answers

How can I make lstlisting look exactly like verbatim?

I like the way the verbatim environment looks, and I want to make my lstlistings look like it. I've tried setting the basic style to \ttfamily, but the letter kerning and line spacing seem to be ...
csl's user avatar
  • 757
39 votes
8 answers

How to insert code with accents with listings?

I'm trying to insert source code in LaTeX with using listings, but my code has accents and pdflatex gives me this error: Unicode char \u8:�\expandafter not set up for use with LaTeX. This is a code ...
kevinz's user avatar
  • 545
39 votes
2 answers

Inline code and short verb with minted

I it possible to use minted for inline code and to add a short verb sing for minted? Like \lstMakeShortInline| in listings.sty? \documentclass{article} \usepackage{minted} \newminted{tex}{} \...
Tobi's user avatar
  • 55.8k
39 votes
6 answers

Using bold/italic text inside listings?

How can I use bold text inside a code listing? I wanted to make some parts of the code bold.
Maiz's user avatar
  • 391
38 votes
4 answers

Shrink lstlisting frames to code content

I use lstlistings to include code in my document. I'd like my code to be framed and its frame to be adjusted to the size of the actual code content. Here is what I have as of now : \lstset{numbers=...
guigui's user avatar
  • 401
36 votes
2 answers

How can I typeset Julia code with the listings package?

I'd like to typeset some Julia code, syntax highlighting and all, with the listings package. For information, the Julia language is a strong contender for MATLAB, and is free and open-source. However,...
jub0bs's user avatar
  • 58.5k
35 votes
2 answers

\listings code style for HTML5 (CSS, HTML, JavaScript)

I would like to create a code style for HTML5 that can be used with the \listings package. An HTML5 document consists of three languages: CSS, HTML and JavaScript. That makes the whole thing a bit ...
Benny Code's user avatar
  • 3,022
35 votes
1 answer

How can I use LaTeX-commands inside of a listing?

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the ...
Konstantin Weitz's user avatar
34 votes
1 answer

Strange character when using listings package

I'm seeing an odd character like a very flat U, where there should be a space, with the listings package. See example below. Does anyone have any idea why this is happening, or how to get rid or work ...
Faheem Mitha's user avatar
  • 7,728
34 votes
2 answers

Indent a code listing in LaTeX

For a little LaTeX document I am writing I would like to insert source code fields (in SQL) into my paper. I found out that I can use the listings package for this, which works well so far: \...
florianbaethge's user avatar
34 votes
5 answers

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 ...
Petra's user avatar
  • 341
34 votes
4 answers

Phantom spaces in listings

I have a problem with SQL code in a PDF document. For code representation I'm using the listings package. Everything works perfect until I copy-paste that code from the created PDF document. I get ...
Mario Miler's user avatar
33 votes
4 answers

How can I get straight double quotes in listings?

My question is related to the following two How to have straight single quotes in lstlistings In the minted package, how do I enforce straight single quotes? but I'm specifically asking about double-...
wchargin's user avatar
  • 3,089
33 votes
1 answer

How can I highlight YAML code in a pretty way with listings?

I'm trying to highlight simple YAML (the markup language, not the CSS framework) code. I know that there is a solution using pygments and minted, however, I would prefer a solution with \...
user avatar
32 votes
2 answers

Ensure verbatim code block is copy/paste-able

After rendering a document containing this code block \begin{verbatim} if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist. if [ ! -f ]; ...
user avatar
31 votes
7 answers

Highlight text in code listing while also keeping syntax highlighting

I’m using the listings package for code listings. Now I try to highlight some part of the code using \hl from the soul package. Here’s an example of a resulting query where the injected part of a SQL ...
Gumbo's user avatar
  • 411

2 3 4 5