Debian Codegraph @

texmf-dist/doc/generic/pst-tools/pst-tools-doc.tex

raw
1 \RequirePackage{pdfmanagement-testphase}
2 \DeclareDocumentMetadata{}
3 %% $Id: pst-tools-doc.tex 256 2021-09-22 18:42:59Z herbert $
4 \documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false,headings=small,
5 headinclude=false,footinclude=false,oneside]{pst-doc}
6 \listfiles
7 \usepackage{pstricks}
8 \usepackage{pst-tools}
9 \let\pstToolsFV\fileversion
10 \usepackage{xltabular}
11 \usepackage{pst-plot}
12 \renewcommand\bgImage{}
13
14 \lstset{language=PSTricks,
15 morekeywords={psPrintValue},basicstyle=\footnotesize\ttfamily}
16 %
17 \usepackage{biblatex}
18 \addbibresource{pst-tools-doc.bib}
19 \begin{document}
20
21 \title{\texttt{pst-tools}}
22 \subtitle{Helper functions; v.\pstToolsFV}
23 \author{Herbert Voß}
24 \docauthor{}
25 \settitle
26
27 \begin{abstract}
28 This package defines some tools which are useful for all packages not only the PSTricks like packages.
29 Since the version 0.10 it includes the macros from \texttt{random.tex}.
30 \vfill
31 \noindent
32 Thanks to:
33 Marcel Krüger;
34 Pablo Gonzáles Luengo;
35 Rolf Niepraschk;
36 \end{abstract}
37
38 \newpage
39
40 \tableofcontents
41 \psset{unit=1cm}
42
43
44 \section{Predefined styles}
45
46 The style \Lkeyword{mmpaper} is defined for \Lcs{psgrid}:
47 %\newpsstyle{mmpaper}{subgriddiv=5,gridlabels=0,gridwidth=1pt,gridcolor=orange,subgridwidth=0.1pt,subgridcolor=orange!90}
48
49 \begin{LTXexample}[width=0.5\linewidth,frame=,pos=r]
50 \begin{pspicture}(6,3)
51 \psgrid[style=mmpaper](6,3)
52 \end{pspicture}
53
54 \begin{pspicture}(6,3)
55 \psgrid[style=mmpaper,
56 gridcolor=blue,subgridcolor=blue!80](6,3)
57 \end{pspicture}
58 \end{LTXexample}
59
60
61 \section{\Lcs{psPrintValue}}\label{sec:printValue}
62 This macro allows to \Index{print} single values of a math function. It has the syntax
63
64 \begin{BDef}
65 \Lcs{psPrintValue}\OptArgs\Largb{PostScript code}\\
66 \Lcs{psPrintValue}\OptArg{algebraic,\ldots}\Largb{x value, algebraic code}
67 \end{BDef}
68
69 Important is the fact, that \Lcs{psPrintValue} works on \PS\ side. For \TeX\ it is only a box of
70 zero dimension. This is the reason why you have to put it into a box, which reserves horizontal
71 space.
72
73
74 There are the following valid options for \Lcs{psPrintValue}:
75
76 \noindent\medskip
77 \begin{xltabular}{\linewidth}{@{}l|>{\ttfamily}l>{\ttfamily}lX@{}}
78 \textrm{name} & \textrm{value} & \textrm{default}\\\hline
79 \endhead
80 \Lkeyword{printfont} & font name & Times & only the current font (\texttt{printfont={}})
81 or valid \PS\ font names are possible, e.g.
82 \Lps{Times-Roman}, \Lps{Helvetica}, \Lps{Courier}, \Lps{Helvetica}, \Lps{Bookman}. If you want to embed the fonts
83 use always the URW names NimbusRomNo9L-Regu, NimbusSanL-Regu and NimbusMonL-Regu. However, the names
84 may vary on different operating systems. If you leave the argument empty, it will choose the currently active font.\\
85 \Lkeyword{postString} & <string> & \{\} & will be appended to the number string\\
86 \Lkeyword{trimSpaces} & <boolean> & false & will strip spaces on the right\\
87 \Lkeyword{fontscale} & <number> & 10 & the font scale in pt\\
88 \Lkeyword{valuewidth} & <number> & 10 & the width of the string for the converted
89 real number; if it is too small, no value is printed\\
90 \Lkeyword{decimals} & <number> & -1 & the number of printed decimals, a negative value
91 prints all possible digits.\\
92 \Lkeyword{xShift} & <number> & 0 & the x shift in pt for the output, relative to the current point.\\
93 \Lkeyword{algebraic} & <boolean> & false & function in algebraic notation.\\
94 \Lkeyword{VarName} & <string> & \{\} & saves the value in /<VarName> for further use\\
95 \Lkeyword{comma} & <boolean> & false & comma instead of the dor for decimals\\
96 \end{xltabular}
97
98
99
100
101 \begin{center}
102 \psset{fontscale=12}
103 \makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
104 \makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
105 \multido{\iA=0+10}{18}{%
106 \makebox[1em]{\iA}
107 \makebox[5em]{\psPrintValue[printfont=NimbusRomNo9L-Regu,xShift=-10]{\iA\space sin}}
108 \makebox[4em][r]{\psPrintValue[printfont={},fontscale=10,decimals=3,xShift=-20]{\iA\space cos}}\hspace{1em}
109 \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,printfont=NimbusSanL-Regu]{\iA\space sqrt}}
110 \makebox[7em]{\psPrintValue[comma,printfont=NimbusRomNo9L-ReguItal]{\iA\space dup sin exch cos add}}
111 \makebox[6em]{\psPrintValue[printfont=Palatino-Roman]{\iA\space dup sin dup mul exch cos dup mul add}}\\
112 }
113 \end{center}
114
115
116 \bigskip
117
118 \begin{lstlisting}
119 \psset{fontscale=12}
120 \makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
121 \makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
122 \multido{\iA=0+10}{18}{
123 \makebox[1em]{\iA}
124 \makebox[5em]{\psPrintValue[printfont=NimbusRomNo9L-Regu,xShift=-10]{\iA\space sin}}
125 \makebox[4em][r]{\psPrintValue[printfont={},fontscale=10,decimals=3,xShift=-20]{\iA\space cos}}\hspace{1em}
126 \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,printfont=NimbusSanL-Regu]{\iA\space sqrt}}
127 \makebox[7em]{\psPrintValue[comma,printfont=NimbusRomNo9L-ReguItal]{\iA\space dup sin exch cos add}}
128 \makebox[6em]{\psPrintValue[printfont=Palatino-Roman]{\iA\space dup sin dup mul exch cos dup mul add}}\\}
129 \end{lstlisting}
130
131
132
133
134 With enabled \Lkeyword{algebraic} option there must be two arguments, separated by a comma.
135 The first one is the x value as a number, which can also be PostScript code, which leaves a
136 number on the stack. The second part is the function described in algebraic notation.
137 Pay attention, in algebraic notation angles must be in radian and not degrees.
138
139
140 \clearpage
141
142
143 \begin{center}
144 \psset{algebraic, fontscale=12}% All functions now in algebraic notation
145 \makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
146 \makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
147 \multido{\rA=0+0.1}{18}{\makebox[1em]{\rA}
148 \makebox[5em]{\psPrintValue[printfont=NimbusSanL-Regu,xShift=-10]{\rA, sin(x)}}
149 \makebox[4em][r]{\psPrintValue[printfont={},fontscale=10,decimals=3,xShift=-20]{\rA,cos(x)}}\hspace{1em}
150 \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,printfont=NimbusSanL-Regu]{\rA,sqrt(x)}}
151 \makebox[7em]{\psPrintValue[comma,printfont=NimbusRomNo9L-ReguItal]{\rA,sin(x)+cos(x)}}
152 \makebox[6em]{\psPrintValue[printfont=Palatino-Roman]{\rA,sin(x)^2+cos(x)^2}}\\}
153 \end{center}
154
155 \bigskip
156
157 \begin{lstlisting}
158 \psset{algebraic, fontscale=12}% All functions now in algebraic notation
159 \makebox[2em]{x(deg)} \makebox[5em]{$\sin x$} \makebox[4em]{$\cos x$}\hspace{1em}
160 \makebox[5em]{$\sqrt x$}\makebox[7em]{$\sin x+\cos x$}\makebox[6em]{$\sin^2 x+\cos^2 x$}\\[3pt]
161 \multido{\rA=0+0.1}{18}{\makebox[1em]{\rA}
162 \makebox[5em]{\psPrintValue[printfont=NimbusSanL-Regu,xShift=-10]{\rA, sin(x)}}
163 \makebox[4em][r]{\psPrintValue[printfont={},fontscale=10,decimals=3,xShift=-20]{\rA,cos(x)}}\hspace{1em}
164 \makebox[5em]{\psPrintValue[valuewidth=15,linecolor=blue,printfont=NimbusSanL-Regu]{\rA,sqrt(x)}}
165 \makebox[7em]{\psPrintValue[comma,printfont=NimbusRomNo9L-ReguItal]{\rA,sin(x)+cos(x)}}
166 \makebox[6em]{\psPrintValue[printfont=Palatino-Roman]{\rA,sin(x)^2+cos(x)^2}}\\}
167 \end{lstlisting}
168
169
170
171 \begin{center}
172 foo \makebox[2em][l]{\psPrintValue[comma]{3.14 10 mul round 10 div}}bar\\[3pt]
173 foo \makebox[2em][l]{\psPrintValue[comma,printfont=StandardSymL,
174 postString=\string\260]{3.14 10 mul round 10 div}}bar\\[3pt]
175 foo \makebox[3.5em][l]{\psPrintValue[printfont=StandardSymL,decimals=6,
176 postString=\string\260]{3.14 dup mul}}bar
177 \end{center}
178
179 \bigskip
180
181 \begin{lstlisting}
182 foo \makebox[2em][l]{\psPrintValue[comma]{3.14 10 mul round 10 div}}bar\\[3pt]
183 foo \makebox[2em][l]{\psPrintValue[comma,printfont=StandardSymL,
184 postString=\string\260]{3.14 10 mul round 10 div}}bar\\[3pt]
185 foo \makebox[3.5em][l]{\psPrintValue[printfont=StandardSymL,decimals=6,
186 postString=\string\260]{3.14 dup mul}}bar
187 \end{lstlisting}
188
189
190 \clearpage
191
192 \section{\nxLcs{psRegisterList}}\label{sec:getElement}
193 The macro defines for every list item an own macro for an easy access to the items.
194 It must be a comma separated list.
195
196 \begin{BDef}
197 \Lcs{psRegisterList}\Largb{Name}\Largb{value list}\\
198 \nxLcs{\Larga{Name}}\Largb{Index}
199 \end{BDef}
200
201
202 \begin{lstlisting}
203 \psRegisterList{Color}{yellow,blue,green,red}% defines macro \Color
204 \begin{pspicture}(-7,-4.5)(7,5.5)
205 \psaxes{->}(0,0)(-6.5,-4.5)(6.75,5)
206 \psset{plotpoints=400,algebraic,linewidth=1pt,fillstyle=solid,opacity=0.4}
207 \multido{\iA=1+1}{4}{%
208 \psplot[linecolor=\Color{\iA},
209 fillcolor=\Color{\iA}!60]{-6.283}{6.283}{\iA*sin(\iA*x)}}%
210 \psset{plotpoints=400,algebraic}
211 \psforeach{\iA}{1,2,3,4}{%
212 \psplot[linecolor=\Color{\iA}]{-6.28}{6.28}{\iA*sin(\iA*x)}}
213 \end{pspicture}
214 \end{lstlisting}
215
216 \psRegisterList{Color}{yellow,blue,green,red}% defines macro \Color
217 \begin{pspicture}(-7,-4.5)(7,5.5)
218 \psaxes{->}(0,0)(-6.5,-4.5)(6.75,5)
219 \psset{plotpoints=400,algebraic,linewidth=1pt,fillstyle=solid,opacity=0.4}
220 \multido{\iA=1+1}{4}{%
221 \psplot[linecolor=\Color{\iA},fillcolor=\Color{\iA}!60]{-6.283}{6.283}{\iA*sin(\iA*x)}}%
222 \psset{plotpoints=400,algebraic}
223 \psforeach{\iA}{1,2,3,4}{%
224 \psplot[linecolor=\Color{\iA}]{-6.28}{6.28}{\iA*sin(\iA*x)}}
225 \end{pspicture}
226
227
228
229 \section{Random numbers}
230 The file \LFile{random.tex} from Donald Arseneau is no more part of CTAN due to a missing licence statement.
231 \LFile{pst-tools} at version 0.10 includes the code. The documentation was inside the package otself:
232
233 Random integers are generated in the range 1 to 2147483646 by the
234 macro \Lcs{nextrandom}. The result is returned in the counter \Lcs{randomi}.
235 Do not change \Lcs{randomi} except, perhaps, to initialize it at some
236 random value. If you do not initialize it, it will be initialized
237 using the time and date. (This is a sparse initialization, giving
238 fewer than a million different starting values, but you should use
239 other sources of numbers if they are available--just remember that
240 most of the numbers available to TeX are not at all random.)
241
242 The \Lcs{nextrandom} command is not very useful by itself, unless you
243 have exactly 2147483646 things to choose from. Much more useful
244 is the \Lcs{setrannum} command which sets a given counter to a random
245 value within a specified range. There are three parameters:
246
247 \Lcs{setrannum\{<counter>\}\{<minimum>\}\{<maximum>\}}
248
249 For example, to
250 simulate a die-roll:
251
252 \verb|\setrannum{\die}{1}{6}| \verb|\ifcase\die...| .
253
254 If you need random numbers that are not integers, you will have to
255 use dimen registers and \Lcs{setrandimen}. For example, to set a random
256 page width:
257
258 \Lcs{setrandimen} \Lcs{hsize\{3in\}\{6.5in\}}
259
260 The »\Lcs{pointless}« macro
261 will remove the »pt« that TeX gives so you can use the dimensions
262 as pure `real' numbers. In that case, specify the range in pt units.
263 For example,
264
265 \verb|\setrandimen\answer{2.71828pt}{3.14159pt}|
266
267 The answer is \verb|\pointless\answer|.
268
269 The random number generator is the one by Lewis, Goodman, and Miller
270 (1969) and used as \texttt{ran0} in »Numerical Recipies« using Schrage's
271 method for avoiding overflows. The multiplier is $16807 (7^5)$, the
272 added constant is 0, and the modulus is $2147483647 (2^{31}-1)$. The
273 range of integers generated is $1 - 2147483646$. A smaller range would
274 reduce the complexity of the macros a bit, but not much--most of the
275 code deals with initialization and type-conversion. On the other hand,
276 the large range may be wasted due to the sparse seed initialization.
277
278
279
280 \section{List of the defined PostScript functions}
281
282 \footnotesize
283 \begin{verbatim}
284 /Pi2 1.57079632679489661925640 def
285 /factorial { % n on stack, returns n!
286 /MoverN { % m n on stack, returns the binomial coefficient m over n
287 /ps@ReverseOrderOfPoints { % on stack [P1 P2 P3 ...Pn]=>[Pn,Pn-1,...,P2,P1]
288 /cxadd { % [a1 b1] [a2 b2] = [a1+a2 b1+b2]
289 /cxneg { % [a b]
290 /cxsub { cxneg cxadd } def % same as negative addition
291 /cxmul { % [a1 b1] [a2 b2]
292 /cxsqr { % % [a b]^2 = [a^2-b^2 2ab] = [a2 b2]
293 /cxsqrt { %
294 /cxarg { % [a b]->arg(z)=atan(b/a)
295 /cxlog { % [a b]->log[a b] = [a^2-b^2 2ab] = [a2 b2]
296 /cxnorm2 { % [a b]->a^2+b^2
297 /cxnorm { %
298 /cxconj { % [a b]->[a -b]
299 /cxre { 0 get } def % real value
300 /cxim { 1 get } def % imag value
301 /cxrecip { % [a b]->1/[a b] = ([a -b]/(a^2+b^2)
302 /cxmake1 { 0 2 array astore } def % make a complex number, real given
303 /cxmake2 { 2 array astore } def % dito, both given
304 /cxdiv { cxrecip cxmul } def
305 /cxrmul { % [a b] r->[r*a r*b]
306 /cxrdiv { % [a b] r->[1/r*a 1/r*b]
307 /cxconv { % theta->exp(i theta) = cos(theta)+i sin(theta) polar<->cartesian
308 /bubblesort { % on stack must be an array [ ... ]
309 /concatstringarray{ % [(a) (b) ... (z)] --> (ab...z) 20100422
310 /concatstrings{ % (a) (b) -> (ab)
311 /reversestring { % (aBC) -> (CBa)
312 /concatarray{ % [a c] [b d] -> [a c b d]
313 /dot2comma {% on stack a string (...)
314 /rightTrim { % on stack the string and the character number to be stripped
315 /psStringwidth /stringwidth load def
316 /psShow /show load def
317 \end{verbatim}
318
319 \normalsize
320
321 \clearpage
322 \section{List of all optional arguments for \texttt{pst-tools}}
323
324 \xkvview{family=pst-tools,columns={key,type,default}}
325
326
327
328
329 \bgroup
330 \raggedright
331 \nocite{*}
332 %\bibliographystyle{plain}
333 \printbibliography
334 \egroup
335
336 \printindex
337
338
339
340 \end{document}
341