In the introduction a basic example of the package listings was presented, let’s see a second example. You can use the option literate to modify the output: \documentclass[a4paper, 10pt]{article} \usepackage[utf8]{inputenc} \usepackage{listings}. Code listings in LaTeX. “Pretty” code listings are sometimes considered worthwhile by the “ordinary” programmer, but they have a serious place in the.

Author: Fenrilabar Sharn
Country: Botswana
Language: English (Spanish)
Genre: Spiritual
Published (Last): 4 April 2006
Pages: 353
PDF File Size: 5.28 Mb
ePub File Size: 12.69 Mb
ISBN: 622-1-72907-417-1
Downloads: 57049
Price: Free* [*Free Regsitration Required]
Uploader: Minos

L a T e X is widely used in science and programming has become an important aspect in several areas of science, hence the need for a tool that properly displays code.

In this article is explained how to use the standard verbatim environment as well as the package listingswhich provide more advanced code-formatting features.

Displaying code in L a T e X is straightforward. For instance, using the lstlisting environment:. In this example, the outupt ignores latsx L a T e X commands and the text is printed keeping all the line breaks and white spaces typed.

To use the lstlisting environment you have to add the next line to the preamble of your document:. Open an example of the listings package in ShareLaTeX.

Code listing

The default tool to display code in L a T e X is verbatimwhich generates an output in monospaced font. Just as in the example at the introduction, all text latwx printed keeping line breaks and white spaces. There’s a starred version of this command whose output is slightly different. Open an example in ShareLaTeX. In the introduction a basic example of the package listings was presented, let’s see a second example:.

listings – How to typeset – – with lstlisting package? – TeX – LaTeX Stack Exchange

See the reference guide for a complete list of supported programming languages. Code is usually stored in a source file, therefore a command that automatically pulls code from a file becomes very handy.

If you need to import only part of the file you can specify two comma-separated parameters inside the brackets.

For instance, to import the code from the line 2 to the line 12, the previous command becomes. If firstline or lastline is omitted, it’s assumed that the values are the beginning of the file, or the bottom of the file, respectively. The package xcolor also works for this.

For more information see: Just like in floats tables and figureslstliting can be added to a listing for a more clear presentation. This caption can be later used in the list of Listings.

Contents 1 Introduction 2 The verbatim environment 3 Using listings to highlight code 4 Importing code from a file 5 Code styles and colours 6 Captions and the list of Listings 7 Reference guide 7.

Author: admin