• Tidak ada hasil yang ditemukan

The Listings Package

N/A
N/A
Protected

Academic year: 2023

Membagikan "The Listings Package"

Copied!
63
0
0

Teks penuh

He then turned over maintenance of the package to Brooks Moses, who volunteered for the job while this procedure went through. There is no intent of offense; the use is for the benefit of the trademark owner.

A minimal file

Typesetting listings

Like most examples, the following shows verbatim LATEX code on the right and the result on the left. To be compatible with such packages, all commands and environments in the summary package use the 'lst' prefix.

Figure out the appearance

Seduce to use

Other features There are still features that have not been mentioned so far: automatic breaking of long lines, the possibility to use LATEX code in listings, automated indexing or personal language definitions. But note that the output is not produced by the LATEX code on the right alone.

Alternatives

In addition, you can move line numbers to the left or right, use arbitrary LATEX code in the source code, print symbols instead of extended names, set font, and more. It supports standalone files, text and display lists, and you can even nest the commands/environments if you use LATEX code in comments, for example.

Package loading

The key=value interface

You must use these keys within the optional environment argument or input command. You must put curly brackets around the value if a value with an optional argument is used within an optional argument.

Programming languages

Preferences

All parameters set via '\lstset' retain their values ​​until the end of the current environment or array. The optional parameters of the two pretty-print commands and the 'lstlisting' environment take effect only on the particular list, ie.

Table 1: Predefined languages. Note that some definitions are preliminary, for example HTML and XML
Table 1: Predefined languages. Note that some definitions are preliminary, for example HTML and XML

Special characters

Similarly, if you use extended UTF-8 characters in a list, they must be escaped to LATEX. Also, section 8 has a few details on how to work with extended characters in the context of Λ.

Line numbers

If you use them, load fontenc, inputenc, and/or any other package that defines the characters. If you have a list contained in a CJK environment and want to have CJK characters inside the list, you can place them in a comment that escapes to LATEX - see section 4.3.13 for how to do that.

Layout elements

You might think that the lines should be drawn to the edge, but what about rounded corners. Note that frameround is used together with \lstset, so the value affects all subsequent lists in the same group or environment.

Emphasize identifiers

Even if your source code is highlighted as expected, there is no guarantee that it will be if you change the order of your listings or use a different version of this package.

Indexing

Fixed and flexible columns . 22

It is obvious that a beautiful printing tool like this requires some kind of language selection and definition. The first has already been described, and the last is discussed in the next section. However, it is very convenient to have the same for printing styles: in a central place in your document, they can be easily changed, and the changes will take effect in all lists.

Keys not used in such a definition are of course unaffected by the corresponding style selection.

Language definitions

Note that each delimiter (pair) requires a key=value itself, even if the two types are the same. So you'll need to insert morestring=[b]' if single quotes open and close string or character literals in the same way as double quotes in the example. This delimiter opens and closes a string, and escapes backslashes or doubles within a string.

Another problem: By default, some characters are not allowed in keywords, for example and so on. The Reference Guide covers this problem by introducing a few more keys that let you adjust the default character table appropriately.

Delimiters

As you can see, you can choose between specifying the style explicitly with LATEX commands or implicitly with other style keys. But you're right, some implicitly defined styles don't have separate keys, like the second-order keyword style. These types can be preceded by ani, but this time only punctuation is discarded from the output.

You can even let the package detect keywords, comments, strings, and other delimiters within the content. The second beginning is not printed in bold font because standard LATEX does not have such a font.

Closing and credits

Now that you've left the user guide, the friend who tells you what to do is gone. Note that some keys default this value to each listing, namely the keys that can only be used on individual listings. [*] must therefore be typed exactly as is, but [*] only gets * if you use this argument.

To enter one of the special characters {}#%\, this character must be escaped with a backslash. This means that you should write \} for the single 'right curly brace' character, but not for the trailing parameter character, of course.

Typesetting listings

Unlike the environment of the package literal, LATEX code is executed on the same line and after the end of the environment respectively.

