Debian Codegraph @

texmf-dist/doc/latex/ran_toks/examples/ran-toks.tex

raw
1 \documentclass{article}
2 \usepackage{ran_toks}
3 \usepackage{ifthen}
4
5 \useThisSeed{606574325} % comment out this line, and uncomment next line to get ...
6 %\useLastAsSeed % a new pseudo-random sequence each time you compile.
7
8 % Other useful switches
9 %\ranToksOn % the default
10 %\ranToksOff
11
12 \parindent0pt \parskip6pt
13 \def\cs#1{\texttt{\char`\\#1}}
14
15 \begin{document}
16 \begin{center}\bfseries
17 Test file for \textsf{ran\_toks} Package\\[3pt]
18 D. P. Story
19 \end{center}
20
21 Test of the \verb!\ranToks! command.
22
23 \ranToks{myPals}{%
24 {Jim}{Richard}{Don}
25 {Alex}{Tom}{J\"{u}rgen}
26 }
27 I have {\nToksFor{myPals}} pals, they are \useRanTok{1}, \useRanTok{2},
28 \useRanTok{3}, \useRanTok{4}, {\useRanTok{5}} and \useRanTok{6}. (Listed
29 in the order of best friend to least best friend.)
30
31 Test of the \verb!\bRTVToks!/\verb!\eRTVToks! pair of commands, which encloses
32 \texttt{rtVW} environments.
33
34 \bRTVToks{myThoughts}%
35 \begin{rtVW}
36 \begin{minipage}[t]{.67\linewidth}
37 Roses are red and violets are blue,
38 I've forgotten the rest, have you too?
39 \end{minipage}
40 \end{rtVW}
41 \begin{rtVW}
42 \begin{minipage}[t]{.67\linewidth}
43 I gave up saying bad things like
44 \verb!$#%%%^*%^&#$@#! when I was just a teenager.
45 \end{minipage}
46 \end{rtVW}
47 \begin{rtVW}
48 \begin{minipage}[t]{.67\linewidth}
49 I am a good guy, pass it on! The code for this last sentence is,
50 \begin{verbatim}
51 %#$% I am a good guy, pass it on! ^&*&^*
52 \end{verbatim}
53 How did that other stuff get in there?
54 \end{minipage}
55 \end{rtVW}
56 \eRTVToks
57 \begin{enumerate}
58 \displayListRandomly[\item]{myThoughts}
59 \end{enumerate}
60
61 Use \verb!\useRTName! command when another list separates the current
62 position from the list you want to use. Here we want to use the list named
63 \texttt{myPals}, but since that definition, a new list named
64 \texttt{myThoughts} was declared.
65
66 \useRTName{myPals}
67 List of pals: \useRanTok{1}, \useRanTok{2}, \useRanTok{3},
68 \useRanTok{4}, \useRanTok{5}, and \useRanTok{6}.
69
70 For mixing lists. it might be easier to use the optional parameter:
71 {\useRanTok[myPals]{1}} and \useRanTok[myThoughts]{1}
72
73 The \cs{rtTokByNum} can retrieve an item from the list in its declared order;
74 eg, from the \texttt{myPals} list, the first and last are
75 {\rtTokByNum[myPals]{1}} and \rtTokByNum[myPals]{\nToksFor{myPals}}.
76
77 We demonstrate the command \cs{reorderRanToks} and the optional parameters of \cs{displayListRandomly}:
78 \begin{quote}\reorderRanToks{myPals}%
79 List of pals: \displayListRandomly[\ifnum\i=\last\space and \fi][\ifnum\i=\last.\else,\fi\space]{myPals}
80 \end{quote}
81 The reordering is global, so \displayListRandomly[\ifnum\i=\last\space and \fi][\ifnum\i=\last\else, \fi]{myPals}
82 are listed in the same order as above, and different from the original random order seen in the second paragraph
83 of this document.
84
85 Without the Oxford comma: My pals are
86 \displayListRandomly[\ifnum\i=\last and \fi][\ifnum\i=\last.\else\ifnum\i=\lessone\relax\space\else, \fi\fi]{myPals}
87
88 The following is the same logic but uses the syntax of the \textsf{ifthen} package: My pals are
89 \displayListRandomly[\ifthenelse{\i=\last}{and }{}][\ifthenelse{\i=\last}{.}{\ifthenelse{\i=\lessone}{\space}{, }}]{myPals}
90
91 Test the \cs{copyRanToks} command:
92 \copyRanToks{myPals}{myPals1}\displayListRandomly[\ifthenelse{\i=\last}{and }{}][\ifthenelse{\i=\last}{.}{\ifthenelse{\i=\lessone}{\space}{, }}]{myPals1}
93 This does not change the order of the \texttt{myPals} list, which is still
94 \displayListRandomly[\ifnum\i=\last\space and \fi][\ifnum\i=\last.\else,\fi\space]{myPals}
95
96 \end{document}