mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 14:29:21 +00:00
0ed05b32be
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19192 a592a061-630c-0410-9148-cb99ea01b6c8
271 lines
5.6 KiB
Plaintext
271 lines
5.6 KiB
Plaintext
#LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
|
|
\lyxformat 276
|
|
\begin_document
|
|
\begin_header
|
|
\textclass article
|
|
\begin_preamble
|
|
\usepackage{a4wide}
|
|
\end_preamble
|
|
\language english
|
|
\inputencoding auto
|
|
\font_roman default
|
|
\font_sans default
|
|
\font_typewriter default
|
|
\font_default_family default
|
|
\font_sc false
|
|
\font_osf false
|
|
\font_sf_scale 100
|
|
\font_tt_scale 100
|
|
\graphics default
|
|
\float_placement H
|
|
\paperfontsize default
|
|
\spacing single
|
|
\papersize default
|
|
\use_geometry false
|
|
\use_amsmath 1
|
|
\use_esint 0
|
|
\cite_engine basic
|
|
\use_bibtopic false
|
|
\paperorientation portrait
|
|
\secnumdepth 3
|
|
\tocdepth 3
|
|
\paragraph_separation indent
|
|
\defskip medskip
|
|
\quotes_language english
|
|
\papercolumns 1
|
|
\papersides 1
|
|
\paperpagestyle default
|
|
\tracking_changes false
|
|
\output_changes false
|
|
\author "Bo Peng"
|
|
\end_header
|
|
|
|
\begin_body
|
|
|
|
\begin_layout Section
|
|
Three types of listings
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
There are three types of listings, in listings package terms:
|
|
\end_layout
|
|
|
|
\begin_layout Description
|
|
lstinline short piece of program code like
|
|
\begin_inset listings
|
|
lstparams "language=C++,basicstyle=\ttfamily,showspaces=true"
|
|
inline true
|
|
status open
|
|
|
|
\begin_layout Standard
|
|
|
|
\color foreground
|
|
int a=5;
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Description
|
|
lstlisting long program listing in its own paragraphs and decorations, For
|
|
example,
|
|
\begin_inset listings
|
|
lstparams "language=Python,numbers=left,numberstyle=\tiny,basicstyle=\ttfamily,numbersep=5pt"
|
|
inline false
|
|
status open
|
|
|
|
\begin_layout Standard
|
|
|
|
\color foreground
|
|
def func(param):
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
'this is a python function'
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
pass
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Description
|
|
lstinputlisting read program listing from a file.
|
|
Parameters can be given to list only given lines.
|
|
For example, the following listings list line 10 - 15 of this lyx file.
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
\begin_inset Include \lstinputlisting{listings.lyx}[firstline=10,lastline=15,language=TeX,breaklines=true,caption={Line 10 - 15 of this listings.lyx file}]
|
|
preview false
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Section
|
|
How to enter listings
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
Inline and normal listings are entered through listings inset (introduced
|
|
by lyx 1.5.0).
|
|
To insert a program listing, choose
|
|
\family typewriter
|
|
Insert->Program Listing
|
|
\family default
|
|
.
|
|
inline listing is selected by choosing
|
|
\family typewriter
|
|
inline listing
|
|
\family default
|
|
in the
|
|
\family typewriter
|
|
placement
|
|
\family default
|
|
section.
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
File listing is inserted using
|
|
\family typewriter
|
|
Insert->File->Child Document
|
|
\family default
|
|
, and choose
|
|
\family typewriter
|
|
listings
|
|
\family default
|
|
from the type combo box.
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Section
|
|
Listings parameters
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
The listings package is a very powerful latex packaging, providing more
|
|
than 130 parameters that customize the look of your program listings.
|
|
Lyx provides direct support for a few most commonly used parameters through
|
|
the listings dialog, and an
|
|
\family typewriter
|
|
advanced
|
|
\family default
|
|
edit box to enter all other parameters.
|
|
\end_layout
|
|
|
|
\begin_layout Subsection
|
|
Global listings options
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
It is likely that your document will have several listings of the same type
|
|
so it makes sense to customize all of them using global listings options.
|
|
To enter these options, choose
|
|
\family typewriter
|
|
Document -> Settings -> Text Layouts
|
|
\family default
|
|
and enter listings parameters in the given edit box.
|
|
The editbox to the left of the input box can provide valuable information
|
|
such as allowed values of a parameter but you may still need to consult
|
|
the listings manual for the meanings of the parameters.
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
Parameters set via this dialog will output as
|
|
\family typewriter
|
|
|
|
\backslash
|
|
lstset
|
|
\family default
|
|
in latex preamble.
|
|
\end_layout
|
|
|
|
\begin_layout Subsection
|
|
Parameters of the listings inset
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
If you right-click a listings inset, a listings dialog will be shown that
|
|
allows you to customize your listings.
|
|
The most commonly used parameters are displayed on the first tab, including
|
|
placement, language, numbering and basic style of the code.
|
|
More advanced options can be entered at the second
|
|
\family typewriter
|
|
advanced
|
|
\family default
|
|
tab.
|
|
\end_layout
|
|
|
|
\begin_layout Subsection
|
|
Parameters of listings child document
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
The child document dialog provides less support for commonly used listings
|
|
parameters so you will have to enter them manually.
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Subsection
|
|
Caption and label
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
Parameters
|
|
\family typewriter
|
|
caption={blah}
|
|
\family default
|
|
and
|
|
\family typewriter
|
|
label={blah}
|
|
\family default
|
|
are handled separately from other listings parameters.
|
|
In the
|
|
\family typewriter
|
|
Child Document
|
|
\family default
|
|
dialog, caption ad label should be entered in the given caption and label
|
|
edit boxes.
|
|
In a listing inset, you can insert caption through
|
|
\family typewriter
|
|
insert -> caption
|
|
\family default
|
|
, and
|
|
\family typewriter
|
|
insert->label
|
|
\family default
|
|
in the caption.
|
|
Explicit
|
|
\family typewriter
|
|
caption
|
|
\family default
|
|
and
|
|
\family typewriter
|
|
label
|
|
\family default
|
|
parameters entered through the
|
|
\family typewriter
|
|
advanced
|
|
\family default
|
|
edit box are allowed, but if both
|
|
\family typewriter
|
|
insert->caption
|
|
\family default
|
|
and parameter
|
|
\family typewriter
|
|
caption={blah}
|
|
\family default
|
|
are entered, the latter will be ignored.
|
|
\end_layout
|
|
|
|
\end_body
|
|
\end_document
|