add question concerning the order of deformer and trafo application
[PyX/mjg.git] / manual / unit.tex
blob2c54b4a65960bcb3e056b0b9a31edef86a21f533
1 \chapter{Module unit}
2 \label{unit}
4 With the \verb|unit| module \PyX{} makes available classes and
5 functions for the specification and manipulation of lengths. As usual,
6 lengths consist of a number together with a measurement unit, e.g.,
7 \unit[1]{cm}, \unit[50]{points}, \unit[0.42]{inch}. In addition,
8 lengths in \PyX{} are composed of the five types ``true'', ``user'',
9 ``visual'', ``width'', and ``\TeX'', e.g., \unit[1]{user cm},
10 \unit[50]{true points}, $(0.42\ \mathrm{visual} + 0.2\
11 \mathrm{width})$ inch. As their names indicate, they serve different
12 purposes. True lengths are not scalable and are mainly used for return
13 values of \PyX{} functions. The other length types can be rescaled by
14 the user and differ with respect to the type of object they are
15 applied to:
17 \begin{description}
18 \item[user length:] used for lengths of graphical objects like
19 positions etc.
20 \item[visual length:] used for sizes of visual elements, like arrows,
21 graph symbols, axis ticks, etc.
22 \item[width length:] used for line widths
23 \item[\TeX{} length:] used for all \TeX{} and \LaTeX{} output
24 \end{description}
26 For instance, if you only want thicker lines for a publication
27 version of your figure, you can just rescale the width lengths. How
28 this all works, is described in the following sections.
30 \section{Class length}
32 The constructor of the \verb|length| class accepts as first argument
33 either a number or a string:
34 \begin{itemize}
35 \item \verb|length(number)| means a user length in units of the default
36 unit, defined via \verb|unit.set(defaultunit=defaultunit)|.
37 \item For \verb|length(string)|, the \verb|string| has to consist of a
38 maximum of three parts separated by one or more whitespaces:
39 \begin{description}
40 \item[quantifier:] integer/float value. Optional, defaults to \verb|1|.
41 \item[type:] \verb|"t"| (true), \verb|"u"| (user), \verb|"v"|
42 (visual), \verb|"w"| (width),
43 or \verb|"x"| (TeX).
44 Optional, defaults to \verb|"u"|.
45 \item[unit:] \verb|"m"|, \verb|"cm"|, \verb|"mm"|, \verb|"inch"|, or
46 \verb|"pt"|. Optional, defaults to the default unit.
47 \end{description}
48 \end{itemize}
49 The default for the first argument is chosen in such a way that
50 \texttt{5*length()==length(5)}. Note that the default unit is
51 initially set to \verb|"cm"|, but can be changed at any time by the
52 user. For instance, use
53 \begin{quote}
54 \begin{verbatim}
55 unit.set(defaultunit="inch")
56 \end{verbatim}
57 \end{quote}
58 if you want to specify per default every length in inches.
59 Furthermore, the scaling of the user, visual and width types can be
60 changed with the \verb|set| function, as well. To this end, \verb|set|
61 accepts the named arguments \verb|uscale|, \verb|vscale|, and
62 \verb|wscale|. For example, if you like to change the thickness of all
63 lines (with predefined linewidths) by a factor of two, just insert
64 \begin{quote}
65 \begin{verbatim}
66 unit.set(wscale = 2)
67 \end{verbatim}
68 \end{quote}
69 at the beginning of your program.
71 To complete the discussion of the \verb|length| class, we mention,
72 that as expected \PyX{} lengths can be added, subtracted, multiplied by
73 a numerical factor, converted to a string and compared with each other.
75 \section{Subclasses of length}
77 A number of subclasses of \verb|length| are already predefined. They
78 only differ by their defaults for \verb|type| and \verb|unit|. Note
79 that again the default value for the quantifier is \verb|1|, such
80 that, for instance, \texttt{5*m(1)==m(5)}.
82 \medskip
83 \begin{center}
84 \begin{tabular}{lll|lll}
85 Subclass of \texttt{length} & Type & Unit & Subclass of \texttt{length} & Type & Unit\\
86 \hline
87 \texttt{m(x)} & user & m & \texttt{v\_m(x)} & visual & m\\
88 \texttt{cm(x)} & user & cm & \texttt{v\_cm(x)} & visual & cm\\
89 \texttt{mm(x)} & user & mm & \texttt{v\_mm(x)} & visual & mm\\
90 \texttt{inch(x)} & user & inch & \texttt{v\_inch(x)} & visual & inch\\
91 \texttt{pt(x)} & user & points & \texttt{v\_pt(x)} & visual & points\\
92 \texttt{t\_m(x)} & true & m & \texttt{w\_m(x)} & width & m\\
93 \texttt{t\_cm(x)} & true & cm & \texttt{w\_cm(x)} & width & cm\\
94 \texttt{t\_mm(x)} & true & mm & \texttt{w\_mm(x)} & width & mm\\
95 \texttt{t\_inch(x)} & true & inch & \texttt{w\_inch(x)} & width & inch\\
96 \texttt{t\_pt(x)} & true & points & \texttt{w\_pt(x)} & width & points\\
97 \texttt{u\_m(x)} & user & m & \texttt{x\_m(x)} & \TeX & m \\
98 \texttt{u\_cm(x)} & user & cm & \texttt{x\_cm(x)} & \TeX & cm \\
99 \texttt{u\_mm(x)} & user & mm & \texttt{x\_mm(x)} & \TeX & mm \\
100 \texttt{u\_inch(x)} & user & inch & \texttt{x\_inch(x)} & \TeX & inch \\
101 \texttt{u\_pt(x)} & user & points & \texttt{x\_pt(x)} & \TeX & points\\
103 \end{tabular}
104 \end{center}
105 \medskip
106 Here, \verb|x| is either a number or a string, which, as mentioned
107 above, defaults to \texttt{1}.
109 \section{Conversion functions}
110 If you want to know the value of a \PyX{} length in certain units, you
111 may use the predefined conversion functions which are given in the
112 following table
113 \begin{center}
114 \begin{tabular}{ll}
115 function & result \\
116 \hline
117 \texttt{tom(l)} & \texttt{l} in units of m\\
118 \texttt{tocm(l)} & \texttt{l} in units of cm\\
119 \texttt{tomm(l)} & \texttt{l} in units of mm\\
120 \texttt{toinch(l)} & \texttt{l} in units of inch\\
121 \texttt{topt(l)} & \texttt{l} in units of points\\
122 \end{tabular}
123 \end{center}
124 If \verb|l| is not yet a \verb|length| instance, it is converted first
125 into one, as described above. You can also specify a tuple, if you
126 want to convert multiple lengths at once.
129 %\section{Examples}
132 %\subsection{Example 1}
136 %%% Local Variables:
137 %%% mode: latex
138 %%% TeX-master: "manual.tex"
139 %%% End: