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
119 votes
4 answers
363k views

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
35 votes
5 answers
9k 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 ...
Petra's user avatar
  • 351
83 votes
7 answers
76k views

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
31 votes
8 answers
27k views

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
58 votes
5 answers
44k views

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
63 votes
6 answers
23k views

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,286
54 votes
5 answers
59k 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 ...
Denilson Sá Maia's user avatar
30 votes
4 answers
16k 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 ...
DELETED PROFILE's user avatar
112 votes
4 answers
230k views

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,734
101 votes
2 answers
137k views

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
21 votes
1 answer
5k views

Listings package: How can I format all numbers?

I want to highlight all the numbers appearing in an input code of a certain program by, for example, coloring them. By numbers I mean integer, rational and floating point numbers. I am trying with the ...
Rafa Gallego's user avatar
59 votes
1 answer
77k views

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
  • 693
43 votes
2 answers
49k views

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
26 votes
3 answers
14k views

How to make overlay still work inside lstlisting environment?

Problem I want to explain C# programming language step by step using overlay in beamer.cls. But it does NOT works as shown in the following figure. How to solve this problem? Code Snippet \...
Display Name's user avatar
  • 46.9k
58 votes
5 answers
56k views

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
26 votes
1 answer
3k views

Problem with literate and breaklines=true in listings package

As the title says, the option breaklines=true seems to have an undesired interaction when using literate; in the following example the closing parenthesis doesn't get colorized \documentclass{...
Gonzalo Medina's user avatar
23 votes
2 answers
15k views

Coloring digits with the listings package

I'm trying to typeset some python code, and I would like integer literals to be highlighted. I've come up, after about two hours of fighting with the documentation and various other questions here and ...
Clément's user avatar
  • 4,004
19 votes
1 answer
8k views

lstlisting in a newenvironment

I have a problem with the lstlisting package. I want to define an \newenvironment with one obligatory parameter, which will be the caption name for the lstlisting. I will also have other lstlisting ...
Pjanc Matuzl's user avatar
17 votes
1 answer
7k views

How can I change the color of digits when using the listings package?

I'm using the listings package and was already able to modify the color of the keywords and almost all elements I was interested in. The only thing that remains is the color of the digits. I'd like to ...
Nanoc's user avatar
  • 171
14 votes
2 answers
6k views

How can I define a custom listing environment?

I am trying to define an enviroment for a specific programming language, F#. Here's my code: \definecolor{bluekeywords}{rgb}{0.13,0.13,1} \definecolor{greencomments}{rgb}{0,0.5,0} \definecolor{...
Bent Rasmussen's user avatar
11 votes
3 answers
5k views

Why can lstlisting not be saved in a command?

This code fails with Emergency stop: \documentclass{scrbook} \usepackage{listings} \newcommand{\demo}{% \begin{lstlisting} foobar \end{lstlisting} } \begin{document} \demo \end{document} Why?
Matthias Pospiech's user avatar
56 votes
1 answer
5k views

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.2k
54 votes
5 answers
101k views

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
28 votes
4 answers
9k views

How to automatically skip leading white spaces in listings

This question led to a new package: lstautogobble (lstaddons bundle) For my programming lecture slides I heavily use the listings package with \lstnewenvironment to typeset source code. It's a ...
Daniel's user avatar
  • 37.5k
20 votes
2 answers
10k views

Escaping in \lstinline

There are several options for escaping LaTeX code in the lstlisting-environment. But this doesn't seem to work in \lstinline. I'd like to do something like this: \lstinline[escapechar=§]{§\textlangle§...
h0b0's user avatar
  • 5,417
9 votes
2 answers
3k views

How to copy/paste multiple spaces from lstlistings?

This is a continuation of a question that I asked already: How to copy/paste from lstlistings?. The solution presented there does not work if the text within the lstlistings environment contains ...
maurera's user avatar
  • 381
5 votes
1 answer
552 views

Textcase, Listings, and Tilde

Consider the following MWE: \documentclass{scrreprt} \usepackage{textcase} \RequirePackage{listings} \usepackage[american]{babel} \begin{document} \MakeTextLowercase{A~B} \end{document} LaTeX ...
user1742364's user avatar
76 votes
4 answers
6k 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, ...
kiss my armpit's user avatar
36 votes
1 answer
23k views

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,758
35 votes
2 answers
49k views

\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,032
21 votes
2 answers
5k views

tcolorbox - list of listings?

In a book with figures, tables and listings, I figured out that all listings and some tables and figures look better when presented in a tcolorbox. The book has the usual tables of contents: \...
user17106's user avatar
  • 907
87 votes
3 answers
157k views

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,167
62 votes
5 answers
87k views

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
39 votes
6 answers
60k views

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
39 votes
8 answers
36k views

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
18 votes
4 answers
11k views

Adding background color to \verb or \lstinline command without \Colorbox

Update: In addition to my previous post, here's a screenshot to give you a better visual example. This was created with HTML and CSS for demo only. In CSS, the code part is made using font-family: ...
guest_5758's user avatar
16 votes
3 answers
9k views

Unwanted White Lines in listings environment

\documentclass{article} \usepackage{listings} \usepackage{color} \begin{document} \definecolor{light-gray}{gray}{0.95} \lstset{basicstyle=\ttfamily\footnotesize, backgroundcolor=\color{light-gray},...
Phil-ZXX's user avatar
  • 1,737
14 votes
1 answer
4k 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} \usepackage[...
Micha's user avatar
  • 2,869
13 votes
1 answer
3k views

produce copy-paste-able pdf output with correct indentation with listing

Here is a block of latex code to produce some Python code. I'd like to be able to copy and paste it into Python. \documentclass{standalone} \usepackage{listings} % Include the ...
Joel's user avatar
  • 2,419
9 votes
1 answer
3k views

How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets?

How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets? E.g. using \bh and \eh commands from Highlight text in code listing while also keeping syntax ...
Eugen Labun's user avatar
95 votes
3 answers
87k views

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
94k views

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
55 votes
2 answers
92k views

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,545
41 votes
2 answers
13k views

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
34 votes
4 answers
9k views

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
30 votes
2 answers
41k views

Defining `lstset` parameters for multiple languages

I am using the listings package, and have defined lstset parameter sets for multiple programming languages. I would like to select a parameter set when beginning a lstlisting or lstinputlisting by ...
user001's user avatar
  • 7,934
28 votes
2 answers
19k views

How best to include programming source code in LaTeX documents? [duplicate]

Possible Duplicate: Syntax Coloring in LaTeX I'm relatively new to LaTeX, and am starting to use it for academic paper writing. I'm doing a lot of computer programming as part of my academic work,...
robintw's user avatar
  • 7,342
25 votes
1 answer
5k 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 ...
Matthias Pospiech's user avatar
24 votes
3 answers
9k views

Colored background in inline listings

I would like to make inline code more distinguishable from the text surrounding it, and I thought that using a background might work (like it is done on the stackexchange pages.) Since I use the ...
xubuntix's user avatar
  • 799
16 votes
1 answer
3k views

How to show similar display of codes of different programming languages in LaTeX

I am very new to LaTeX and I am writing my thesis. In a chapter, I want to show my codes, which are in Mathematica. I use the listings package as follows: \documentclass{article} \usepackage{...
enthu's user avatar
  • 3,795

1
2 3 4 5
19