| 1 |
%% $Id: pst-tools.tex 265 2021-09-24 18:47:41Z herbert $ |
| 2 |
%% |
| 3 |
%% This is file `pst-tools.tex', |
| 4 |
%% |
| 5 |
%% IMPORTANT NOTICE: |
| 6 |
%% |
| 7 |
%% Package `pst-tools.tex' |
| 8 |
%% |
| 9 |
%% Herbert Voss <[email protected]> |
| 10 |
%% |
| 11 |
%% This program can be redistributed and/or modified under the terms |
| 12 |
%% of the LaTeX Project Public License Distributed from CTAN archives |
| 13 |
%% in directory macros/latex/base/lppl.txt. |
| 14 |
%% |
| 15 |
%% DESCRIPTION: |
| 16 |
%% `pst-tools' is a PSTricks package for helper functions |
| 17 |
%% |
| 18 |
%% |
| 19 |
\csname PSTtoolsLoaded\endcsname |
| 20 |
\let\PSTtoolsLoaded\endinput |
| 21 |
|
| 22 |
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi |
| 23 |
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey.tex \fi |
| 24 |
% |
| 25 |
\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax |
| 26 |
% interface to the `xkeyval' package |
| 27 |
\pst@addfams{pst-tools} |
| 28 |
% |
| 29 |
\def\fileversion{0.12} |
| 30 |
\def\filedate{2021/09/23} |
| 31 |
\message{`PST-tools' v\fileversion, \filedate\space (hv)} |
| 32 |
% |
| 33 |
\define@key[psset]{pst-tools}{decimalSeparator}[.]{\def\psk@decimalSeparator{#1}}% |
| 34 |
\define@boolkey[psset]{pst-tools}[Pst@]{comma}[true]{% |
| 35 |
\ifPst@comma\def\psk@decimalSeparator{,}\else\def\psk@decimalSeparator{.}\fi} |
| 36 |
\define@boolkey[psset]{pst-tools}[Pst@]{trimSpaces}[true]{} |
| 37 |
\define@key[psset]{pst-tools}{xShift}[0]{\def\psk@xShift{#1}} |
| 38 |
\define@key[psset]{pst-tools}{yShift}[0]{\def\psk@yShift{#1}} |
| 39 |
\define@key[psset]{pst-tools}{postString}[{}]{\def\psk@postString{#1}} |
| 40 |
\define@key[psset]{pst-tools}{VarName}[]{\def\psk@VarName{#1 }} |
| 41 |
\define@key[psset]{pst-tools}{printfont}[NimbusRomNo9L-Regu]{% |
| 42 |
\ifPSTlualatex |
| 43 |
\expandafter\ifx\expandafter\relax#1\relax |
| 44 |
\def\psk@printfont{ \fontid\font\space .findfontid }% |
| 45 |
\else |
| 46 |
\def\psk@printfont{ /#1 findfont }% |
| 47 |
\fi |
| 48 |
\else |
| 49 |
\ifx\relax#1\relax |
| 50 |
\def\psk@printfont{ /NimbusRomNo9L-Regu findfont }% |
| 51 |
\else |
| 52 |
\def\psk@printfont{ /#1 findfont }% |
| 53 |
\fi |
| 54 |
\fi |
| 55 |
}% |
| 56 |
\define@key[psset]{pst-tools}{valuewidth}[10]{\pst@getint{#1}\psk@valuewidth } |
| 57 |
\define@key[psset]{pst-tools}{fontscale}[10]{\pst@checknum{#1}\psk@fontscale } |
| 58 |
\define@key[psset]{pst-tools}{decimals}[-1]{\pst@getint{#1}\psk@decimals } |
| 59 |
\psset[pst-tools]{printfont=Helvetica,fontscale=10,valuewidth=10,decimals=-1, |
| 60 |
xShift=0,yShift=0,trimSpaces=false,postString={},VarName={}, |
| 61 |
comma=false,decimalSeparator=.} |
| 62 |
% |
| 63 |
\def\txG{ true setglobal globaldict begin } |
| 64 |
\def\etxG{ end false setglobal } |
| 65 |
% |
| 66 |
\newpsstyle{mmpaper}{subgriddiv=5,gridlabels=0,gridwidth=1pt,gridcolor=orange,subgridwidth=0.1pt,subgridcolor=orange!90} |
| 67 |
% |
| 68 |
\def\psPrintValue{\pst@object{psPrintValue}} |
| 69 |
\def\psPrintValue@i#1{\expandafter\psPrintValue@ii#1,,\@nil} |
| 70 |
\def\psPrintValue@ii#1,#2,#3\@nil{% #1,#2 only for algebraic code |
| 71 |
\begin@SpecialObj |
| 72 |
\addto@pscode{ |
| 73 |
gsave \psk@printfont \psk@fontscale scalefont setfont |
| 74 |
\ifPst@algebraic |
| 75 |
/x #1 def |
| 76 |
/Func (#2) tx@AlgToPs begin AlgToPs end cvx def |
| 77 |
Func |
| 78 |
\else |
| 79 |
#1 |
| 80 |
\fi |
| 81 |
\ifx\relax\psk@VarName\relax\else dup \txG 10 string cvs /\psk@VarName\space exch def \etxG \fi |
| 82 |
\psk@decimals -1 gt { 10 \psk@decimals exp dup 3 1 roll mul cvi exch div } if |
| 83 |
\psk@valuewidth string cvs %/Output exch def % save output |
| 84 |
%/concatstringarray % [(a) (b) ... (z)] --> (ab...z) 20100422 |
| 85 |
\ifx\relax\psk@postString\relax\else [ exch (\psk@postString) ] concatstringarray \fi |
| 86 |
\ifPst@trimSpaces rightTrim \fi |
| 87 |
\ifPst@comma dot2comma \fi % do we have to change dot to comma |
| 88 |
\psk@xShift\space \psk@yShift\space moveto %Output |
| 89 |
show grestore |
| 90 |
}% |
| 91 |
\end@SpecialObj |
| 92 |
} |
| 93 |
|
| 94 |
\define@boolkey[psset]{pst-tools}[Pst@]{round}[true]{}% |
| 95 |
\define@boolkey[psset]{pst-tools}[Pst@]{science}[true]{% |
| 96 |
\ifPst@science\def\psk@Scin{true }\else\def\psk@Scin{false }\fi} |
| 97 |
\psset[pst-tools]{science=false,round=false} |
| 98 |
% |
| 99 |
\def\psPrintValueNew{\pst@object{psPrintValueNew}} |
| 100 |
\def\psPrintValueNew@i#1{\expandafter\psPrintValueNew@ii#1,,!!} |
| 101 |
\def\psPrintValueNew@ii#1,#2,#3!!{% #1,#2 only for algebraic code |
| 102 |
\begin@SpecialObj |
| 103 |
\addto@pscode{ % thanks to Buddy Ledger |
| 104 |
/mfont { \psk@printfont |
| 105 |
\psk@fontscale scalefont setfont } bind def |
| 106 |
/mfontexp { \psk@printfont |
| 107 |
\psk@fontscale 1.2 div scalefont setfont } bind def |
| 108 |
/s1 { /StandardSymL findfont \psk@fontscale scalefont setfont } bind def |
| 109 |
\ifPst@algebraic |
| 110 |
/x #1 def |
| 111 |
/Func (#2) tx@AlgToPs begin AlgToPs end cvx def |
| 112 |
Func |
| 113 |
\else #1 \fi |
| 114 |
/value exch def |
| 115 |
\psk@Scin { |
| 116 |
value 0 ne { value log floor cvi /expon exch def }{ /expon 0 def } ifelse |
| 117 |
value 10 expon exp div |
| 118 |
\psk@decimals -1 gt { 10 \psk@decimals exp dup 3 1 roll mul |
| 119 |
\ifPst@round round \else cvi \fi exch div } if |
| 120 |
\psk@decimals 0 eq { cvi } if /numb exch def |
| 121 |
expon \psk@valuewidth string cvs /expon exch def |
| 122 |
numb \psk@valuewidth string cvs |
| 123 |
\ifPst@comma dot2comma \fi % do we have to change dot to comma |
| 124 |
/Output exch def |
| 125 |
/txspc \psk@fontscale 4 div def |
| 126 |
\psk@xShift\space 0 moveto mfont Output show |
| 127 |
txspc 0 rmoveto s1 (\string\264) show |
| 128 |
txspc 0 rmoveto mfont (10) show |
| 129 |
txspc 2 div txspc 1.5 mul rmoveto mfontexp expon show } |
| 130 |
{ value |
| 131 |
\psk@decimals -1 gt { 10 \psk@decimals exp dup 3 1 roll mul |
| 132 |
\ifPst@round round \else cvi \fi exch div } if |
| 133 |
\psk@decimals 0 eq { cvi } if %inserted to handle decimals=0 |
| 134 |
\psk@valuewidth string cvs |
| 135 |
\ifPst@comma dot2comma \fi % do we have to change dot to comma |
| 136 |
\psk@xShift\space 0 moveto mfont %Output |
| 137 |
show |
| 138 |
} ifelse |
| 139 |
}% |
| 140 |
\end@SpecialObj |
| 141 |
} |
| 142 |
% |
| 143 |
\def\psRegisterList#1#2{% |
| 144 |
\@namedef{#1}##1{\@nameuse{#1##1}}% |
| 145 |
\pst@cnto=1 |
| 146 |
\@for\pst@tempA:=#2\do{% |
| 147 |
\edef\pst@tempB{\@namedef{#1\the\pst@cnto}{\pst@tempA}}% |
| 148 |
\pst@tempB |
| 149 |
\advance\pst@cnto by 1 |
| 150 |
}% |
| 151 |
} |
| 152 |
% RANDOM.TEX v.1 (Donald Arseneau) |
| 153 |
% Generating "random" numbers in TeX. |
| 154 |
% |
| 155 |
% Random integers are generated in the range 1 to 2147483646 by the |
| 156 |
% macro \nextrandom. The result is returned in the counter \randomi. |
| 157 |
% Do not change \randomi except, perhaps, to initialize it at some |
| 158 |
% random value. If you do not initialize it, it will be initialized |
| 159 |
% using the time and date. (This is a sparse initialization, giving |
| 160 |
% fewer than a million different starting values, but you should use |
| 161 |
% other sources of numbers if they are available--just remember that |
| 162 |
% most of the numbers available to TeX are not at all random.) |
| 163 |
% |
| 164 |
% The \nextrandom command is not very useful by itself, unless you |
| 165 |
% have exactly 2147483646 things to choose from. Much more useful |
| 166 |
% is the \setrannum command which sets a given counter to a random |
| 167 |
% value within a specified range. There are three parameters: |
| 168 |
% \setrannum {<counter>} {<minimum>} {<maximum>}. For example, to |
| 169 |
% simulate a die-roll: \setrannum{\die}{1}{6} \ifcase\die... . |
| 170 |
% |
| 171 |
% If you need random numbers that are not integers, you will have to |
| 172 |
% use dimen registers and \setrandimen. For example, to set a random |
| 173 |
% page width: \setrandimen \hsize{3in}{6.5in}. The "\pointless" macro |
| 174 |
% will remove the "pt" that TeX gives so you can use the dimensions |
| 175 |
% as pure `real' numbers. In that case, specify the range in pt units. |
| 176 |
% For example, |
| 177 |
% \setrandimen\answer{2.71828pt}{3.14159pt} |
| 178 |
% The answer is \pointless\answer. |
| 179 |
% |
| 180 |
% The random number generator is the one by Lewis, Goodman, and Miller |
| 181 |
% (1969) and used as "ran0" in "Numerical Recipies" using Schrage's |
| 182 |
% method for avoiding overflows. The multiplier is 16807 (7^5), the |
| 183 |
% added constant is 0, and the modulus is 2147483647 (2^{31}-1). The |
| 184 |
% range of integers generated is 1 - 2147483646. A smaller range would |
| 185 |
% reduce the complexity of the macros a bit, but not much--most of the |
| 186 |
% code deals with initialization and type-conversion. On the other hand, |
| 187 |
% the large range may be wasted due to the sparse seed initialization. |
| 188 |
|
| 189 |
\newcount\randomi % the random number seed (while executing) |
| 190 |
\global\randomi\catcode`\@ % scratch variable during definitions |
| 191 |
\catcode`\@=11 |
| 192 |
|
| 193 |
\def\nextrandom{\begingroup |
| 194 |
\ifnum\randomi<\@ne % then initialize with time |
| 195 |
\global\randomi\time |
| 196 |
\global\multiply\randomi388 \global\advance\randomi\year |
| 197 |
\global\multiply\randomi31 \global\advance\randomi\day |
| 198 |
\global\multiply\randomi97 \global\advance\randomi\month |
| 199 |
\message{Randomizer initialized to \the\randomi.}% |
| 200 |
\nextrandom \nextrandom \nextrandom |
| 201 |
\fi |
| 202 |
\count@ii\randomi |
| 203 |
\divide\count@ii 127773 % modulus = multiplier * 127773 + 2836 |
| 204 |
\count@\count@ii |
| 205 |
\multiply\count@ii 127773 |
| 206 |
\global\advance\randomi-\count@ii % random mod 127773 |
| 207 |
\global\multiply\randomi 16807 |
| 208 |
\multiply\count@ 2836 |
| 209 |
\global\advance\randomi-\count@ |
| 210 |
\ifnum\randomi<\z@ \global\advance\randomi 2147483647\relax\fi |
| 211 |
\endgroup |
| 212 |
} |
| 213 |
|
| 214 |
\countdef\count@ii=2 % use only in boxes! |
| 215 |
\ifx\@tempcnta\undefined \csname newcount\endcsname \@tempcnta \fi |
| 216 |
\ifx\@tempcntb\undefined \csname newcount\endcsname \@tempcntb \fi |
| 217 |
|
| 218 |
\def\setrannum#1#2#3{% count register, minimum, maximum |
| 219 |
\@tempcnta#3\advance\@tempcnta-#2\advance\@tempcnta\@ne |
| 220 |
\@tempcntb 2147483645 % = m - 2 = 2^{31} - 3 |
| 221 |
\divide\@tempcntb\@tempcnta |
| 222 |
\getr@nval |
| 223 |
\advance\ranval#2\relax |
| 224 |
#1\ranval |
| 225 |
} |
| 226 |
|
| 227 |
\def\setrandim#1#2#3{% dimen register, minimum length, maximum length |
| 228 |
\dimen@#2\dimen@ii#3\relax |
| 229 |
\setrannum\ranval\dimen@\dimen@ii |
| 230 |
#1\ranval sp\relax |
| 231 |
} |
| 232 |
|
| 233 |
\def\getr@nval{% The values in \@tempcnta and \@tempcntb are parameters |
| 234 |
\nextrandom |
| 235 |
\ranval\randomi \advance\ranval\m@ne \divide\ranval\@tempcntb |
| 236 |
\ifnum\ranval<\@tempcnta\else \expandafter\getr@nval \fi |
| 237 |
} |
| 238 |
|
| 239 |
\def\pointless{\expandafter\PoinTless\the} |
| 240 |
{\catcode`p=12 \catcode`t=12 |
| 241 |
\gdef\PoinTless#1pt{#1}} |
| 242 |
|
| 243 |
\catcode`\@=\randomi |
| 244 |
\global\randomi=0 |
| 245 |
\newcount\ranval |
| 246 |
|
| 247 |
\catcode`\@=\PstAtCode\relax |
| 248 |
% |
| 249 |
%% END: pst-tools.tex |
| 250 |
\endinput |
| 251 |
% |