From 7b5a3fd458aadd8e0f254ccdcf8594030b46f1d5 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sun, 26 Sep 2021 21:00:24 +0000
Subject: scrambledenvs (25sep21)

git-svn-id: svn://tug.org/texlive/trunk@60615 c570f23f-e606-0410-a88d-b1316a301751
---
 .../tex/latex/scrambledenvs/scrambledenvs.sty      | 52 +++++++++++++++-------
 1 file changed, 36 insertions(+), 16 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/scrambledenvs/scrambledenvs.sty')

diff --git a/Master/texmf-dist/tex/latex/scrambledenvs/scrambledenvs.sty b/Master/texmf-dist/tex/latex/scrambledenvs/scrambledenvs.sty
index 3b44bedbeac..615acf1051e 100644
--- a/Master/texmf-dist/tex/latex/scrambledenvs/scrambledenvs.sty
+++ b/Master/texmf-dist/tex/latex/scrambledenvs/scrambledenvs.sty
@@ -27,7 +27,8 @@
 
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{scrambledenvs}[2021/08/03 v1.0.1 Create and print scrambled environments]
+\ProvidesPackage{scrambledenvs}[2021/09/26 v1.1.0 Create and print scrambled environments]
+\RequirePackage{ifthen}
 \RequirePackage{forloop}
 \RequirePackage{pgfmath}
 \pgfmathsetseed{2407}
@@ -49,11 +50,11 @@
 \else
     \ifnum\value{scrambledenvs@#1@tempcount}=1\relax
         {\csname scrambledenvs@#1@labelfont\endcsname\csname scrambledenvs@#1@label\endcsname :}
-        {\csname scrambledenvs@#1@reffont\endcsname\ref{#1:\value{scrambledenvs@#1@count}}}%
+        {\csname scrambledenvs@#1@reffont\endcsname\csname scrambledenvs@#1@refprefix\endcsname\ref{#1:\the\numexpr\value{scrambledenvs@#1@count}}}%
     \else
         {\csname scrambledenvs@#1@labelfont\endcsname\csname scrambledenvs@#1@label\endcsname s:}
         \forloop{scrambledenvs@loopcount}{\the\numexpr\value{scrambledenvs@#1@count}-\value{scrambledenvs@#1@tempcount}+1\relax}{\value{scrambledenvs@loopcount}<\the\numexpr\value{scrambledenvs@#1@count}+1\relax} {%
-            {\csname scrambledenvs@#1@reffont\endcsname\ref{#1:\thescrambledenvs@loopcount}}
+            {\csname scrambledenvs@#1@reffont\endcsname\csname scrambledenvs@#1@refprefix\endcsname\ref{#1:\thescrambledenvs@loopcount}}
         }
     \fi
 \fi
@@ -72,31 +73,45 @@
 {%
     \endfilecontents
 }
+\expandafter\def\csname scrambledenvs@#1@start\endcsname{1}
 \expandafter\newcommand\csname print#1\endcsname{%
     \ifscrambledenvs@scramble %\if
         \ifcsname thescrambledenvs@#1@count\endcsname
-            \ifnum\value{scrambledenvs@#1@count}>0\relax
-                \expandafter\edef\csname pgfmath@randomlist@#1\endcsname{\value{scrambledenvs@#1@count}}%
-                \forloop{scrambledenvs@loopcount}{1}{\value{scrambledenvs@loopcount}<\the\numexpr\value{scrambledenvs@#1@count}+1\relax}{\expandafter\edef\csname pgfmath@randomlist@#1@\thescrambledenvs@loopcount\endcsname{\thescrambledenvs@loopcount}}%
-                \begin{scrambledenvs@#1@printenv}%
-                    \forloop{scrambledenvs@loopcount}{0}{\value{scrambledenvs@loopcount}<\value{scrambledenvs@#1@count}}{%
-                        \pgfmathrandomitem\scrambledenvs@tempindex{#1}%
-                        \csname scrambledenvs@#1@printitem\endcsname\label{#1:\scrambledenvs@tempindex}%
+            \ifnum\value{scrambledenvs@#1@count}<\csname scrambledenvs@#1@start\endcsname\relax
+            \else
+                \expandafter\edef\csname pgfmath@randomlist@#1\endcsname{\numexpr\value{scrambledenvs@#1@count}-\csname scrambledenvs@#1@start\endcsname+1}
+                    \count@=1
+                    \loop
+                        \expandafter\edef\csname pgfmath@randomlist@#1@\the\count@\endcsname{\the\numexpr\count@+\csname scrambledenvs@#1@start\endcsname-1\relax}
+                    \ifnum\count@<\numexpr\value{scrambledenvs@#1@count}-\csname scrambledenvs@#1@start\endcsname+1\relax
+                    \advance\count@ 1
+                    \repeat
+                \begin{scrambledenvs@#1@printenv}
+                    \setcounter{scrambledenvs@loopcount}{\csname scrambledenvs@#1@start\endcsname}
+                    \whiledo{\value{scrambledenvs@loopcount}<\the\numexpr\value{scrambledenvs@#1@count}+1\relax}{%
+                    \stepcounter{scrambledenvs@loopcount}
+                    \pgfmathrandomitem\scrambledenvs@tempindex{#1}
+                    \csname scrambledenvs@#1@printitem\endcsname\label{#1:\scrambledenvs@tempindex}%
                         \input{\jobname-\scrambledenvs@tempindex.#1}%
-                        \forloop{scrambledenvs@innerloopcount}{\scrambledenvs@tempindex}{\value{scrambledenvs@innerloopcount}<\csname pgfmath@randomlist@#1\endcsname}{%
-                            \global\expandafter\let\csname pgfmath@randomlist@#1@\thescrambledenvs@innerloopcount\expandafter\endcsname\csname pgfmath@randomlist@#1@\the\numexpr\thescrambledenvs@innerloopcount+1\relax\endcsname%
-                        }%
-                        \expandafter\xdef\csname pgfmath@randomlist@#1\endcsname{\the\numexpr\csname pgfmath@randomlist@#1\endcsname-1\relax}%
-                    }%
+                        \count@\pgfmath@randomtemp
+                        \loop
+                            \global\expandafter\let\csname pgfmath@randomlist@#1@\the\count@\expandafter\endcsname\csname pgfmath@randomlist@#1@\the\numexpr\the\count@+1\relax\endcsname%
+                        \advance\count@ 1
+                        \ifnum \count@ < \csname pgfmath@randomlist@#1\endcsname\relax
+                        \repeat
+                    \expandafter\xdef\csname pgfmath@randomlist@#1\endcsname{\the\numexpr\csname pgfmath@randomlist@#1\endcsname-1\relax}%
+                    }
                 \end{scrambledenvs@#1@printenv}
+                \expandafter\edef\csname scrambledenvs@#1@start\endcsname{\the\numexpr\value{scrambledenvs@#1@count}+1\relax}
             \fi
         \fi
     \else
         \ifcsname thescrambledenvs@#1@count\endcsname
             \ifnum\value{scrambledenvs@#1@count}>0\relax
                 \begin{scrambledenvs@#1@printenv}%
-                    \forloop{scrambledenvs@loopcount}{1}{\value{scrambledenvs@loopcount}<\the\numexpr\value{scrambledenvs@#1@count}+1\relax}{\csname scrambledenvs@#1@printitem\endcsname\label{#1:\thescrambledenvs@loopcount}\input{\jobname-\thescrambledenvs@loopcount.#1}}%
+                    \forloop{scrambledenvs@loopcount}{\csname scrambledenvs@#1@start\endcsname}{\value{scrambledenvs@loopcount}<\the\numexpr\value{scrambledenvs@#1@count}+1\relax}{\csname scrambledenvs@#1@printitem\endcsname\label{#1:\thescrambledenvs@loopcount}\input{\jobname-\thescrambledenvs@loopcount.#1}}%
                 \end{scrambledenvs@#1@printenv}
+                \expandafter\edef\csname scrambledenvs@#1@start\endcsname{\the\numexpr\value{scrambledenvs@#1@count}+1\relax}
             \fi
         \fi
     \fi
@@ -107,6 +122,9 @@
 \expandafter\def\csname scrambledenvs@#1@labelfont\endcsname{\scrambledenvs@labelfont}
 \scrambledenvs@check@macrodefined{#1labelfont}
 \expandafter\newcommand\csname #1labelfont\endcsname[1]{\expandafter\def\csname scrambledenvs@#1@labelfont\endcsname{##1}}
+\expandafter\def\csname scrambledenvs@#1@refprefix\endcsname{\scrambledenvs@refprefix}
+\scrambledenvs@check@macrodefined{#1refprefix}
+\expandafter\newcommand\csname #1refprefix\endcsname[1]{\expandafter\def\csname scrambledenvs@#1@refprefix\endcsname{##1}}
 \expandafter\def\csname scrambledenvs@#1@reffont\endcsname{\scrambledenvs@reffont}
 \scrambledenvs@check@macrodefined{#1reffont}
 \expandafter\newcommand\csname #1reffont\endcsname[1]{\expandafter\def\csname scrambledenvs@#1@reffont\endcsname{##1}}
@@ -138,6 +156,8 @@
 \newcounter{scrambledenvs@innerloopcount}
 \def\scrambledenvs@labelfont{\bfseries}
 \def\defaultlabelfont#1{\def\scrambledenvs@lineformat{#1}}
+\def\scrambledenvs@refprefix{}
+\def\defaultrefprefix#1{\def\scrambledenvs@refprefix{#1}}
 \def\scrambledenvs@reffont{}
 \def\defaultreffont#1{\def\scrambledenvs@reffont{#1}}
 \newenvironment{scrambledenvs@printenv}{\begin{enumerate}}{\end{enumerate}}
-- 
cgit v1.2.3

