diff options
author | Karl Berry <karl@freefriends.org> | 2016-02-12 00:26:01 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-02-12 00:26:01 +0000 |
commit | 07d426b145a3c2e39a7a85b56dc211f9fbd0a0df (patch) | |
tree | d4809cc574ab5869f6e31147aa716fc754ca3c7e /Master/texmf-dist/source | |
parent | 89bd11ec39b2b88d322dca36ee0db6e01050dda3 (diff) |
ran_toks (10feb16)
git-svn-id: svn://tug.org/texlive/trunk@39684 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
-rw-r--r-- | Master/texmf-dist/source/latex/ran_toks/ran_toks.dtx | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/Master/texmf-dist/source/latex/ran_toks/ran_toks.dtx b/Master/texmf-dist/source/latex/ran_toks/ran_toks.dtx index 5236428ec86..be22614b340 100644 --- a/Master/texmf-dist/source/latex/ran_toks/ran_toks.dtx +++ b/Master/texmf-dist/source/latex/ran_toks/ran_toks.dtx @@ -29,7 +29,7 @@ %</internal> %<*copyright> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% ran_toks.sty package, 2012/10/29 %% +%% ran_toks.sty package, 2013/08/03 %% %% Copyright (C) 2012 D. P. Story %% %% dpstory@uakron.edu %% %% %% @@ -42,7 +42,7 @@ %</copyright> %<package>\NeedsTeXFormat{LaTeX2e} %<package>\ProvidesPackage{ran_toks} -%<package> [2012/11/18 v1.0a Randomizing tokens] +%<package> [2016/02/06 v1.0e Randomizing tokens] %<*driver> \documentclass{ltxdoc} %\usepackage{\jobname} @@ -114,7 +114,11 @@ % and \texttt{random.tex}, the package was written by Donald Arseneau. % \begin{macrocode} \RequirePackage{verbatim} -\input{random.tex} +% \end{macrocode} +% Input \texttt{random.tex} if now already input. +%\changes{v1.0d}{2013/08/03}{Added conditional input of random.tex} +% \begin{macrocode} +\@ifundefined{nextrandom}{\input{random.tex}}{} % \end{macrocode} % We redefine \cs{nextrandom} from \texttt{random.tex} to save the initializing seed. % \begin{macrocode} @@ -128,8 +132,9 @@ \nextrandom \nextrandom \nextrandom % \end{macrocode} % Save the initial seed value to \cs{rtInitSeedValue}. +% \changes{v1.0c}{2013/08/03}{Save the initial seed value to \cs{rtInitSeedValue}.} % \begin{macrocode} - \xdef\rtInitSeedValue{\the\randomi}% + \xdef\InitSeedValue{\the\randomi}% \fi \count@ii\randomi \divide\count@ii 127773 % modulus = multiplier * 127773 + 2836 @@ -181,22 +186,30 @@ % last random seed. If the file \cs{jobname\_rt.sav} does not exist, the generator will be % initialized using time and date data. % \begin{macrocode} -\def\useLastAsSeed{\IfFileExists{\jobname_rt.sav}% - {% +\def\useLastAsSeed{\rt@useLastAsSeed} +\@onlypreamble\useLastAsSeed +\def\rt@useLastAsSeed{% + \IfFileExists{\jobname_rt.sav}{% \PackageInfo{ran_toks}{Inputting \jobname_rt.sav}% - \newread\readsavfile + \@ifundefined{readsavfile}{\newread\readsavfile}{}% \openin\readsavfile=\jobname_rt.sav - \read\readsavfile to \rtInitSeedValue + \read\readsavfile to \InitSeedValue \read\readsavfile to \lastRandomNum \closein\readsavfile \randomi=\lastRandomNum +% \end{macrocode} +% When \cs{useLastAsSeed}, the last becomes the first. +% \begin{macrocode} + \xdef\InitSeedValue{\the\randomi} }{% \PackageInfo{ran_toks}{\jobname_rt.sav cannot be found, \MessageBreak using the random initializer}% }% } -\@onlypreamble\useLastAsSeed +\@ifundefined{aeb@randomizeChoices}{% + \let\inputRandomSeed\useLastAsSeed + \let\useRandomSeed\useThisSeed}{} % \end{macrocode} % % \section{Utility commands} @@ -215,18 +228,18 @@ % \end{macrocode} % We write only if \cs{ifsaveseed} is true. % \begin{macrocode} -\def\rtInitSeedValue{\the\randomi} +\def\InitSeedValue{\the\randomi} \def\rt@writeSeedData{% \ifsaveseed - \newwrite\rt@savedata - \immediate\openout \rt@savedata \jobname_rt.sav - \let\verbatim@out\rt@savedata + \@ifundefined{saveseedinfo}{\newwrite\saveseedinfo}{} + \immediate\openout \saveseedinfo \jobname_rt.sav + \let\verbatim@out\saveseedinfo \def\rt@msgi{initializing seed value}% \def\rt@msgii{last random number used}% \uccode`c=`\%\uppercase{% - \rt@IWVO{\rtInitSeedValue\space c \rt@msgi}% + \rt@IWVO{\InitSeedValue\space c \rt@msgi}% \rt@IWVO{\the\randomi\space c \rt@msgii}% - }% + }\immediate\closeout\saveseedinfo \fi } % \end{macrocode} @@ -387,13 +400,16 @@ % \DescribeMacro{\r@ndToks} is main looping command for \cs{ranToks} % and \cs{eRTVToks} (through \cs{r@nVToks}). If the ending token \cs{rt@NIL} is detected, we % break off and go to \cs{rt@endToks}. +% \changes{v1.0e}{2016/02/06}{Fixed a bug, when the first two tokens \texttt{\#1} are the same, +% we get an incorrect decision} % \begin{macrocode} -\long\def\r@ndToks#1{% +\def\rt@PAR{\par} +\long\def\r@ndToks#1{\def\rt@rgi{#1}% % \end{macrocode} % If the current argument is \cs{par}, we skip it % \begin{macrocode} - \ifx#1\par\def\rt@next{\r@ndToks}\else - \advance\rt@nMax1 + \ifx\rt@rgi\rt@PAR\def\rt@next{\r@ndToks}\else + \advance\rt@nMax1\relax \global\@namedef{rtTok\the\rt@nMax\rt@BaseName}{#1}% \def\rt@next{\@ifnextchar\rt@NIL {\rt@endToks\@gobble}{\r@ndToks}}% @@ -427,7 +443,8 @@ % \begin{macrocode} \def\assignRanToks#1{\advance\rt@nCnt1 \global\rt@nameedef{rtRanTok\the\rt@nCnt\rt@BaseName}% - {\noexpand\rtTokByNum[\rt@BaseName]{#1}}% + {\noexpand\@nameuse{rtTok#1\rt@BaseName}}% +% {\noexpand\rtTokByNum[\rt@BaseName]{#1}}% } % \end{macrocode} % \subsection{Additional user access commands} @@ -439,13 +456,26 @@ % The argument of it is an integer, eg, \verb!\rtTokByNum{3}! is the third token, as listed in the order % given in the argument of \cs{ranToks}. % \begin{macrocode} -\newcommand{\rtTokByNum}[2][\rt@BaseName]{\@nameuse{rtTok#2#1}\ignorespaces} +\newcommand{\rtTokByNum}[2][\rt@BaseName]{\@nameuse{rtTok#2#1}% + \ignorespaces} % \end{macrocode} %\DescribeMacro{\useRanTok} After \cs{ranToks} has been executed, the user has access to the % randomized tokens through \cs{useRanTok}. The argument is an integer 1 through max. % \begin{macrocode} \newcommand{\useRanTok}[2][\rt@BaseName]{\@nameuse{rtRanTok#2#1}} % \end{macrocode} +% \DescribeMacro{\displayListRandomly} lists all items in the list as passed +% by the required argument. For expanding in a list environment, use \cs{item} as +% the optional argument. Designed for listing all question in an eqexam +% document in random order. +%\changes{v1.0b}{2013/07/29}{Added \cs{displayListRandomly}} +%\changes{v1.0e}{2016/02/06}{Added optional argument to \cs{displayListRandomly}} +% \begin{macrocode} +\newcommand{\displayListRandomly}[2][]{\rt@nCnt=0\relax + \@whilenum\rt@nCnt<\nToksFor{#2}\advance\rt@nCnt1\relax + \do{#1\useRanTok{\the\rt@nCnt}}% +} +% \end{macrocode} % \begin{macrocode} %</package> % \end{macrocode} |