Options

  • Searching for files
  • Space and placement
  • The printed range
  • Languages and styles
  • Figure out the appearance . 31
  • Captions
  • Margins and line shape
  • Frames
  • Indexing
  • Column alignment
  • Escaping to L A TEX

See classoffsetkey in Section 4.3.5 to mark language keywords differently. If you use an optional asterisk for the (optional) class number, the keywords are printed in uppercase - even if the language is case-sensitive and specifies only lowercase keywords. If you use one optional asterisk, the package will detect keywords, comments, and strings within delimited code.

Each entry is, in descending priority, either the short caption, the caption, the file name or the name of the list entry, see also the key name in section 4.3.7. Note: The size of the quarter circles depends on the frame and is independent of the extra margins of a frame. Each occurrence of the explicitly given identifiers and each occurrence of the identifiers of the specified keyword classes are indexed.

About half of the comment line of the second example is printed by this package, and the rest is in "LATEX mode".

Interface to fancyvrb

In the first example, the comment line through aij has been commented out by the listing package. If you're using fancyvrb's commandchars, you'll need to tell the listingspackage how many arguments each command needs. So, if you want to use \textcolor{red}{keyword} with the fancyvrb-listings interface, you have to write \lstset{morefvcmdparams=\textcolor 2} .

The lines set by the listing package are wider because the default base width is not equal to the width of a single typewriter character. Additionally, note that the first space begins a comment as defined at the beginning of the example.

Environments

Short Inline Listing Commands 44

For example, if you write keywords={one-two,\#include}, the minus sign must become a number and the slash a letter, since the keywords cannot be found otherwise. The optional argument is the type and controls how the delimiter itself is represented in a string or character literal: it is escaped by a backslash, doubled (or both are allowed via bd). The delimiter begins a comment line, which generally begins with the delimiter and ends at the end of the line.

The delimiter starts a comment line if and only if it appears in a fixed column number, that is, if it is in column n (zero-based). Each first-argument keyword starts a comment, and each second-argument keyword ends it (and also a semicolon); a comment that begins with any third-argument keyword ends with only the next semicolon.

Table 2: Standard character table class characters
Table 2: Standard character table class characters

Installation

Note that the listings require at least version 1.10 of the keyval package included in thegraphicsbundle by David Carlisle. Software configuration Read this only if you encounter problems with the standard configuration or if you want the package to correspond to, for example, foreign languages. All of them are unlikely to be removed (unless specifically stated), but are subject to (major) changes and improvements.

There are a few things to consider if you want to use \lstinline or the listing environment within arguments. A generic interface is completely outside the scope of this package - that's the job of a compiler, not a pretty printing tool.

Literate programming

It marks and indexes the function definitions so far, but it would be possible to also mark the following function calls, for example. A key can control whether function names are added to a special keyword class, which then appears in 'procname' style. Instead of printing these characters, we use replacement text, which takes the width of length characters in the output.

To do: Of course it's good to have keys for adding and removing some replacement items. Perhaps the key(s) should work in the same way as the string and comment definitions, i.e.

LGrind definitions

This would make it easier to provide better automatic detection in the case of a subsequence. Insert a horizontal space to separate the function/procedure name and the parentheses that follow, or to separate function arguments, e.g. It can be annoying if empty or small blocks take up three or more lines in the output - think of scrolling down all the time.

Arbitrary linerange markers . 54

If you encounter a problem with the listing package, there are a few steps you should take before filing a bug report. If you are using a very special package (ie one that is not on CTAN), also include the package if the software license allows it. If you did that, the compiler wouldn't see the LATEX code since it would be in a comment, and the list packages wouldn't print anything since the delimiters would be omitted and produce no printable output, but you could still reference the line number.

Note that empty lines and the start and end of the environment do not have to respect the indentation. Now if you use Λ (Lambda, the LATEX variant for Omega) and want to say Arabic comment lines, you don't need to write \begin{arab}.

Gambar

Table 1: Predefined languages. Note that some definitions are preliminary, for example HTML and XML
Table 2: Standard character table class characters

Referensi

Dokumen terkait

To improve the quality of sleep in the elderly, exercise intervention can be carried out as for the types of exercise that can be used to improve sleep quality in the elderly,