From fc082f22f8569ded9b8f518fb13c32cbbbbf1e73 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 19 Aug 2021 20:21:03 +0000 Subject: gamebooklib (19aug21) git-svn-id: svn://tug.org/texlive/trunk@60276 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/gamebooklib/gamebooklib.sty | 266 +++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty (limited to 'Master/texmf-dist/tex/latex/gamebooklib') diff --git a/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty b/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty new file mode 100644 index 00000000000..7822d932cdc --- /dev/null +++ b/Master/texmf-dist/tex/latex/gamebooklib/gamebooklib.sty @@ -0,0 +1,266 @@ +%% +%% This is file `gamebooklib.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% gamebooklib.dtx (with options: `package') +%% +%% This is a generated file. +%% +%% Copyright (C) 2021 by Robert J Lee +%% +%% This file may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either +%% version 1.3 of this license or (at your option) any later +%% version. The latest version of this license is in: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% and version 1.3 or later is part of all distributions of +%% LaTeX version 2005/12/01 or later. +%% +\ProvidesPackage{gamebooklib}[2021/08/10 Gamebook by R Lee latex@rjlee.homelinux.org] +\NeedsTeXFormat{LaTeX2e}[1994/06/01] +\newcommand{\gamebook@info}[1]{}% +\DeclareOption{verbose}{% + \renewcommand{\gamebook@info}[1]{\PackageInfo{gamebooklib}{#1}}% + \gamebook@info{Gamebook Library package is logging}}% +\newcommand\gamebook@beforelast{} +\DeclareOption{endpage}{% + \renewcommand\gamebook@beforelast{\eject}% +}% +\def\if@gamebook@footnotes{\iffalse} +\DeclareOption{footnote}{% + \gdef\if@gamebook@footnotes{\iftrue}% + \gamebook@info{Gamebook Library footnotes per gamebook entry}% +}% +\def\if@gamebook@shuffle{\iftrue} +\DeclareOption{noshuffle}{% + \gdef\if@gamebook@shuffle{\iffalse}% + \gamebook@info{Gamebook Library entries output in order}% +}% +\DeclareOption*{% + \typeout{Current option: \CurrentOption}% + \PassOptionsToClass{\CurrentOption}{lcg}% +}% +\ProcessOptions\relax% +\RequirePackage{environ}% +\RequirePackage{macroswap}% +\RequirePackage{ifthen} +\RequirePackage{lcg}% +\RequirePackage[debrief]{silence}% +\newcounter{gentryctr}% +\setcounter{gentryctr}{0}% +\newcommand{\gentry}[1][]{\@gentry{#1}}% +\newenvironment{@gentry}[2]{% + \def\gentryidx{#1}% + \def\gentrycode{#2}% + \@@gentry% +}{\ignorespacesandallpars% +}% +\newcommand{\@@gentry}[1][]{% + \def\gentrytitle{#1}% + \stepcounter{gentryctr}% + \ifthenelse{\equal{\gentryidx}{}}{}{% + \expandafter\xdef\csname fixedat\arabic{gentryctr}% + \endcsname{\gentryidx}% + }% + \expandafter\global\expandafter\newtoks\expandafter{% + \csname paratok\arabic{gentryctr}\endcsname}{ }% + \Collect@Body\gentry@store% +} +\newcommand{\gentry@store}[1]{% + \edef\head{\noexpand\begingroup\noexpand\gentryheader% + {\arabic{gentryctr}}{\gentryidx}{\gentrycode}{\gentrytitle}% + \noexpand\label{gentry:\gentrycode}% + }% + \global\expandafter\csname paratok\arabic{gentryctr}\endcsname=% + \expandafter{\head #1% + \outputfootnotes@endgentry% + \gentryfooter\endgroup}% +}% +\newcommand{\gentry@footnotespergentry}{} +\newcommand{\thegentries}{% +\begingroup% + \if@gamebook@footnotes\gentry@footnotespergentry\fi% + \xdef\gentrycount{\arabic{gentryctr}}% + \WarningFilter{lcg}{Using an already existing counter rand}% +\newtoks\gentry@oldoutput{}% +\edef\mytmp@{\noexpand\gentry@oldoutput={\the\output}}\mytmp@% +\if@gamebook@footnotes\output={% + \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 +}\fi% + \xdef\gentrycount{\arabic{gentryctr}}% + \setcounter{gentryctr}{0}% + \ifthenelse{\gentrycount<3}{}{%SHUFFLE START + \whiledo{\not{\value{gentryctr}>\gentrycount}}{% + \edef\myidx{\arabic{gentryctr}}% + \expandafter\xdef\csname paraIdx\myidx\endcsname{\myidx}% + \stepcounter{gentryctr}% + }% + \if@gamebook@shuffle + \setcounter{gentryctr}{2}% + \setcounter{rand}{\gentrycount}% + \addtocounter{rand}{-1}\edef% + \stoppoint{\arabic{rand}}% + \chgrand[last=\stoppoint]% + \whiledo{\value{gentryctr}<\stoppoint}{% + \edef\myidx{\arabic{gentryctr}}% + \expandafter\ifcsname fixedat\myidx\endcsname% + \gamebook@info{Not shuffling \myidx; fixed pos}% + \stepcounter{gentryctr}% + \else% + \gamebook@info{Shuffling \myidx}% + \stepcounter{gentryctr}% + \edef\nextidx{\arabic{gentryctr}}% + \expandafter\ifcsname fixedto\arabic{rand}\endcsname\else% + \chgrand[first=\nextidx]% + \rand% + \gamebook@info{Shuffling \myidx to \arabic{rand}}% + \macroswap{paraIdx\myidx}{paraIdx\arabic{rand}}% + \fi% + \fi% + }% + \setcounter{gentryctr}{2}% + \whiledo{\value{gentryctr}<\stoppoint}{% + \edef\myidx{\arabic{gentryctr}}% + \expandafter\ifcsname fixedat\myidx\endcsname% + \expandafter\edef\expandafter\mydest\expandafter% + {\expandafter\csname fixedat\myidx\endcsname}% + \gamebook@info{MOVING FIXED GAMEBOOK ENTRY INTO PLACE: \myidx -> \mydest}% + \macroswap{paraIdx\myidx}% + {paraIdx\expandafter\csname fixedat\myidx\endcsname}% + \fi% + \stepcounter{gentryctr}% + }}\fi%SHUFFLE END + \gamebook@info{Shuffled! Gentry order:}% + \setcounter{gentryctr}{1}% + \whiledo{\not{\value{gentryctr}>\gentrycount}}{% + \edef\myidx{\arabic{gentryctr}}% + \gamebook@info{\myidx -> \csname paraIdx\myidx\endcsname}% + \stepcounter{gentryctr}% + }% + \setcounter{gentryctr}{0}% + \gamebook@info{Outputting \gentrycount\ gamebook entries}% + \whiledo{\value{gentryctr}<\gentrycount}{% + \refstepcounter{gentryctr}% + \ifthenelse{\value{gentryctr}=\gentrycount}{% + \gamebook@beforelast% + }{}% + \edef\myidx{\arabic{gentryctr}}% + \xdef\youridx{\csname paraIdx\myidx\endcsname}% + \gamebook@info{Output gentry \myidx\ of \gentrycount,% + original idx \youridx}% + \the\csname paratok\youridx\endcsname% + }% + \gamebook@info{All gamebook entries added to main vertical list}% + \setcounter{gentryctr}{1}% + \whiledo{\not{\value{gentryctr}>\gentrycount}}{% + \edef\myidx{\arabic{gentryctr}}% + \expandafter\global\expandafter\let% + \csname paratok\myidx\endcsname\@undefined% + \expandafter\ifcsname fixedat\myidx\endcsname% + \expandafter\global\expandafter\let% + \csname fixedat\myidx\endcsname\@undefined% + \fi% + \stepcounter{gentryctr}% + }% + \setcounter{gentryctr}{0}% + \eject + \endgroup% +}% +\newcommand{\gentryheader}[4]{% + \noindent\textbf{\Huge\arabic{gentryctr}\large\ #4}% + \nopagebreak% + \vspace{0.3em}% + \nopagebreak% + \par% + \marginpar{#3}% +}% +\newcommand{\gentryfooter}{% + \par\vspace{2em}\centerline{---}\vspace{2em plus 1in}\par% +}% +\def\ignorespacesandallpars@{% + \@ifnextchar\par% + {\expandafter\ignorespacesandallpars\@gobble}% + {}% +}% +\g@addto@macro{\@makefnmark}{% + \ifcsname in@out\endcsname\else% + \mark{\arabic{\@mpfn}}% + \fi% +}% +\g@addto@macro{\gentry@footnotespergentry}{% +\newcommand{\@footnotetext@save}[3]{% + \global\newtoks#2{}% + \global#2={\noindent\@footnotemark{}#3}% +}}% +\g@addto@macro{\gentry@footnotespergentry}{% +\newcommand{\@footnotetext@save@}[2]{% + \edef\@tmp@{\expandafter\arabic{\@mpfn}}% + \expandafter\@footnotetext@save\expandafter{\@tmp@}{#1}{#2}% +}}% +\g@addto@macro{\gentry@footnotespergentry}{% +\renewcommand{\@footnotetext}[1]{% + \begingroup% + \def\in@out{}% flag that we're building footnotes + \edef\@tmp{\expandafter\csname footnotetoks\arabic{\@mpfn}\endcsname}% + \expandafter\@footnotetext@save@\expandafter{\@tmp}{% + % This fixes up the use of \cs{footnotemark} within footnotes: + #1}% + \endgroup% +}}% +\newcounter{fncounter}% +\newcommand{\outputfootnotes}[1]{% + \begingroup% + \def\in@out{}% flag that footnotes are outputting; suppresses marks + \setcounter{fncounter}{1} + \def\footnote@rule{% + \leftskip=0pt\rightskip=0pt\interlinepenalty=1000% + \penalty-1000% + \vspace{1pt plus 2pt minus 0.5pt}% + \hspace{-0.5in}\rule{1.5in}{0.4pt}\\% + }% + \outputpenalty=-\@MM\break% + \vbox{% + \whiledo{\not{\value{fncounter}>#1}}{% + \expandafter\ifcsname footnotetoks\arabic{fncounter}\endcsname% + \edef\tmp@@{\csname footnotetoks\arabic{fncounter}\endcsname}% + \expandafter\if\expandafter\relax\expandafter% + \detokenize\expandafter{\the\tmp@@}\relax\else% + \footnote@rule\gdef\footnote@rule{\ifvmode\else\par\fi}% + \interlinepenalty\interfootnotelinepenalty% + \expandafter\the\tmp@@% + \global\expandafter\tmp@@={}% + \expandafter\let\tmp@@\@undefined% + \fi\fi% + \stepcounter{fncounter}% + }% + }% + \endgroup% +}% +\newcommand{\outputfootnotes@endgentry}{% + \if@gamebook@footnotes% + \nopagebreak\ifhmode\\\fi% get into vertical mode + \nopagebreak\outputfootnotes{\arabic{\@mpfn}}% + \fi% +}% +\newcommand{\noentryfoot}{\def\outputfootnotes@endgentry{}} +\g@addto@macro{\gentry@footnotespergentry}{ +\newcommand{\outputfootnotes@endpage}{% + \expandafter\if\expandafter\relax\expandafter% + \detokenize\expandafter{\botmark}\relax\else% + \outputfootnotes{\botmark}% + \fi% +}}% +\endinput +%% +%% End of file `gamebooklib.sty'. -- cgit v1.2.3