diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-12 23:46:03 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-12 23:46:03 +0000 |
commit | 873660d1a83ece926fe7206288dda9c36b349c1b (patch) | |
tree | a48f77125c309a355b5d0eb58d6b24446abe9d62 /Master/texmf-dist/tex/generic/eijkhout | |
parent | 2939242967231097459df0fc3150fabc2f639111 (diff) |
generic 1
git-svn-id: svn://tug.org/texlive/trunk@613 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/eijkhout')
-rw-r--r-- | Master/texmf-dist/tex/generic/eijkhout/CD_labeler.tex | 350 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/eijkhout/CD_labeler_test.tex | 27 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/eijkhout/DB_process.tex | 151 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/eijkhout/repeat.tex | 206 |
4 files changed, 734 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/eijkhout/CD_labeler.tex b/Master/texmf-dist/tex/generic/eijkhout/CD_labeler.tex new file mode 100644 index 00000000000..989cd9a4a3f --- /dev/null +++ b/Master/texmf-dist/tex/generic/eijkhout/CD_labeler.tex @@ -0,0 +1,350 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% CD labeling macros, version 0.93, unreleased +% Copyright Victor Eijkhout 2001 +% file name: CD_labeler.tex +% uses: repeat.tex +% +% Author: +% Victor Eijkhout +% Department of Computer Science +% University of Tennessee, Knoxville TN 37996 +% +% victor@eijkhout.net +% +% This program is free software; you can redistribute it and/or +% modify it under the terms of the GNU General Public License +% as published by the Free Software Foundation; either version 2 +% of the License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% For a copy of the GNU General Public License, write to the +% Free Software Foundation, Inc., +% 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, +% or find it on the net, for instance at +% http://www.gnu.org/copyleft/gpl.html +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Use this file as follows: +% +% \input CD_labeler +% \CDLlabel{ <label content> } +% +% where the <label content> is usually comprised of +% one or more of the following: +% +% \CDLbackground{ <picture material> } +% \CDLunderhole{<setup>}{ <material printed below the hole> } +% \CDLlowerhalf{<setup>}{ <material on the lower half of the label, +% left of and below the hole> } +% \CDLleft{<setup>}{ <material printed on the left side of the label> } +% \CDLright{<setup>}{ <material printed on the right side of the label> } +% +% (You can insert your own material, which gets processed in +% horizontal mode. However, you'll have a hard time controlling +% its elevation in the label.) +% +% These commands can be given in any order, since basically +% everything is printed on top of each other. +% +% Make sure to put %-signs at line ends: +% \CDLlabel{% +% \CDLbackground{<stuff>}% +% \CDLleft{<text>}% +% } +% +% The <setup> material contains such things as \baselineskip +% settings. If you use a non-standard baselineskip, it is +% *essential* that you put that declaration in the first +% argument. Things such as font choices can go in the second. +% +% With the material left and right of the label, you may want to +% leave a few lines blank at the top. Here's how: +% To leave some blank lines: \CDLblank{ <number of lines to skip> } +% +% For guidance, a box is printed around the label. You can suppress +% this by \CDLboxfalse. +% +% Adjustable dimensions: +% \CDLdiscsize (default 120mm, which is CD size) +% \CDLinnerdiameter (default 40mm, the hole and ring around it) +% \CDLedgemargin (default 4mm, stay away this much from the edge) +% \CDLgutterwidth (default 0mm, keep this much space between +% \CDLleft and \CDLright text) +% +% Auxiliary commands: +% \CDLraggedright suppress hyphenation and use ragged right margin +% +% If you also use my DB_process macros, you can do things like +% +% \CDLlabel{% +% \CDLunderhole{\baselineskip8pt}{\smallfont \DBPtabfile{cd_file}}% +% \CDLleft{\baselineskip22pt \rightskip0pt plus 1cm}% +% {\CDLblank{3}\titlefont My favourite bedtime songs}% +% \CDLright{\baselineskip8pt}{\CDLblank{7}\smallfont +% \leftskip=1cm \rightskip=0pt plus 1cm +% Compiled for his own +% private use, by Victor Eijkhout, 1998}} +% where the cd_file is dumped from your favourite database. +% +% Share and enjoy! +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% revision history: +% 0.9 first release, December 1998 +% 0.91 fixed documentation, use repeat.tex for loop macro, +% copyright notice, bug in lower half macro, Feb 1999 +% 0.92 \CDLlabel made \long +% \CDLinnerradius changed to \CDLinnerdiameter +% fixed double subtracting of offset in \CDL{left,right}, +% and added empty line, suggestions by Yotam Medini. April 1999 +% 0.93 added \CDLragged{left,right} \CDLgutterwidth \CDLsquash. +% Major improvement in \CDL{left,right}. February 2001. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%% +%% Prevent multiple loading of this file +%% +\expandafter\ifx\csname CDLcount\endcsname\relax + \message{Loading CD labeler, version 0.92}% +\else + \message{CD labeling macros already loaded ... }\endinput \fi + +\newtoks\CDLtoks \newbox\CDLbox +\newdimen\CDLdiscsize \CDLdiscsize=120mm +\newdimen\CDLinnerdiameter \CDLinnerdiameter=40mm +\newdimen\CDLedgemargin \CDLedgemargin=4mm +\newdimen\CDLgutterwidth \CDLgutterwidth=0mm +\newif\ifCDLbox \CDLboxtrue + +%% +%% Load auxiliary files: loop macro +%% +\input repeat.tex + +%% +%% CDLlabel +%% main routine, this draws an empty box, with any +%% background and content supplied by the user +%% in \CDLbackground and \CDL{left,right,underhole,overhole} +%% +\long\def\CDLlabel#1% + {\vbox{\ifCDLbox\hrule\fi + \hbox to \CDLdiscsize + {\hsize=\CDLdiscsize \ifCDLbox\vrule\fi + \ignorespaces #1\hss \ifCDLbox\vrule\fi} + \ifCDLbox\hrule\fi}} +%% +%% CDLbackground +%% user macro +%% place a dimensionless item, presumably a picture +%% +\def\CDLbackground#1{ + \setbox\CDLbox=\vbox to 0pt{\hsize=0pt + \hbadness\maxdimen \vbadness\maxdimen #1}% + \wd\CDLbox=0pt \raise \CDLdiscsize\box\CDLbox} +%% +%% CDLlabelbox +%% basic macro for shape macros below +%% +\long\def\CDLlabelbox#1{% + \setbox\CDLbox=\vbox to \CDLdiscsize{\hsize=\CDLdiscsize + \hrule width \CDLdiscsize height 0pt depth 0pt \nointerlineskip + \vskip\CDLedgemargin + #1\vfil + }% + \wd\CDLbox=0pt \box\CDLbox \ignorespaces} + +%% +%% Shapes macros: various loops of calling CDLline, and building +%% up a \parshape. This is built around CDLline, which computes +%% length and indents left/right of a line somewhere on the label. +%% #1 is an option for setup: baselineskip and such +%% +\def\CDLlowerhalf#1#2{\CDLlabelbox{#1\relax + \vskip.5\CDLdiscsize + \CDLtoks={}% + \begingroup + \repeat \for{CDLcount} \from{0} \do {% + \count1=\CDLcount \advance\count1 by 1 + \CDLline{\count1}\a\t\c + \CDLline\CDLcount\t\b\t + \if\CDLerror \expandafter\breakrepeat \fi + \dimen1=\c\relax \dimen2=\a\relax + \ifdim\b=0pt \multiply\dimen2 by 2 \fi + \edef\temp{\global\CDLtoks={\the\CDLtoks + \space\the\dimen1 \space\the\dimen2}}\temp + }% + \noindent \parshape \CDLcount \the\CDLtoks #2\par + \endgroup + }} +\def\CDLunderhole#1#2{\CDLlabelbox{#1\relax + \vskip.5\CDLdiscsize \vskip.5\CDLinnerdiameter \vskip\baselineskip + \CDLtoks={}% + \begingroup + \count0=0 + \repeat \for{CDLcount} \from{0} \do {% + \count1=\CDLcount \advance\count1 by 1 + \CDLline{\count1}\a\t\c + \CDLline\CDLcount\t\b\t + \if\CDLerror \expandafter\breakrepeat \fi + \ifdim\b>0pt \advance\count0 by 1 + \else \dimen1=\c\relax \dimen2=\a\relax + \multiply\dimen2 by 2 + \edef\temp{\global\CDLtoks={\the\CDLtoks + \space\the\dimen1 \space\the\dimen2}}\temp + \fi + }% + \advance\CDLcount by -\count0 + \noindent \parshape \CDLcount \the\CDLtoks #2\par + \endgroup + }} +\def\CDLleft#1#2{\CDLlabelbox{ + \CDLtoks={}#1\relax + \begingroup + \repeat \for{CDLcount} \from{0} \do {% + \CDLline\CDLcount\a\b\c + \if\CDLerror \expandafter\breakrepeat \fi + % if we're not next to the hole, leave a gutter + \ifdim\b=0pt \dimen0=\a \advance\dimen0 by -\CDLgutterwidth + \edef\a{\the\dimen0 }\fi + \edef\temp{\CDLtoks={\c\space\a \space\the\CDLtoks \space \c\space\a}}\temp + }% + \noindent + \multiply\CDLcount by 2 \advance\CDLcount by 1 + \parshape \CDLcount 0pt 0pt \the\CDLtoks \hfill\break #2\par + \endgroup + }} +\def\CDLright#1#2{\CDLlabelbox{ + \CDLtoks={}#1\relax + \begingroup + %\count0=\CDLdiscsize \divide\count0 by \baselineskip + %\message{Should fit \the\count0 lines}% + \repeat \for{CDLcount} \from{0} \do {% + % get \a=length \b=inner gap \c=outer gap + \CDLline\CDLcount\a\b\c + \if\CDLerror \expandafter\breakrepeat \fi + % if we're not next to the hole, leave a gutter + \ifdim\b=0pt \dimen0=\a \advance\dimen0 by -\CDLgutterwidth + \edef\a{\the\dimen0 }% + \else + \dimen0=\a \advance\dimen0 by -\baselineskip \edef\a{\the\dimen0 }% + \dimen0=\b \advance\dimen0 by \baselineskip \edef\b{\the\dimen0 }% + \fi + \dimen0=\CDLdiscsize \divide\dimen0 by 2 + \advance\dimen0 by \b + \edef\temp{\CDLtoks={ + \the\dimen0 \space\a \space\the\CDLtoks + \the\dimen0 \space\a}}\temp + }% + \noindent \multiply\CDLcount by 2 \advance\CDLcount by 1 + \parshape \CDLcount 0pt 0pt \the\CDLtoks \hfill\break #2\par + \endgroup + }} +\def\CDLleftandunder#1#2{\CDLlabelbox{ + \CDLtoks={}#1\relax + \begingroup + \repeat \for{CDLcount} \from{1} \do {% + % get \a=length \b=inner gap \c=outer gap + \CDLline\CDLcount\a\b\c + \if\CDLerror \expandafter\breakrepeat \fi + % if we're not next to the hole, leave a gutter + \ifdim\b=0pt \dimen0=\a \advance\dimen0 by -\CDLgutterwidth + \edef\a{\the\dimen0 }\fi + \edef\temp{\CDLtoks={\c\space\a \space\the\CDLtoks}}\temp + }% + \CDLline0\a\b\c + \edef\temp{\CDLtoks={\the\CDLtoks \space \c\space\a \space \c\space\a}}\temp + \advance\CDLcount by 3 + \edef\tempc{\the\CDLcount}% + \repeat \for{CDLcount} \from{0} \do {% + \count1=\CDLcount \advance\count1 by 1 + \CDLline{\count1}\a\t\c + \CDLline\CDLcount\t\b\t + \if\CDLerror \expandafter\breakrepeat \fi + \dimen1=\c\relax \dimen2=\a\relax + \ifdim\b=0pt \multiply\dimen2 by 2 \fi + \edef\temp{\global\CDLtoks={\the\CDLtoks + \space\the\dimen1 \space\the\dimen2}}\temp + }% + \advance\CDLcount by \tempc + \noindent + \parshape \CDLcount 0pt 0pt \the\CDLtoks \hfill\break #2\par + \endgroup + }} +\def\CDLblank#1{\begingroup\count0=#1\relax + \ifnum\count0>0 \hfill\break \advance\count0 by -1 + \expandafter\CDLblank\expandafter{\number\count0}\fi\endgroup} + +%%%%%%%%%%%%%%%% Auxiliaries %%%%%%%%%%%%%%%% +%% +%% \CDLraggedright & \CDLraggedleft +\def\CDLraggedright{\hyphenchar\font=-1 + \rightskip=0pt plus .5\CDLdiscsize} +\def\CDLraggedleft{\hyphenchar\font=-1 + \leftskip=0pt plus .5\CDLdiscsize} +\def\CDLsquash#1{{\setbox0\hbox{#1}\ht0=0pt \dp0=0pt \box0\relax}} + +%%%%%%%%%%%%%%%% Interal macros %%%%%%%%%%%%%%%% +%% +%% CDLline +%% from #1 line number compute #2 length, #3 inner gap #4 outer gap +%% +\def\CDLline#1#2#3#4{\CDLsetnoerror + \begingroup \dimen0=\baselineskip + \multiply\dimen0 by #1\relax + \divide\CDLdiscsize by 2 \divide\CDLinnerdiameter by 2 + \dimen1=\CDLdiscsize \advance\dimen1 by -\CDLedgemargin + \CDLcircle{\dimen1}{\dimen0}\blen + \if\CDLerror \aftergroup\CDLseterror \else + \CDLcircle\CDLinnerdiameter{\dimen0}\slen + \dimen0=\blen sp + \dimen2=\CDLdiscsize \advance\dimen2 by -\dimen0 + \xdef#4{\the\dimen2}% + \if\CDLerror + \xdef#2{\the\dimen0}\gdef#3{0pt}% + \else + \dimen1=\slen sp\relax \advance\dimen0 by -\dimen1 + \xdef#2{\the\dimen0}\xdef#3{\the\dimen1}% + \fi \fi + \endgroup} +%% +%% CDLcircle +%% from #1=r #2=y compute #3=x so that x^2+y^2=r^2 +%% +\def\CDLcircle#1#2#3{\CDLsetnoerror + \begingroup + \count2=#1\advance\count2 by #2\edef\a{\number\count2}% + \count3=#1\advance\count3 by -#2\edef\b{\number\count3}% + \ifnum\count3<0 \aftergroup\CDLseterror \else + \CDLsqrt\a\aa \CDLsqrt\b\bb + \count0=\aa \multiply\count0 by \bb + \xdef#3{\number\count0}% + \fi + \endgroup} +%% +%% CDLsqrt +%% #1 is dimension, #2 is receiving control sequence +%% +\def\CDLsqrt#1#2{\begingroup + \count1=#1\relax + \repeat \do { + \count2=#1\relax \divide\count2 by \count1 + \advance\count2 by \count1 \divide\count2 by 2 + \ifnum\count2<\count1 \count1=\count2 + \else \expandafter\breakrepeat \fi} + \xdef#2{\the\count1}\endgroup} + +%% +%% Error handling +%% +\def\CDLsetnoerror{\def\CDLerror{10}} +\def\CDLseterror{\def\CDLerror{11}} + +\endinput + diff --git a/Master/texmf-dist/tex/generic/eijkhout/CD_labeler_test.tex b/Master/texmf-dist/tex/generic/eijkhout/CD_labeler_test.tex new file mode 100644 index 00000000000..a261f5f36f0 --- /dev/null +++ b/Master/texmf-dist/tex/generic/eijkhout/CD_labeler_test.tex @@ -0,0 +1,27 @@ +% This file tests Victor Eijkhout's CD_labeler.tex + +\input CD_labeler + +\def\hr{b\hrulefill e\break} +\def\fivehr{\hr \hr \hr \hr \hr} +\def\tenhr{\fivehr\fivehr} + +\hsize\CDLdiscsize +\vsize2.1\CDLdiscsize +\CDLlabel{ + \CDLleft{\baselineskip8pt}{\tenhr\tenhr\tenhr\tenhr} + \CDLright{\baselineskip8pt}{\tenhr\tenhr\tenhr\tenhr} + } +\smallskip +\CDLlabel{ + \CDLleft{\baselineskip8.4pt}{\tenhr\fivehr\hr\hr\hr} + \CDLlowerhalf{\baselineskip8.4pt}{\tenhr\tenhr}} +\smallskip +\CDLlabel{ + \CDLunderhole{\baselineskip8.4pt}{\tenhr\hr} + } +\smallskip +%\CDLlabel{% +% \CDLleftandunder{\baselineskip8.4pt}{\tenhr\tenhr}} + +\bye diff --git a/Master/texmf-dist/tex/generic/eijkhout/DB_process.tex b/Master/texmf-dist/tex/generic/eijkhout/DB_process.tex new file mode 100644 index 00000000000..f43078e950e --- /dev/null +++ b/Master/texmf-dist/tex/generic/eijkhout/DB_process.tex @@ -0,0 +1,151 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DataBase processing macros, version 0.91, December 2000 +% Copyright Victor Eijkhout 2000 +% file name: DB_process.tex +% +% Author: +% Victor Eijkhout +% Department of Computer Science +% University of Tennessee, Knoxville TN 37996 +% +% victor@eijkhout.net +% +% This program is free software; you can redistribute it and/or +% modify it under the terms of the GNU General Public License +% as published by the Free Software Foundation; either version 2 +% of the License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% For a copy of the GNU General Public License, write to the +% Free Software Foundation, Inc., +% 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, +% or find it on the net, for instance at +% http://www.gnu.org/copyleft/gpl.html +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Use this file as follows: +% +% \input DB_process +% \def\DBPprintline#1#2#3#4#5#6#7#8#9% +% { < do whatever you want with the argument > } +% \DBPtabfile{ <input file> } or \DBPcommafile{ <input file> } +% +% The user macro \DBPprintline is applied to the max 9 arguments +% of each database line. You need to define the macro with 9 arguments; +% if the database has less than 9 fields, empty arguments are passed. +% +% The input records are counted, and the counter is available as \DBPno. +% To print this, you have to do \number\DBPno or somesuch. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% revision history: +% 0.9 first release, December 1998 +% 0.91 documentation update, use repeat.tex for loop macro, +% copyright notice, better handling of 'fragile' material +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +%% +%% prevent multiple loading of this file +%% +\expandafter\ifx\csname DBPfile\endcsname\relax + \message{Loading DataBase Processing macros ... }% +\else + \message{DataBase Processing macros already loaded ... }\endinput \fi + +%% +%% Allocations +%% +\newread\DBPfile \newcount\DBPitem \newtoks\DBPtoks +\def\csarg#1#2{\expandafter#1\csname#2\endcsname} +\def\cscsarg#1#2{\csname#1\expandafter\endcsname\csname#2\endcsname} +\cscsarg{newtoks}{DBPtoks1} +\cscsarg{newtoks}{DBPtoks2} +\cscsarg{newtoks}{DBPtoks3} +\cscsarg{newtoks}{DBPtoks4} +\cscsarg{newtoks}{DBPtoks5} +\cscsarg{newtoks}{DBPtoks6} +\cscsarg{newtoks}{DBPtoks7} +\cscsarg{newtoks}{DBPtoks8} +\cscsarg{newtoks}{DBPtoks9} + +%% +%% Load auxiliary files: loop macro +%% +\input repeat.tex + +%% +%% a default printline macro +%% +\def\DBPprintline#1#2#3#4#5#6#7#8#9{\number\DBPno: #1\par} + +%% +%% general parsing macros +%% +\def\DBPparsefile{\def\DBPtestc{\par}% + \repeat \for{DBPno} \do {\read\DBPfile to \DBPinput + \ifx\DBPinput\DBPtestc \expandafter\breakrepeat \fi + \DBPitem=1\relax \DBPtoks=\expandafter{\DBPinput}% + \edef\DBPtemp{\noexpand\DBPparseline\the\DBPtoks + \DBPdelim DBP\DBPdelim}\DBPtemp + }} +\def\DBPline#1#2{% + \def\DBPtesta{#1}\def\DBPtestb{DBP}% + \ifx\DBPtesta\DBPtestb + \edef\DBPtemp{\noexpand\DBPprintline + {\csarg\the{DBPtoks1}}% + {\csarg\the{DBPtoks2}}% + {\csarg\the{DBPtoks3}}% + {\csarg\the{DBPtoks4}}% + {\csarg\the{DBPtoks5}}% + {\csarg\the{DBPtoks6}}% + {\csarg\the{DBPtoks7}}% + {\csarg\the{DBPtoks8}}% + {\csarg\the{DBPtoks9}}% + }\DBPtemp + \csarg\relax{DBPtoks1}{}% + \csarg\relax{DBPtoks2}{}% + \csarg\relax{DBPtoks3}{}% + \csarg\relax{DBPtoks4}{}% + \csarg\relax{DBPtoks5}{}% + \csarg\relax{DBPtoks6}{}% + \csarg\relax{DBPtoks7}{}% + \csarg\relax{DBPtoks8}{}% + \csarg\relax{DBPtoks9}{}% + \else \ifnum\DBPitem<10\relax + \csname DBPtoks\number\DBPitem\endcsname={#1}% + \else \message{DB Processor: can not handle >9 items/line}% + \fi + \advance\DBPitem by 1 + \expandafter#2\fi} + +%% +%% macros for comma-delimited +%% +\def\DBPcommafile#1{% + \openin\DBPfile=#1\relax + \let\DBPparseline=\DBPcommaline + \def\DBPdelim{,}% + \DBPparsefile} +\def\DBPcommaline#1,{\DBPline{#1}\DBPcommaline} + +%% +%% macros for tab-delimited +%% +\begingroup \catcode9=12 +\gdef\DBPtabfile#1{% + \openin\DBPfile=#1\relax + \begingroup + \catcode9=12 \let\DBPparseline=\DBPtabline + \def\DBPdelim{^^I}% + \DBPparsefile + \endgroup} +\gdef\DBPtabline#1^^I{\DBPline{#1}\DBPtabline} +\endgroup + +\endinput diff --git a/Master/texmf-dist/tex/generic/eijkhout/repeat.tex b/Master/texmf-dist/tex/generic/eijkhout/repeat.tex new file mode 100644 index 00000000000..6d149e15ee7 --- /dev/null +++ b/Master/texmf-dist/tex/generic/eijkhout/repeat.tex @@ -0,0 +1,206 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Repeat loop macro, version 0.92, December 2000 +% Copyright Victor Eijkhout 2000 +% file name: repeat.tex +% +% Author: +% Victor Eijkhout +% Department of Computer Science +% University of Tennessee, Knoxville TN 37996 +% +% victor@eijkhout.net +% +% This program is free software; you can redistribute it and/or +% modify it under the terms of the GNU General Public License +% as published by the Free Software Foundation; either version 2 +% of the License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% For a copy of the GNU General Public License, write to the +% Free Software Foundation, Inc., +% 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, +% or find it on the net, for instance at +% http://www.gnu.org/copyleft/gpl.html +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% General loop macro: +% \repeat +% \for{<var>} \from{<start>} \by{<step>} \to{<end>} \downto{<end>} +% \until{<cond>} \while{<cond>} +% \do { <loop body> } +% where all control sequences in between \repeat and \do are optional. +% The space after each argument is mandatory! +% (This implies that you will have to write "\from\i" as "\from{\i}".) +% +% var: characters to form a control sequence; +% after \for{index} you can access the loop counter as \index. +% This is a count register; to print it use \number\index. +% start,step,end: integers with obvious relations to the loop counter; +% start and step have a default value of 1 +% cond: (sequence of commands ending in) any TeX \if... test. +% +% Count down instead of up with \downto; the increment given in \by +% is always positive, and is added or subtracted accordingly. +% +% Tests: \until is evaluated at the end of the loop body; \while +% at the beginning of the loop body. +% +% Exit from middle of loop: \breakrepeat +% use this at any place in the loop; in case of a conditional, use +% \ifsomething ... \expandafter \breakrepeat \fi +% +% There are some examples at the end of this file, after the \endinput line. +% +% Technical details: +% The loop body is not executed in a group: the braces are those +% of a token list. +% The `for' variable is \let to a \count register. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% revision history: +% 0.9 first release, January 1999 +% 0.91 documentation update, +% csarg-like control sequences made REP... +% counter update made global in case the body issues grouping, +% copyright notice, February 1999 +% 0.92 installed trace switches, eliminated unwanted space caused by +% "\for{ijk} \do{...}" +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% + +%% +%% Prevent multiple loading of this file +%% +\expandafter\ifx\csname REPdepth\endcsname\relax + \message{Loading loop macro, version 0.92}% +\else \endinput \fi + +%% +%% Auxiliary stuff +%% +\def\REPcsarg#1#2{\expandafter#1\csname#2\endcsname} +\def\REPcsrom#1{\csname #1\romannumeral\REPdepth\endcsname} +\def\REPcsargrom#1#2{\expandafter#1\csname#2\romannumeral\REPdepth\endcsname} +%\def\cscsarg#1#2#3{\expandafter#1\expandafter#2\csname#3\endcsname} +%\def\REPcsREPcsargrom#1#2#3{\expandafter#1\expandafter#2% +% \csname#3\romannumeral\REPdepth\endcsname} + +\newcount\REPdepth +\let\endrepeat\relax \def\csprotect{} +% Trace switches may later be defined by PAC_utils +\let\REPtraceinit\relax \let\REPtraceexit\relax + +%% +%% Main repeat macro +%% - go to next level and allocate unique counter/toks if this is the +%% first time we visit this level +%% - setup: gather bounds and termination conditions +%% - scoop up body in token list; after the assignment define and +%% execute body +%% +\def\repeat#1\do{ + \REPtraceinit % exit in \breakrepeat + \advance\REPdepth by 1\relax + \REPcsargrom\ifx{REPcount}\relax + \REPcsargrom{\csname newcount\expandafter\endcsname}{REPcount}% + \REPcsargrom{\csname newtoks\expandafter\endcsname}{REPtoks}% + \REPcsargrom{\csname newtoks\expandafter\endcsname}{REPwtest}% + \REPcsargrom{\csname newtoks\expandafter\endcsname}{REPutest}% + \fi \REPzero \def\REPsign{}\def\REPcomp{>}\REPsetup{#1}% + \edef\REPtmp + {\def\REPcsargrom\noexpand{REPrepeat}{\REPcsargrom\noexpand{REPbody}}}\REPtmp + \afterassignment\REPdxbody\REPcsrom{REPtoks}} +%% +%% Define and execute loop body +%% This is done with an \edef to construct the actual sequence +%% +\def\REPdxbody{\REPcsargrom\edef{REPbody}{% + \REPcsargrom\the{REPwtest}% + \noexpand\the\REPcsargrom\noexpand{REPtoks}% + \REPcsargrom\the{REPutest}% + \global\REPcsargrom\advance{REPcount} by \REPsign\REPcsrom{REPinc}\relax% + \noexpand\endrepeat + \REPcsargrom\noexpand{REPrepeat}}% + \REPcsrom{REPbody}} +%% +%% Stop test +%% In order to stop, issue a +%% \breakrepeat which scoops up the rest of the body and exits +%% +\def\breakrepeat#1\endrepeat{\REPzero\REPcsargrom\let{REPrepeat}\relax + \advance\REPdepth by -1 \REPtraceexit + } +%% +%% Setup +%% gather bounds and termination conditions +%% +\def\REPsetup#1{% + \begingroup + \def\for##1 {\edef\REPtmp{% + \global\let\REPcsarg\noexpand{##1}\REPcsrom{REPcount}}\REPtmp}% + \def\from##1 {\REPcsargrom\global{REPcount}##1\relax}% + \def\to##1 {\edef\REPtmp{\global\REPcsargrom\noexpand{REPwtest}= + {\REPcsargrom\the{REPwtest}% + \noexpand\ifnum\REPcsargrom\noexpand{REPcount}\REPcomp##1\relax + \noexpand\expandafter \noexpand\breakrepeat \noexpand\fi}}\REPtmp}% + \def\downto##1 {\gdef\REPsign{-}\gdef\REPcomp{<}\to{##1}}% + \def\by##1 {\ifnum##1<0 \message{REPEAT: increment has to be >0}% + \REPcsargrom\gdef{REPinc}{-##1}\else + \REPcsargrom\gdef{REPinc}{##1}\fi} + \def\until##1 {\edef\REPtmp{\global\REPcsargrom\noexpand{REPutest}= + {\noexpand##1\relax + \noexpand\expandafter \noexpand\breakrepeat \noexpand\fi}}\REPtmp}% + \def\while##1 {\edef\REPtmp{\global\REPcsargrom\noexpand{REPwtest}= + {\noexpand##1\relax \noexpand\else + \noexpand\expandafter \noexpand\breakrepeat \noexpand\fi}}\REPtmp}% + \from{1} \by{1} #1% + \endgroup} +\def\REPzero + {\REPcsrom{REPtoks}{}\REPcsrom{REPutest}{}\REPcsrom{REPwtest}{}% + \REPcsargrom\def{REPbody}{}} + +\endinput + +%\tracingmacros2 +\repeat \for{i} \by{2} \do { + \ifnum\i=13 \expandafter\breakrepeat \fi + \message{doing \number\i} +} + +\repeat \for{iii} \to{8} \do {} +\message{After loop: \number\iii} + +\repeat \for{i} \from{10} \by{2} \downto{0} \do { + \message{countdown \number\i} +} + +\repeat \for{x} \while{\ifnum\x<7} \do { + \message{going \number\x} +} + +\repeat \to{3} \do { + \message{hello there!} +} + +\newcount\tmpcount +\repeat \for{j} + \until{\tmpcount\j \divide\tmpcount by 37 \noexpand\ifnum\tmpcount=1} + \do { + \message{testing \number\j} +} + +\repeat \for{i} \by{2} \to{10} \do + {\repeat \for{j} \from{\i} \by{3} \to{18} \do + {\message{(\number\i.\number\j)} + }} + +% infinite loop +%\repeat \do {} + +\bye |