Skip to main content

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
120 votes
4 answers
367k 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,947
35 votes
5 answers
10k 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
88 votes
7 answers
79k 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
28k 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
61 votes
5 answers
45k 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
64 votes
6 answers
24k 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,306
53 votes
5 answers
60k 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 ...
user avatar
114 votes
4 answers
241k 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,754
103 votes
2 answers
142k 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,267
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
61 votes
1 answer
79k 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
  • 713
44 votes
2 answers
51k 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
  • 443
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
  • 47.2k
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
58 votes
5 answers
58k 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
  • 17.1k
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
16k 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,024
21 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,577
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
7k 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
12 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
11 votes
2 answers
1k 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 \documentclass{...
kiss my armpit'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.4k
55 votes
5 answers
106k 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.7k
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
  • 391
5 votes
1 answer
554 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
39 votes
6 answers
61k 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
37 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,838
35 votes
2 answers
50k 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,062
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
90 votes
4 answers
73k views

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,066
90 votes
3 answers
160k 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,237
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
62 votes
5 answers
88k 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
41 votes
8 answers
37k 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
  • 565
18 votes
4 answers
12k 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,767
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
14 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,449
9 votes
1 answer
3k views

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

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
100 votes
3 answers
90k 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
95k 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
56 votes
2 answers
98k 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,565
43 votes
2 answers
14k 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
  • 699
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
29 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,492
29 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,994
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

1
2 3 4 5
19