]> git.lyx.org Git - lyx.git/blob - lib/examples/listings.lyx
- add Farsi splash.lyx
[lyx.git] / lib / examples / listings.lyx
1 #LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
2 \lyxformat 270
3 \begin_document
4 \begin_header
5 \textclass article
6 \begin_preamble
7 \usepackage{a4wide}
8 \end_preamble
9 \language english
10 \inputencoding auto
11 \font_roman default
12 \font_sans default
13 \font_typewriter default
14 \font_default_family default
15 \font_sc false
16 \font_osf false
17 \font_sf_scale 100
18 \font_tt_scale 100
19 \graphics default
20 \float_placement H
21 \paperfontsize default
22 \spacing single
23 \papersize default
24 \use_geometry false
25 \use_amsmath 1
26 \use_esint 0
27 \cite_engine basic
28 \use_bibtopic false
29 \paperorientation portrait
30 \secnumdepth 3
31 \tocdepth 3
32 \paragraph_separation indent
33 \defskip medskip
34 \quotes_language english
35 \papercolumns 1
36 \papersides 1
37 \paperpagestyle default
38 \tracking_changes false
39 \output_changes false
40 \author "Bo Peng" 
41 \end_header
42
43 \begin_body
44
45 \begin_layout Section
46 Three types of listings
47 \end_layout
48
49 \begin_layout Standard
50 There are three types of listings, in listings package terms:
51 \end_layout
52
53 \begin_layout Description
54 lstinline short piece of program code like 
55 \begin_inset listings
56 lstparams "language=C++,basicstyle=\ttfamily,showspaces=true"
57 inline true
58 status open
59
60 \begin_layout Standard
61
62 \color foreground
63 int a=5;
64 \end_layout
65
66 \end_inset
67
68  
69 \end_layout
70
71 \begin_layout Description
72 lstlisting long program listing in its own paragraphs and decorations, For
73  example, 
74 \begin_inset listings
75 lstparams "language=Python,numbers=left,numberstyle=\tiny,basicstyle=\ttfamily,numbersep=5pt"
76 inline false
77 status open
78
79 \begin_layout Standard
80
81 \color foreground
82 def func(param):
83 \end_layout
84
85 \begin_layout Standard
86     'this is a python function'
87 \end_layout
88
89 \begin_layout Standard
90     pass
91 \end_layout
92
93 \end_inset
94
95
96 \end_layout
97
98 \begin_layout Description
99 lstinputlisting read program listing from a file.
100  Parameters can be given to list only given lines.
101  For example, the following listings list line 10 - 15 of this lyx file.
102 \end_layout
103
104 \begin_layout Standard
105 \begin_inset Include \lstinputlisting{listings.lyx}[firstline=10,lastline=15,language=TeX,breaklines=true,caption={Line 10 - 15 of this listings.lyx file}]
106 preview false
107
108 \end_inset
109
110
111 \end_layout
112
113 \begin_layout Section
114 How to enter listings
115 \end_layout
116
117 \begin_layout Standard
118 Inline and normal listings are entered through listings inset (introduced
119  by lyx 1.5.0).
120  To insert a program listing, choose 
121 \family typewriter
122 Insert->Program Listing
123 \family default
124 .
125  inline listing is selected by choosing 
126 \family typewriter
127 inline listing 
128 \family default
129 in the 
130 \family typewriter
131 placement 
132 \family default
133 section.
134 \end_layout
135
136 \begin_layout Standard
137 File listing is inserted using 
138 \family typewriter
139 Insert->File->Child Document
140 \family default
141 , and choose 
142 \family typewriter
143 listings 
144 \family default
145 from the type combo box.
146  
147 \end_layout
148
149 \begin_layout Section
150 Listings parameters
151 \end_layout
152
153 \begin_layout Standard
154 The listings package is a very powerful latex packaging, providing more
155  than 130 parameters that customize the look of your program listings.
156  Lyx provides direct support for a few most commonly used parameters through
157  the listings dialog, and an 
158 \family typewriter
159 advanced 
160 \family default
161 edit box to enter all other parameters.
162 \end_layout
163
164 \begin_layout Subsection
165 Global listings options
166 \end_layout
167
168 \begin_layout Standard
169 It is likely that your document will have several listings of the same type
170  so it makes sense to customize all of them using global listings options.
171  To enter these options, choose 
172 \family typewriter
173 Document -> Settings -> Text Layouts 
174 \family default
175 and enter listings parameters in the given edit box.
176  The editbox to the left of the input box can provide valuable information
177  such as allowed values of a parameter but you may still need to consult
178  the listings manual for the meanings of the parameters.
179 \end_layout
180
181 \begin_layout Standard
182 Parameters set via this dialog will output as 
183 \family typewriter
184
185 \backslash
186 lstset 
187 \family default
188 in latex preamble.
189 \end_layout
190
191 \begin_layout Subsection
192 Parameters of the listings inset
193 \end_layout
194
195 \begin_layout Standard
196 If you right-click a listings inset, a listings dialog will be shown that
197  allows you to customize your listings.
198  The most commonly used parameters are displayed on the first tab, including
199  placement, language, numbering and basic style of the code.
200  More advanced options can be entered at the second 
201 \family typewriter
202 advanced 
203 \family default
204 tab.
205 \end_layout
206
207 \begin_layout Subsection
208 Parameters of listings child document
209 \end_layout
210
211 \begin_layout Standard
212 The child document dialog provides less support for commonly used listings
213  parameters so you will have to enter them manually.
214  
215 \end_layout
216
217 \begin_layout Subsection
218 Caption and label
219 \end_layout
220
221 \begin_layout Standard
222 Parameters 
223 \family typewriter
224 caption={blah}
225 \family default
226  and 
227 \family typewriter
228 label={blah}
229 \family default
230  are handled separately from other listings parameters.
231  In the 
232 \family typewriter
233 Child Document 
234 \family default
235 dialog, caption ad label should be entered in the given caption and label
236  edit boxes.
237  In a listing inset, you can insert caption through 
238 \family typewriter
239 insert -> caption
240 \family default
241 , and 
242 \family typewriter
243 insert->label
244 \family default
245  in the caption.
246  Explicit 
247 \family typewriter
248 caption
249 \family default
250  and
251 \family typewriter
252  label 
253 \family default
254 parameters entered through the 
255 \family typewriter
256 advanced 
257 \family default
258 edit box are allowed, but if both 
259 \family typewriter
260 insert->caption
261 \family default
262  and parameter 
263 \family typewriter
264 caption={blah} 
265 \family default
266 are entered, the latter will be ignored.
267 \end_layout
268
269 \end_body
270 \end_document