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