prepare manual for rest conversion
[PyX/mjg.git] / manual / unit.tex
blob57805d871635263dd617724802932aa3c3499223
1 \chapter{Module unit}
2 \label{unit}
4 \sectionauthor{J\"org Lehmann}{joergl@users.sourceforge.net}
6 \declaremodule{}{unit}
8 With the \verb|unit| module \PyX{} makes available classes and
9 functions for the specification and manipulation of lengths. As usual,
10 lengths consist of a number together with a measurement unit, e.g.,
11 1 cm, 50 points, 0.42 inch. In addition,
12 lengths in \PyX{} are composed of the five types ``true'', ``user'',
13 ``visual'', ``width'', and ``\TeX'', e.g., 1 user cm,
14 50 true points, 0.42 visual + 0.2 width inch. As their names
15 indicate, they serve different purposes. True lengths are not scalable
16 and are mainly used for return values of \PyX{} functions. The other
17 length types can be rescaled by the user and differ with respect to
18 the type of object they are applied to:
20 \begin{description}
21 \item[user length:] used for lengths of graphical objects like
22 positions etc.
23 \item[visual length:] used for sizes of visual elements, like arrows,
24 graph symbols, axis ticks, etc.
25 \item[width length:] used for line widths
26 \item[\TeX{} length:] used for all \TeX{} and \LaTeX{} output
27 \end{description}
29 When not specified otherwise, all types of lengths are interpreted
30 in terms of a default unit, which, by default, is 1 cm.
31 You may change this default unit by using the module level function
32 \begin{funcdesc}{set}{uscale=None, vscale=None, wscale=None,
33 xscale=None, defaultunit=None}
34 When \var{uscale}, \var{vscale}, \var{wscale}, or \var{xscale} is not
35 \keyword{None}, the corresponding scaling factor(s) is redefined to
36 the given number. When \var{defaultunit} is not \keyword{None},
37 the default unit is set to the given value, which has to be
38 one of \code{"cm"}, \code{"mm"}, \code{"inch"}, or \code{"pt"}.
39 \end{funcdesc}
41 For instance, if you only want thicker lines for a publication
42 version of your figure, you can just rescale all width lengths using
43 \begin{verbatim}
44 unit.set(wscale=2)
45 \end{verbatim}
46 Or suppose, you are used to specify length in imperial units. In this,
47 admittedly rather unfortunate case, just use
48 \begin{verbatim}
49 unit.set(defaultunit="inch")
50 \end{verbatim}
51 at the beginning of your program.
53 \section{Class length}
55 \begin{classdesc}{length}{f, type="u", unit=None}
56 The constructor of the \class{length} class expects as its first
57 argument a number \var{f}, which represents the prefactor of the given length.
58 By default this length is interpreted as a user length (\code{type="u"}) in units
59 of the current default unit (see \function{set()} function of the \module{unit}
60 module). Optionally, a different \var{type} may be specified, namely
61 \code{"u"} for user lengths, \code{"v"} for visual lengths, \code{"w"}
62 for width lengths, \code{"x"} for \TeX{} length, and \code{"t"} for true
63 lengths. Furthermore, a different unit may be specified using the \var{unit}
64 argument. Allowed values are \code{"cm"}, \code{"mm"}, \code{"inch"},
65 and \code{"pt"}.
66 \end{classdesc}
68 Instances of the \class{length} class support addition and substraction either by another \class{length}
69 or by a number which is then interpeted as being a user length in
70 default units, multiplication by a number and division either by another
71 \class{length} in which case a float is returned or by a number in which
72 case a \class{length} instance is returned. When two lengths are
73 compared, they are first converted to meters (using the currently set
74 scaling), and then the resulting values are compared.
76 \section{Predefined length instances}
78 A number of \verb|length| instances are already predefined, which
79 only differ in there values for \verb|type| and \verb|unit|. They are
80 summarized in the following table
82 \medskip
83 \begin{tableiii}{lll}{textrm}{name}{type}{unit}
84 \lineiii{\constant{m}}{user}{m}
85 \lineiii{\constant{cm}}{user}{cm}
86 \lineiii{\constant{mm}}{user}{mm}
87 \lineiii{\constant{inch}}{user}{inch}
88 \lineiii{\constant{pt}}{user}{points}
89 \lineiii{\constant{t\_m}}{true}{m}
90 \lineiii{\constant{t\_cm}}{true}{cm}
91 \lineiii{\constant{t\_mm}}{true}{mm}
92 \lineiii{\constant{t\_inch}}{true}{inch}
93 \lineiii{\constant{t\_pt}}{true}{points}
94 \lineiii{\constant{u\_m}}{user}{m}
95 \lineiii{\constant{u\_cm}}{user}{cm}
96 \lineiii{\constant{u\_mm}}{user}{mm}
97 \lineiii{\constant{u\_inch}}{user}{inch}
98 \lineiii{\constant{u\_pt}}{user}{points}
99 \lineiii{\constant{v\_m}}{visual}{m}
100 \lineiii{\constant{v\_cm}}{visual}{cm}
101 \lineiii{\constant{v\_mm}}{visual}{mm}
102 \lineiii{\constant{v\_inch}}{visual}{inch}
103 \lineiii{\constant{v\_pt}}{visual}{points}
104 \lineiii{\constant{w\_m}}{width}{m}
105 \lineiii{\constant{w\_cm}}{width}{cm}
106 \lineiii{\constant{w\_mm}}{width}{mm}
107 \lineiii{\constant{w\_inch}}{width}{inch}
108 \lineiii{\constant{w\_pt}}{width}{points}
109 \lineiii{\constant{x\_m}}{\TeX}{m }
110 \lineiii{\constant{x\_cm}}{\TeX}{cm }
111 \lineiii{\constant{x\_mm}}{\TeX}{mm }
112 \lineiii{\constant{x\_inch}}{\TeX}{inch }
113 \lineiii{\constant{x\_pt}}{\TeX}{points}
114 \end{tableiii}
115 \medskip
117 Thus, in order to specify, e.g., a length of 5 width points, just use
118 \code{5*unit.w_pt}.
120 \section{Conversion functions}
121 If you want to know the value of a \PyX{} length in certain units, you
122 may use the predefined conversion functions which are given in the
123 following table
124 \begin{tableii}{l|l}{textrm}{function}{result}
125 \lineii{\texttt{tom(l)}}{\texttt{l} in units of m}
126 \lineii{\texttt{tocm(l)}}{\texttt{l} in units of cm}
127 \lineii{\texttt{tomm(l)}}{\texttt{l} in units of mm}
128 \lineii{\texttt{toinch(l)}}{\texttt{l} in units of inch}
129 \lineii{\texttt{topt(l)}}{\texttt{l} in units of points}
130 \end{tableii}
131 If \verb|l| is not yet a \verb|length| instance but a number, it first
132 is interpreted as a user length in the default units.
136 %%% Local Variables:
137 %%% mode: latex
138 %%% TeX-master: "manual.tex"
139 %%% End: