diff options
author | Karl Berry <karl@freefriends.org> | 2022-05-28 20:18:12 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-05-28 20:18:12 +0000 |
commit | 7d948ae1e94a78e333748f27292be16da078074b (patch) | |
tree | 3173124565a32ae706e7318d0cc27dc9f90c0ac0 /Master/texmf-dist/tex/latex | |
parent | 282d86452c6ed49026b345932f198ecfce65ea6f (diff) |
gamebooklib (28may22)
git-svn-id: svn://tug.org/texlive/trunk@63424 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty b/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty index b85504a71a0..882565f7e2d 100644 --- a/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty +++ b/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty @@ -20,7 +20,7 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\ProvidesPackage{gamebooklib}[2021/08/24 Gamebook by R Lee latex@rjlee.homelinux.org] +\ProvidesPackage{gamebooklib}[2022/05/25 Gamebook by R Lee latex@rjlee.homelinux.org] \NeedsTeXFormat{LaTeX2e}[1994/06/01] \newcommand{\gamebook@info}[1]{}% \DeclareOption{verbose}{% @@ -30,6 +30,11 @@ \DeclareOption{endpage}{% \renewcommand\gamebook@beforelast{\eject}% }% +\DeclareOption{jukebox}{% + \newcommand\gamebook@jukebox{}% + \gamebook@info{Gamebook Library to perform jukebox index reshuffle + pass}% +}% \def\if@gamebook@footnotes{\iffalse} \DeclareOption{footnote}{% \gdef\if@gamebook@footnotes{\iftrue}% @@ -92,14 +97,19 @@ \newtoks\gentry@oldoutput{}% \edef\mytmp@{\noexpand\gentry@oldoutput={\the\output}}\mytmp@% \if@gamebook@footnotes\output={% + \def\gentry@deferoutput{\the\gentry@oldoutput}% \ifnum\outputpenalty<-\@M\else% - \edef\tmp@{footnotetoks\botmark} - \expandafter\ifcsname footnotetoks\botmark\endcsname% - \global\setbox255=\vbox to \vsize{% - \unvbox255\vfill\outputfootnotes@endpage}% - \fi% - \fi% - \the\gentry@oldoutput + \if\gentryshouldoutput0% + \unvbox255\def\gentry@deferoutput{}% + \else% + \expandafter\ifcsname footnotetoks\botmark\endcsname% + \expandafter\if\expandafter\relax\expandafter% + \detokenize\expandafter{\csname footnotetoks\botmark\endcsname}\relax\else% + \global\setbox255=\vbox to \vsize{% + \unvbox255\vfill\outputfootnotes@endpage}% + \fi\fi% + \fi\fi% + \gentry@deferoutput% }\fi% \xdef\gentrycount{\arabic{gentryctr}}% \setcounter{gentryctr}{0}% @@ -107,9 +117,10 @@ \whiledo{\not{\value{gentryctr}>\gentrycount}}{% \edef\gentryidxu{\arabic{gentryctr}}% \expandafter\xdef\csname paraIdx\gentryidxu\endcsname{\gentryidxu}% + \typeout{DEFINED paraIdx\gentryidxu}% \stepcounter{gentryctr}% }% - \if@gamebook@shuffle + \if@gamebook@shuffle% \setcounter{rand}{\gentrycount}% \addtocounter{rand}{-1}\edef% \stoppoint{\arabic{rand}}% @@ -146,9 +157,54 @@ \expandafter\global\expandafter\let\csname fixedat\mydest\endcsname\@undefined% \addtocounter{gentryctr}{-1}% \fi% + \ifcsname gamebook@jukebox\endcsname% + \expandafter\def\csname fixedto\mydest\endcsname{}% + \fi% \fi% \stepcounter{gentryctr}% - }}\fi%SHUFFLE END + }% + \ifcsname gamebook@jukebox\endcsname% + \ifnum\gentrycount<6% + \gamebook@info{Jukebox pass skipped; too few entries}% + \else% + \setcounter{gentryctr}{2}% + \whiledo{\not{\value{gentryctr}=\stoppoint}}{% + \edef\gentryidxt{\arabic{gentryctr}}% + \edef\curpos{\csname paraIdx\gentryidxt\endcsname}% + \stepcounter{gentryctr}% + \edef\gentryidxu{\arabic{gentryctr}}% + \edef\nextpos{\csname paraIdx\gentryidxu\endcsname}% + \edef\pdiff{\the\numexpr\curpos+\nextpos}% + \ifnum\pdiff<0\edef\pdiff{\the\numexpr-\pdiff}\fi% + \edef\sdiff{\the\numexpr\curpos-\nextpos}% + \ifnum\sdiff<0\edef\sdiff{\the\numexpr-\sdiff}\fi% + \ifnum\pdiff<\sdiff\relax\def\thediff{\pdiff}\else\def\thediff{\sdiff}\fi% + \ifnum\thediff=1% + \gamebook@info{Jukebox: entries are too close: % + \gentryidxt,\gentryidxu\space (original \curpos,\nextpos)}% + \chgrand[first=\numexpr\gentryidxu+1]% + \rand% + \expandafter\ifcsname fixedto\arabic{rand}\endcsname\rand\fi% + \expandafter\ifcsname fixedto\arabic{rand}\endcsname\rand\fi% + \expandafter\ifcsname fixedto\arabic{rand}\endcsname% + \gamebook@info{Can't reshuffle: failed to find non-fixed index}% + \else% + \ifcsname fixedto\gentryidxu\endcsname% + \ifcsname fixedto\gentryidxt\endcsname% + \gamebook@info{Can't reshuffle: \curpos\space and % + \nextpos\space are both fixed.}% + \else% + \gamebook@info{Reshuffling \gentryidxt\space to \arabic{rand}}% + \macroswap{paraIdx\gentryidxt}{paraIdx\arabic{rand}}% + \fi% + \else% + \gamebook@info{Reshuffling \gentryidxu\space to% + \arabic{rand} (alt)}% + \macroswap{paraIdx\gentryidxu}{paraIdx\arabic{rand}}% + \fi\fi\fi% + }% + \fi\fi% + }\fi%SHUFFLE END \gamebook@info{Shuffled! Gentry order:}% \setcounter{gentryctr}{1}% \whiledo{\not{\value{gentryctr}>\gentrycount}}{% @@ -157,7 +213,7 @@ \stepcounter{gentryctr}% }% \setcounter{gentryctr}{0}% - \gamebook@info{Outputting \gentrycount\ gamebook entries}% + \gamebook@info{Outputting \gentrycount\space gamebook entries}% \whiledo{\value{gentryctr}<\gentrycount}{% \refstepcounter{gentryctr}% \ifthenelse{\value{gentryctr}=\gentrycount}{% @@ -182,7 +238,7 @@ \stepcounter{gentryctr}% }% \setcounter{gentryctr}{0}% - \eject + \eject% \endgroup% }% \newcommand{\gentryheader}[4]{% @@ -193,6 +249,7 @@ \par% \marginpar{#3}% }% +\newcommand{\gentryshouldoutput}{1} \newcommand{\gentryfooter}{% \par\vspace{2em}\centerline{---}\vspace{2em plus 1in}\par% }% @@ -230,7 +287,7 @@ \newcommand{\outputfootnotes}[1]{% \begingroup% \def\in@out{}% flag that footnotes are outputting; suppresses marks - \setcounter{fncounter}{1} + \setcounter{fncounter}{1}% \def\footnote@rule{% \leftskip=0pt\rightskip=0pt\interlinepenalty=1000% \penalty-1000% @@ -262,7 +319,7 @@ \fi% }% \newcommand{\noentryfoot}{\def\outputfootnotes@endgentry{}} -\g@addto@macro{\gentry@footnotespergentry}{ +\g@addto@macro{\gentry@footnotespergentry}{% \newcommand{\outputfootnotes@endpage}{% \expandafter\if\expandafter\relax\expandafter% \detokenize\expandafter{\botmark}\relax\else% |