summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ran_toks/ran_toks.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/ran_toks/ran_toks.dtx')
-rw-r--r--macros/latex/contrib/ran_toks/ran_toks.dtx55
1 files changed, 38 insertions, 17 deletions
diff --git a/macros/latex/contrib/ran_toks/ran_toks.dtx b/macros/latex/contrib/ran_toks/ran_toks.dtx
index 5549bbc01c..7b247d20ce 100644
--- a/macros/latex/contrib/ran_toks/ran_toks.dtx
+++ b/macros/latex/contrib/ran_toks/ran_toks.dtx
@@ -16,7 +16,7 @@
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
%<package>\ProvidesPackage{ran_toks}
-%<package> [2021/01/19 v1.3.1 Randomizing tokens (dps)]
+%<package> [2021/06/06 v1.4 Randomizing tokens (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,hyperindex=false]{hyperref}
@@ -113,7 +113,7 @@
%\useRanTok{1}, \useRanTok{2},..., \useRanTok{n}
%\end{Verbatim}
% Other details are left to the readers' imagination.
-%
+% \changes{v1.4}{2021/06/06}{Rounded up v1.3.3 to v1.4 for publication}
% \paragraph{Requirements.} As of this writing, we require only the \texttt{verbatim} package
% and \texttt{random.tex}, the package was written by Donald Arseneau.
% \begin{macrocode}
@@ -437,15 +437,15 @@
% access to the contents of the \texttt{rtVW} environments, this done by
% \cs{r@nVToks}.
% \begin{macrocode}
-\newcommand{\eRTVToks}{\global
- \rt@nameedef{\rt@BaseName Cnt}{\the\rt@nCnt}\expandafter
+\newcommand{\eRTVToks}{%
+ \global\rt@nameedef{\rt@BaseName Cnt}{\the\rt@nCnt}\expandafter
\r@nVToks\expandafter{\rt@BaseName}}
% \end{macrocode}
% \end{macro}
% \begin{environment}{rtVW}
% \cs{rtVW} is a verbatim write environment. It saves its contents to the file
% \verb!\jobname_\rt@BaseName-\the\rt@nCnt.cut!. The file is later input back into
-% the source file in a random way. % J14
+% the source file in a random way.
% \begin{macrocode}
\def\reVerbEnd{\ifhmode\unskip\fi}
% \end{macrocode}
@@ -464,6 +464,8 @@
\def\rtVWId#1{\ifviewIDs\noindent#1\fi
\ifxDBUnique\ifrt@InputUsedIDs\wrtProbIds{#1}\fi\fi
}
+% \end{macrocode}
+% \begin{macrocode}
\newenvironment{rtVW}{\global\advance\rt@nCnt\@ne
\immediate\openout\rt@Verb@write
\jobname_\rt@BaseName-\the\rt@nCnt.cut
@@ -478,6 +480,15 @@
\immediate\closeout\rt@Verb@write
}
% \end{macrocode}
+% (2021/05/29) In support of nested |\bRTVToks/\eRTVToks| constructs, we \cs{let}
+% \cs{rtVWi} and \cs{rtVWii} to \cs{rtVW}, and \cs{endrtVWi} and \cs{endrtVWii} to \cs{endrtVW}.
+% \changes{v1.3.3}{2021/05/29}{Assign \string\cs{rtVWi} and \string\cs{endrtVWi}}
+% \begin{macrocode}
+\let\rtVWi\rtVW % dps5-29
+\let\endrtVWi\endrtVW
+\let\rtVWii\rtVW % dps5-29
+\let\endrtVWii\endrtVW
+% \end{macrocode}
% \end{environment}
% \DescribeMacro{\r@nVToks} randomizes the contents of the \texttt{rtVW}
% environment.
@@ -699,12 +710,14 @@
%\changes{v1.0b}{2013/07/29}{Added \string\cs{displayListRandomly}}
%\changes{v1.0e}{2016/02/06}{Added optional argument to \string\cs{displayListRandomly}}
%\changes{v1.1}{2017/05/04}{Added second optional argument to \string\cs{displayListRandomly}}
+%\changes{v1.3.3}{2021/05/29}{In support of nested \string\cs{bRTVToks}/\string\cs{eRTVToks}\space
+% constructs, replace the counter \string\cs{rt@nCnt} with \string\cs{@tempcntb}}
% \begin{macrocode}
-\newcommand{\displayListRandomly}[1][]{\bgroup
+\newcommand{\displayListRandomly}[1][]{\begingroup
\def\rt@prior{#1}\displ@yListRandomly
}
-\newcommand{\displ@yListRandomly}[2][]{\rt@nCnt\z@\expandafter
- \ifx\csname nMax4#2\endcsname\relax
+\newcommand{\displ@yListRandomly}[2][]{\@tempcntb\z@ % dps5-29
+ \expandafter\ifx\csname nMax4#2\endcsname\relax
\rt@rgi\space\textbf{??}\rt@badTokName{#2}#1%
\else
\rt@recordingfalse
@@ -715,14 +728,21 @@
% These four macro are defined locally and not available outside the command
% \cs{displayListRandomly}.
% \begin{macrocode}
- \def\rt@post{#1}\useRTName{#2}\let\i\rt@nCnt
+ \def\rt@post{#1}\useRTName{#2}\let\i\@tempcntb
\def\first{1}\edef\last{\@nameuse{nMax4#2}}\@tempcnta\last
\advance\@tempcnta\m@ne
- \edef\lessone{\the\@tempcnta}\@whilenum\rt@nCnt<\last
- \advance\rt@nCnt\@ne
- \do{\rt@prior\useRanTok{\the\rt@nCnt}\rt@post
+ \edef\lessone{\the\@tempcnta}\@whilenum\@tempcntb<\last
+ \advance\@tempcntb\@ne
+% \end{macrocode}
+% There is one example of this command getting confused and printing the wrong
+% number of items. Here, we pass the optional argument of \cs{useRanTok} and that
+% cleared up the problem.
+% \changes{v1.3.2}{2021/05/25}{Insert optional argument for \string\cs{useRanTok}
+% within \string\cs{displ@yListRandomly}}
+% \begin{macrocode}
+ \do{\rt@prior\useRanTok[#2]{\the\@tempcntb}\rt@post
}\fi
- \egroup
+ \endgroup
}
%</package>
%<*dbapp>
@@ -866,10 +886,11 @@
\def\rt@STOP{\relax}%
% \end{macrocode}
%We use the randomized list for the \ameta{name}
-%\begin{verbatim}
-% \@nameuse{#1-List} is the randomized list: eg,
-% \\{3}\\{2}\\{4}\\{5}\\{1}
-%\end{verbatim}
+\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
+%commandchars={!()},codes={\catcode`\%=9}]
+%\@nameuse{#1-List} is the randomized list: eg,
+%\\{3}\\{2}\\{4}\\{5}\\{1}
+%\end{Verbatim}
% \begin{macrocode}
\let\\\relax\edef\x{\@nameuse{#1-List}}%
\toks@=\expandafter{\x}\let\\\getR@nIndx