From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- info/laan/bridge/bridge.tex | 415 +++++ info/laan/paradigm/baker.eps | 40 + info/laan/paradigm/barnwindowii.eps | 38 + info/laan/paradigm/bentley.eps | 15 + info/laan/paradigm/eschera.eps | 17 + info/laan/paradigm/escherb.eps | 25 + info/laan/paradigm/escherknotiii.epsabr | 25 + info/laan/paradigm/escherknotmf.eps | 20 + info/laan/paradigm/flower.eps | 17 + info/laan/paradigm/gurariabc.eps | 20 + info/laan/paradigm/gurarisq.eps | 15 + info/laan/paradigm/jvr.eps | 44 + info/laan/paradigm/linebundle.eps | 15 + info/laan/paradigm/malbork.eps | 28 + info/laan/paradigm/paradigm.gam | 431 +++++ info/laan/paradigm/paradigm.hea | 587 +++++++ info/laan/paradigm/paradigm.itm | 216 +++ info/laan/paradigm/paradigm.lin | 755 +++++++++ info/laan/paradigm/paradigm.lps | 566 +++++++ info/laan/paradigm/paradigm.opt | 463 ++++++ info/laan/paradigm/paradigm.postscript | 1483 +++++++++++++++++ info/laan/paradigm/paradigm.ps | 2751 +++++++++++++++++++++++++++++++ info/laan/paradigm/paradigm.src | 759 +++++++++ info/laan/paradigm/paradigm.srt | 723 ++++++++ info/laan/paradigm/paradigm.two | 622 +++++++ info/laan/paradigm/polygon.eps | 16 + info/laan/paradigm/polygonii.eps | 20 + info/laan/paradigm/prpie.eps | 98 ++ info/laan/paradigm/readme.fst | 22 + info/laan/paradigm/seal.eps | 26 + info/laan/paradigm/sine.eps | 22 + info/laan/paradigm/sinedisks.eps | 13 + info/laan/paradigm/textalongarc.eps | 20 + info/laan/paradigm/textalongspiral.eps | 45 + info/laan/pwt/README | 1 + info/laan/pwt/pwt.aft | 293 ++++ info/laan/pwt/pwt.cus | 433 +++++ info/laan/pwt/pwt.fmt | 1467 ++++++++++++++++ info/laan/pwt/pwt.his | 84 + info/laan/pwt/pwt.ind | 506 ++++++ info/laan/pwt/pwt.int | 707 ++++++++ info/laan/pwt/pwt.mat | 1167 +++++++++++++ info/laan/pwt/pwt.obs | 5 + info/laan/pwt/pwt.ref | 292 ++++ info/laan/pwt/pwt.scr | 452 +++++ info/laan/pwt/pwt.sur | 139 ++ info/laan/pwt/pwt.tab | 1875 +++++++++++++++++++++ info/laan/pwt/pwt.tls | 365 ++++ info/laan/pwt/pwt.tot | 154 ++ info/laan/pwt/pwt.txt | 1255 ++++++++++++++ info/laan/pwt/readme.fst | 66 + 51 files changed, 19633 insertions(+) create mode 100644 info/laan/bridge/bridge.tex create mode 100644 info/laan/paradigm/baker.eps create mode 100644 info/laan/paradigm/barnwindowii.eps create mode 100644 info/laan/paradigm/bentley.eps create mode 100644 info/laan/paradigm/eschera.eps create mode 100644 info/laan/paradigm/escherb.eps create mode 100644 info/laan/paradigm/escherknotiii.epsabr create mode 100644 info/laan/paradigm/escherknotmf.eps create mode 100644 info/laan/paradigm/flower.eps create mode 100644 info/laan/paradigm/gurariabc.eps create mode 100644 info/laan/paradigm/gurarisq.eps create mode 100644 info/laan/paradigm/jvr.eps create mode 100644 info/laan/paradigm/linebundle.eps create mode 100644 info/laan/paradigm/malbork.eps create mode 100644 info/laan/paradigm/paradigm.gam create mode 100644 info/laan/paradigm/paradigm.hea create mode 100644 info/laan/paradigm/paradigm.itm create mode 100644 info/laan/paradigm/paradigm.lin create mode 100644 info/laan/paradigm/paradigm.lps create mode 100644 info/laan/paradigm/paradigm.opt create mode 100644 info/laan/paradigm/paradigm.postscript create mode 100644 info/laan/paradigm/paradigm.ps create mode 100644 info/laan/paradigm/paradigm.src create mode 100644 info/laan/paradigm/paradigm.srt create mode 100644 info/laan/paradigm/paradigm.two create mode 100644 info/laan/paradigm/polygon.eps create mode 100644 info/laan/paradigm/polygonii.eps create mode 100644 info/laan/paradigm/prpie.eps create mode 100644 info/laan/paradigm/readme.fst create mode 100644 info/laan/paradigm/seal.eps create mode 100644 info/laan/paradigm/sine.eps create mode 100644 info/laan/paradigm/sinedisks.eps create mode 100644 info/laan/paradigm/textalongarc.eps create mode 100644 info/laan/paradigm/textalongspiral.eps create mode 120000 info/laan/pwt/README create mode 100644 info/laan/pwt/pwt.aft create mode 100644 info/laan/pwt/pwt.cus create mode 100644 info/laan/pwt/pwt.fmt create mode 100644 info/laan/pwt/pwt.his create mode 100644 info/laan/pwt/pwt.ind create mode 100644 info/laan/pwt/pwt.int create mode 100644 info/laan/pwt/pwt.mat create mode 100644 info/laan/pwt/pwt.obs create mode 100644 info/laan/pwt/pwt.ref create mode 100644 info/laan/pwt/pwt.scr create mode 100644 info/laan/pwt/pwt.sur create mode 100644 info/laan/pwt/pwt.tab create mode 100644 info/laan/pwt/pwt.tls create mode 100644 info/laan/pwt/pwt.tot create mode 100644 info/laan/pwt/pwt.txt create mode 100644 info/laan/pwt/readme.fst (limited to 'info/laan') diff --git a/info/laan/bridge/bridge.tex b/info/laan/bridge/bridge.tex new file mode 100644 index 0000000000..e90050f007 --- /dev/null +++ b/info/laan/bridge/bridge.tex @@ -0,0 +1,415 @@ + +\documentstyle[twocolumn]{article} +% +\setlength{\textwidth}{7in} +\setlength{\textheight}{9in} +\setlength{\oddsidemargin}{-.4in} +\setlength{\topmargin}{-.5in} +\newlength{\br} +\setlength{\br}{8em} +% +\renewcommand{\c}{\(\clubsuit\)} +\renewcommand{\d}{\(\diamondsuit\)} +\newcommand{\h}{\(\heartsuit\)} +\newcommand{\s}{\(\spadesuit\)} +% +\newcommand{\hand}[4]{ + \begin{minipage}[t]{\br}%I chose \br=8em + \begin{tabbing} + %width of parbox depends on the parameters: + %min{\br, max{string #1, ..., string #4}} + \(\spadesuit\) \= #1 \\ + \(\heartsuit\) \> #2 \\ + \(\diamondsuit\)\> #3 \\ + \(\clubsuit\) \> #4 + \end{tabbing} + \end{minipage} }%end \hand +% +\newsavebox{\NESW} +\savebox{\NESW}[4em]{% +\raisebox{-1.5\baselineskip}% +{\fbox{\small W + \raisebox{2.6ex}{N} + \hspace*{-1em} + \raisebox{-2.6ex}{S} + {E} + } +} }%end \NESW +% +\newcommand{\crdima}[6]{% +\begin{tabular}[t]{lll} + #1 & #3 & #2\\ + #4 & \usebox{\NESW} & #5\\ + & #6 & +\end{tabular} +}%end \crdima +% +\newenvironment{bidding}% +{\begin{tabbing} + xxxxxx\=xxxxxx\=xxxxxx\=xxxxxx \kill + West \>North \>East \> South\\ +}{\end{tabbing} }%end bidding +% +\begin{document} +\title{Typesetting Bridge\\ + via \LaTeX} +\author{C.G. van der Laan\\ +Rekencentrum RUG\\ +9700 AV Groningen\\ +The Netherlands\\ +Earn/Bitnet: cgl@hgrrug5\\ +\date{}} +\maketitle +\begin{abstract} +\LaTeX\ macros and a bidding environment +for typesetting bridge card distributions and bidding +sequences are given. +Examples borrowed from bridge literature are supplied. +\end{abstract} +% +\section{Card deals} +In bridge literature diagrams of distribution of cards over +the hands are often given in order to demonstrate bidding +sequences or to explain play technique. +In order to do this systematically and to abstract from layout details +I wrote a macro --- \verb=crdima= --- with six parameters +\begin{description} +\item[first parameter:] text, especially who is the dealer and what is the + vulnerability. For example: N/None, for North dealer and + vulnerability none. +\item[second parameter:] text, for example indication of play, + e.g., number \verb=Play 1= or otherwise, e.g., \\ + \verb=\begin{minipage}[t]{\br}=\\ + \verb= Play:\\demo=\\ + \verb=\end{minipage}= +\item[next four parameters:] the four hands in the sequence N, W, E, S. + Each hand is a call of the \verb=hand= macro +with four parameters: the \s, \h, \d, \c\ cards. +\end{description} +Example +\begin{quote} +\begin{verbatim} +\crdima{N/None}{% + \begin{minipage}[t]{\br} + Play:\\demo + \end{minipage}}% + {\hand{J74}{AJ}{QJT2}{Q874}}% + {\hand{A3}{K76}{963}{KJ952}}% + {\hand{K86}{T9542}{874}{T3}}% + {\hand{QT952}{Q83}{AK5}{A6}}% +\end{verbatim} +\end{quote} +yields +\begin{quote} +\crdima{N/None}{% + \begin{minipage}[t]{\br} + Play:\\demo + \end{minipage}}% + {\hand{J74}{AJ}{QJT2}{Q874}}% + {\hand{A3}{K76}{963}{KJ952}}% + {\hand{K86}{T9542}{874}{T3}}% + {\hand{QT952}{Q83}{AK5}{A6}}% +\end{quote} +% +{\bf Remarks}\\ +By this levelling I circumvented the limit of the +number of parameters. Because +parameter substitution is done by `text' +replacement there is no `(strong) type checking' +as in modern high-level programming languages. \\ +There is no check on the correctness of the cards (correct number, +distribution, multiple occurrence or omission), nor on the correct sequence +of the parameters. In SGML compliance with the input syntax can be +imposed with enhanced user convenience and alleviated proofreading, but +at the expense of elaborate coding, \cite{JG}. +No test on the +correctness of the sequence of the hands is ever possible, however.\\ +The \verb=crdima= macro can be used +to display all phases of the play. +Hands can be suppressed at discretion of the user +by empty actual parameters. +A renounce can be supplied via \verb=--=. +In the listings of the commands used for the examples +the \verb=quote= environment command is omitted. +\\[1ex] +For tournaments (bridge) plays are often dealt by computer. +At the end of tournaments players appreciate prints +of the deals. For that purpose my (Pascal) deal program +generates ASCII output --- for simple display on the PC --- +as well as \LaTeX\ input, optionally. This input is printed +with the aid of \verb=crdima=. Parameter testing is superfluous +for \LaTeX\ input generated this way. +% +\section{Bidding} +In the context of bidding theory I use a bidding environment. +The given card deal takes the following ACOL bidding +\begin{quote} +\begin{bidding} +-- \> 1\c\> no \> 1\s\\ +no \> 2\s\> no \> 4\s\\ +a.p. +\end{bidding} +\end{quote} +obtained via +\begin{quote} +\begin{verbatim} +\begin{bidding} +-- \> 1\c\> no \> 1\s\\ +no \> 2\s\> no \> 4\s\\ +a.p. +\end{bidding} +\end{verbatim} +\end{quote} +{\bf Remark} The bidding environment is independent of the language +of the bidding (West etc.\ can easily be adapted), +the bidding system as well as the number of bid +rounds. +\section{Macro texts} +% +%\verbinput{tcmac.tex} +% +\begin{verbatim} +\newcommand{\hand}[4]{ + \begin{minipage}[t]{\br}%I chose \br=8em + \begin{tabbing} + %width of parbox depends on the parameters: + %min{\br, max{string #1, ..., string #4}} + \(\spadesuit\) \= #1 \\ + \(\heartsuit\) \> #2 \\ + \(\diamondsuit\)\> #3 \\ + \(\clubsuit\) \> #4 + \end{tabbing} + \end{minipage} }%end \hand +% +\newsavebox{\NESW} +\savebox{\NESW}[4em]{% +\raisebox{-1.5\baselineskip}% +{\fbox{\small W + \raisebox{2.6ex}{N} + \hspace*{-1em} + \raisebox{-2.6ex}{S} + {E} + } +} }%end \NESW +% +\newcommand{\crdima}[6]{% +\begin{tabular}[t]{lll} + #1 & #3 & #2\\ + #4 & \usebox{\NESW} & #5\\ + & #6 & +\end{tabular} +}%end \crdima +% +\newenvironment{bidding}% +{\begin{tabbing} + xxxxxx\=xxxxxx\=xxxxxx\=xxxxxx \kill + West \>North \>East \> South\\ +}{\end{tabbing} }%end bidding +% +\end{verbatim}% +% +To eliminate data integrity errors +the listings of the above macros and +the listings of the commands used in the examples are `included' +via a transparent verbatim like environment, \cite{HM}; +so the same files were used for execution and listing. +% +\section{Some more examples} +In order to illustrate general bidding theory +from the point of view of one hand only, +the \verb=hand= macro can be used. +The following layout, heavily used in \cite{EC}, +\begin{quote} +\hand{AKJ42}{AK9}{T832}{T}\hspace{.5\br} +\begin{minipage}[t]{\br} +\begin{bidding} +-- \> 1\s\> no \> 1NT \\ +2\c\> ? +\end{bidding} +\end{minipage} +\end{quote} +is obtained via +\begin{quote} +\begin{verbatim} +\hand{AKJ42}{AK9}{T832}{T}\hspace{.5\br} +\begin{minipage}[t]{\br} +\begin{bidding} +-- \> 1\s\> no \> 1NT \\ +2\c\> ? +\end{bidding} +\end{minipage} +\end{verbatim} +\end{quote} +For issues related to defense play one often displays +only the dummy hand and your own hand. +The following example --- layout and text --- +is from \cite{Br}. +\begin{quote} +\crdima{}{}{}{\hand{AJ632}{43}{KQ7}{A85}}% + {}{\hand{985}{852}{AJ5}{KQT3}}\\ +\begin{bidding} +1\s\> no \> 2\h \> no\\ +2NT\> no \> 4\h \> a.p. +\end{bidding} +\end{quote} +\begin{quote} +Against 4\h\ South starts \c K, taken +with \c A. Leader continues \h AKQ. On the third +round of \h's, partner discards \d 9 (indicates +interest in \s). Leader continues with \d 2, +how do you continue? +\end{quote} +The example is obtained via +\begin{quote} +\begin{verbatim} +\crdima{}{}{}{\hand{AJ632}{43}{KQ7}{A85}}% + {}{\hand{985}{852}{AJ5}{KQT3}}\\ +\begin{bidding} +1\s\> no \> 2\h \> no\\ +2NT\> no \> 4\h \> a.p. +\end{bidding} +\end{verbatim} +\end{quote} +{\bf Remark} In a similar way W--N, N--E, E--S hands, +or W--E, N--S hands, or one hand only, with NESW diagram, +can be displayed simply by a suitable call of \verb=crdima=. \\[2ex] +% +Finally, an endplay --- positional squeeze --- +from \cite{HWK}\ is given. +\begin{quote} +\crdima{}{S leads \c A}% + {\hand{AJ}{K}{--}{--}}% + {\hand{KQ}{A}{--}{--}}% + {\hand{7}{9}{T}{--}}% + {\hand{2}{4}{--}{A}} +\end{quote} +The example is obtained via +\begin{quote} +\begin{verbatim} +\crdima{}{S leads \c A}% + {\hand{AJ}{K}{--}{--}}% + {\hand{KQ}{A}{--}{--}}% + {\hand{7}{9}{T}{--}}% + {\hand{2}{4}{--}{A}} +\end{verbatim} +\end{quote} +% +\section{Variation} +An elementary, and in a sense more general, crdima macro is +\begin{quote} +\begin{verbatim} +\newcommand{\crdimaele}[9]{% +\begin{tabular}[t]{lll} +#1 & #2 & #3\\ +#4 & #5 & #6\\ +#7 & #8 & #9 +\end{tabular}}%end crdimaele +\end{verbatim} +\end{quote} +All the given examples can be handled with \verb=crdimaele=. +\verb=crdimaele= applied to +the original deal without NESW diagram reads +\begin{quote} +\begin{verbatim} +\crdimaele{N/None}% + {\hand{J74}{AJ}{QJT2}{Q874}}% + {\begin{minipage}[t]{\br} + Play: demo; no NESW diagram + \end{minipage}}% + {\hand{A3}{K76}{963}{KJ952}}% + {}% + {\hand{K86}{T9542}{874}{T3}}% + {}% + {\hand{QT952}{Q83}{AK5}{A6}}% + {} +\end{verbatim} +\end{quote} +with result +\begin{quote} +\newcommand{\crdimaele}[9]{% +\begin{tabular}[t]{lll} +#1 & #2 & #3\\ +#4 & #5 & #6\\ +#7 & #8 & #9 +\end{tabular}}%end crdimaele +\crdimaele{N/None}% + {\hand{J74}{AJ}{QJT2}{Q874}}% + {\begin{minipage}[t]{\br} + Play: demo; no NESW diagram + \end{minipage}}% + {\hand{A3}{K76}{963}{KJ952}}% + {}% + {\hand{K86}{T9542}{874}{T3}}% + {}% + {\hand{QT952}{Q83}{AK5}{A6}}% + {} +\end{quote} +{\bf Remarks} \\ +A NESW diagram is obtained with +\verb=\usebox{\NESW}= --- or something +you have designed yourself --- +as fifth parameter.\\ +An elegant solution to the problem of having a default +NESW figure which could be overruled by another figure +is the optional parameter mechanism, which --- helas --- +is lacking in the macro facility of \LaTeX. The same applies +to the bidding environment with the default bid sequence +N E S W. Again via the mechanism of optional parameters +one could provide another bid sequence order or +abbreviations suited for other languages. +For the hand parameters one could think of the mechanism of named +parameters with complete freedom of the sequence order +of the parameters: one could easily provide the hands +in the order N E S W, the deal order. +% +\section*{Conclusions} +The author claims that bridge publications can be typeset easily +with high quality via \LaTeX\ and the given macros. +Proofreading of deals not generated by computer remains +tiresome.\\ +The lack of the facility of optional parameters in the +\verb=\newcommand= command and the \verb=newenvironment= +environment is felt as an understandable inelegancy. +% +\section*{Acknowledgements} +The author is grateful to Victor Eijkhout and Nico Poppelier +for their suggested improvements. +% +\begin{thebibliography}{99} +\bibitem{Br} BRIDGE. Monthly of the NBB (Dutch +Bridge Union). +\bibitem{EC} Crowhurst, E.\ (1986): +ACOL in competition. Pelham. London. +\bibitem{JG}Grootenhuis, J.\ (priv.\ comm.): +Kaartverdelingen en biedverloop bij bridgen +--- Een SGML tutorial. (Dutch). +\bibitem{HWK}Kelder, J., B.\ van der Velde (1986): +Dwangposities tegen \'e\'en tegenstander. Becht. A'dam. (Dutch). +Translated from:\\ +Kelsey, H.W.\ (1985, paperback):\\ +Simple squeezes. Gollancz. London. +\bibitem{LL} Lamport, L.\ (1986): +\LaTeX, a document preparation system. Addison-Wesley. +\bibitem{HM}Mulders, H.P.A.\ (priv.\ comm.): +\verb=\verbinput=. +\end{thebibliography} +{\bf P.S.} \ Dear Ron,\\ +I hope you are not too annoyed with my polishing of the article. +Agreed, I should have done that before submitting the paper. +Sorry once again. +But now the good news. At this moment --- the really (sic!) end of my +polishing process ---I asked myself the questions: `Is this article +worth publishing?', `Isn't it so that the macros are that simple such that +everybody not only could but would write them from scratch?'. +I for myself wouldn't and certainly didn't. +I polished and polished and paid attention to as much details as I +could think of under guidance of: abstraction, adaptability, +beauty, clearity, compactness, completeness, correctness, efficiency, +elegance, flexibility, modularity, modesty, relevance, robustness, +simplicity, transparency, and usefulness. \\ +Best wishes, +Kees (I wouldn't mind publishing this note as well). +\end{document} +% + + diff --git a/info/laan/paradigm/baker.eps b/info/laan/paradigm/baker.eps new file mode 100644 index 0000000000..60dc0b457e --- /dev/null +++ b/info/laan/paradigm/baker.eps @@ -0,0 +1,40 @@ +%!PS +%%BoundingBox: -80 -80 80 80 +%%Creator: cgl (inspired by Woody Baker) +%%CreationDate: 1996.05.21:1858 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%200 500 translate +% +4{%one quarter +-15 25 moveto +0 -10 rlineto +60 0 rlineto +0 -30 rlineto +10 0 rlineto +0 40 rlineto +-70 0 rlineto +0 10 rlineto +80 0 rlineto +0 -60 rlineto +-30 0 rlineto +0 10 rlineto +10 0 rlineto +% +35 -25 moveto +0 -10 rlineto +20 0 rlineto +10 10 rlineto +% +45 15 moveto +10 10 rlineto +90 rotate +}repeat +% +stroke +% +/Courier findfont 10 scalefont setfont +-55 -75 moveto +(Courtesy Woody Baker)show +showpage diff --git a/info/laan/paradigm/barnwindowii.eps b/info/laan/paradigm/barnwindowii.eps new file mode 100644 index 0000000000..a5fe8a57d9 --- /dev/null +++ b/info/laan/paradigm/barnwindowii.eps @@ -0,0 +1,38 @@ +%!PS Barn Window II +%%BoundingBox: -40 -40 40 40 +%%Creator: cgl +%%CreationDate: May 29 1996 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%300 500 translate +% +/l 36 def +/r {l 22.5 sin mul} def +/m {l 22.5 cos mul} def +8{r .5 mul 0 moveto + l 0 lineto + currentpoint %begin circular arc + 22.5 rotate m 0%center + r %radius + -90 90 arc + 22.5 rotate +}repeat +%inner circle +/rin {r .5 mul} def +rin 0 moveto +0 0 rin 0 360 arc +%outer circle +/rout {r m add} def +rout 0 moveto +0 0 rout 0 360 arc +%extra circles +/rin {r .25 mul} def +22.5 rotate +8{m rin add 0 moveto + m 0 rin 0 360 arc + 45 rotate +}repeat +stroke +showpage +%end diff --git a/info/laan/paradigm/bentley.eps b/info/laan/paradigm/bentley.eps new file mode 100644 index 0000000000..40af96a287 --- /dev/null +++ b/info/laan/paradigm/bentley.eps @@ -0,0 +1,15 @@ +%!PS EPSF +%%Title: Bentley's double loop +%%Creator: cgl (inspired by Bentleyj) +%%CreationDate: May 30 1996 +%%BoundingBox: -100 -105 100 105 +%%EndProlog +10{1 1 10{100 0 moveto + gsave + dup 36 mul rotate + 100 0 lineto stroke + grestore + } for + 36 rotate +} repeat +showpage \ No newline at end of file diff --git a/info/laan/paradigm/eschera.eps b/info/laan/paradigm/eschera.eps new file mode 100644 index 0000000000..ad36e3f510 --- /dev/null +++ b/info/laan/paradigm/eschera.eps @@ -0,0 +1,17 @@ +%!PS Escher's impossible triangle +%%BoundingBox: -40 -40 40 40 +%%Creator: cgl (inspired by Guy Shaw) +%%CreationDate: 1996.05.23:1858 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%100 500 translate +3{25 34 moveto + 25 -34 lineto + 17 -38.2 lineto + 17 20 lineto + -17.6 0 lineto +120 rotate +}repeat +stroke +showpage \ No newline at end of file diff --git a/info/laan/paradigm/escherb.eps b/info/laan/paradigm/escherb.eps new file mode 100644 index 0000000000..5a3ea87dd9 --- /dev/null +++ b/info/laan/paradigm/escherb.eps @@ -0,0 +1,25 @@ +%!PS +%%BoundingBox: -40 -40 40 40 +%%Creator: cgl (inspired by Guy Shaw) +%%CreationDate: 1996.05.23:1858 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%Essential part +%300 500 translate +25 34 moveto currentpoint +0 -68 rlineto currentpoint%down + -120 rotate +25 34 lineto%preserve symmetry + 120 rotate currentpoint +17 20 lineto currentpoint +-17.6 0 lineto currentpoint +%labels +/Courier findfont 8 scalefont setfont +moveto -5 -3 rmoveto (5) show +moveto 1 1 rmoveto (4) show +moveto 2 -5 rmoveto (3) show +moveto 2 0 rmoveto (2) show +moveto 2 0 rmoveto (1) show +stroke +showpage diff --git a/info/laan/paradigm/escherknotiii.epsabr b/info/laan/paradigm/escherknotiii.epsabr new file mode 100644 index 0000000000..31946a9aae --- /dev/null +++ b/info/laan/paradigm/escherknotiii.epsabr @@ -0,0 +1,25 @@ +%!PS EPSF +%%BoundingBox: -40 -31 40 43 +%%Creator: MetaPost and JJW, CGL +%%CreationDate: June 17 1996 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +3{-21.6507 12.5 moveto +-21.6507 27.74551 -13.78212 42.5003 + 0 42.5003 curveto +13.78212 42.5003 21.6507 27.74551 + 21.6507 12.5 curveto +21.6507 -0.24506 16.04897 -12.19249 + 6.58395 -20.3313 curveto +% +-14.3152 15.86746 moveto +-12.43301 23.58928 -7.45113 29.75021 + 0 29.75021 curveto +9.64748 29.75021 15.15549 19.42186 + 15.15549 8.75 curveto +15.15549 -2.07904 9.37823 -12.08548 + 0 -17.5 curveto +120 rotate +}repeat stroke showpage +%%EOF \ No newline at end of file diff --git a/info/laan/paradigm/escherknotmf.eps b/info/laan/paradigm/escherknotmf.eps new file mode 100644 index 0000000000..32370ae4f3 --- /dev/null +++ b/info/laan/paradigm/escherknotmf.eps @@ -0,0 +1,20 @@ +%!PS EPSF +%%Title: Escher knot (mf prompted) +%%Creator: cgl (inspired Knotplot) +%%CreationDate: June 1996 +%%BoundingBox: -80 -80 80 80 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%150 650 translate +3{-43.30139 25 moveto + -43.30139 55.49103 -27.56424 85.00061 + 0 85.00061 curveto + 27.56424 85.00061 43.30139 55.49103 + 43.30139 25 curveto + 43.30139 -5.94014 26.79497 -34.5299 + 0 -50 curveto +120 rotate +}repeat +%pathbox = = = = ???p +stroke showpage diff --git a/info/laan/paradigm/flower.eps b/info/laan/paradigm/flower.eps new file mode 100644 index 0000000000..cd39433b4b --- /dev/null +++ b/info/laan/paradigm/flower.eps @@ -0,0 +1,17 @@ +%!PS EPSF +%%Title: flower.eps +%%Creator: cgl +%%CreationDate: June 4 1996 +%%BoundingBox: -50 -50 50 50 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +/r 36 def +10{r r moveto%begin drawing point + r 0 r 90 180 arc + currentpoint%origin + 0 r r 270 360 arc + 36 rotate +}repeat +stroke +showpage diff --git a/info/laan/paradigm/gurariabc.eps b/info/laan/paradigm/gurariabc.eps new file mode 100644 index 0000000000..979f573bca --- /dev/null +++ b/info/laan/paradigm/gurariabc.eps @@ -0,0 +1,20 @@ +%!PS EPS +%%Title: Guarai's ABC +%%BoundingBox: 0 -45 100 90 +%%Creator: Gurari +%%CreationDate: copied June 17 1996 +%%Pages: 1 +%%EndComments +%%EndProlog +%%Page: 1 1 +%300 500 translate +/Times-Bold findfont 45 scalefont setfont +-40 rotate +1 -.03 0{setgray + 0 0 moveto + (ABC) show + 3 rotate + } for +0 0 moveto -4 rotate +1 setgray (ABC) show +showpage diff --git a/info/laan/paradigm/gurarisq.eps b/info/laan/paradigm/gurarisq.eps new file mode 100644 index 0000000000..d95dfe63a7 --- /dev/null +++ b/info/laan/paradigm/gurarisq.eps @@ -0,0 +1,15 @@ +%!PS Gurari squares +%%BoundingBox: -200 -40 200 125 +%%Creator: cgl +%%CreationDate: June 20 1996 +%%EndProlog +%300 500 translate +/r 50 def +0 0 moveto 90 rotate +50{r 0 rmoveto + 1 1 4{0 r rlineto + 90 rotate}for + -30 rotate + .9 .9 scale +}repeat +stroke showpage diff --git a/info/laan/paradigm/jvr.eps b/info/laan/paradigm/jvr.eps new file mode 100644 index 0000000000..5273a7e86f --- /dev/null +++ b/info/laan/paradigm/jvr.eps @@ -0,0 +1,44 @@ +%!PS +%%Creator: J.V. Romanovsky +%%CreationDate: 1996? +%%BoundingBox: -200 -200 200 200 +%%EndProlog +%%Page: 0 1% +/rl{rlineto}def % to reduce the code +/FS {gsave setgray fill grestore stroke}def + % gsave ... grestore are used to save the graphic environment + % it is necessary if you want to use the current path several + % times, as here: to fill and to stroke +/s3 0.75 sqrt def /unit 40 def + % Two constants, 'unit' defines the size of construction +/U { unit mul 0 exch rl} def + % Verical line for several units +/R { unit mul % Transfer the number of units to length + dup % Copy it + s3 mul % Calculate X-offset + exch % Hide it + 0.5 mul % Calculate Y-offset + rl} def % Draw the line with the given offset pair +/L { unit mul dup s3 mul neg % neg is the only modificaion + exch 0.5 mul rl}def + % Right and left lines for several lines +/M{ s3 unit mul 0.5 unit mul translate -120 rotate} def + % Rotation of the picture to scan the vertices of the central + % triangle +%200 400 translate +/P1{ 0 0 moveto 2 R -1 L -2 U 4 R -1 U -9 R 4 U -1 L -2 U + 3 R 4 U -4 R 3 U -1 L -2 U -1 L} def + % Sorry, only copying the source Escher draft + % and no own imagination + % Three parts of the picture are made with the same procedure +%mark origin +%0 10 moveto +%0 -10 lineto +%10 0 moveto +%-10 0 lineto +%stroke +P1 0.6 FS M +P1 0.8 FS M +P1 0.95 FS M +showpage +% End diff --git a/info/laan/paradigm/linebundle.eps b/info/laan/paradigm/linebundle.eps new file mode 100644 index 0000000000..95f30d401a --- /dev/null +++ b/info/laan/paradigm/linebundle.eps @@ -0,0 +1,15 @@ +%!PS +%%Title: linebundle.eps +%%Creator: cgl +%%CreationDate: June 4 1996 +%%BoundingBox: -40 -40 40 40 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +/r 36 def +10{0 0 moveto + r 0 lineto + 36 rotate +}repeat +stroke +showpage \ No newline at end of file diff --git a/info/laan/paradigm/malbork.eps b/info/laan/paradigm/malbork.eps new file mode 100644 index 0000000000..ec53c48c44 --- /dev/null +++ b/info/laan/paradigm/malbork.eps @@ -0,0 +1,28 @@ +%!PS +%%BoundingBox: -40 -40 40 40 +%% +%%Creator: cgl +%%CreationDate: 1996.05.21:1858 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 + +%100 400 translate + +% +45 rotate +10 0 moveto +4{20 0 37.5 12.5 25 25 curveto + 12.5 37.5 0 20 0 10 curveto + 90 rotate}repeat + +%inside lops +5 0 moveto +4{5 35 35 5 0 5 curveto + 90 rotate}repeat + +%circle +36 0 moveto +0 0 36 0 360 arc +stroke +showpage diff --git a/info/laan/paradigm/paradigm.gam b/info/laan/paradigm/paradigm.gam new file mode 100644 index 0000000000..b22198c1e0 --- /dev/null +++ b/info/laan/paradigm/paradigm.gam @@ -0,0 +1,431 @@ +%August 1995, C.G. van der laan, cgl@rc.service.rug.nl +\input blue.tex +\loadtocmacros +%\tolerance500\hbadness=499\hfuzz=5pt +\parindent=1pc +\everyverbatim{\unmc} + +\bluetitle Paradigms: It's all in the game + +\bluesubtitle Dialogue with \TeX + +\blueissue \maps{96}1 + +\beginscript + +\bluehead BLUe's Design VI + +Hi folks. +In {\oldstyle1989} Greene contributed +`Playing in \TeX's mind' to TUG {\oldstyle89}. +Having fun with \TeX{} has been on my mind all the time. +Of late, I thought of tic-tac-too as an exercise in programming +dialogues in \TeX, in a simple and elegant way, with hopefully +some paradigms emerging, suited for educational purposes. +The play is simple but nevertheless entails essential aspects +of having a dialogue with \TeX. +Below I first strip the play to the essentials and +from there build the user-friendly, but otherwise modest, code. +At the end the \TeX ing peculiarities are summarized. + +\bluehead The play + +Tic-tac-too is played by two persons on a board with $3{\times}3$ fields. +Each player marks a field in turn and the one who has first +three marks in a row has won. +\def\data{+\cs o\cs+\rs \cs o\cs+\rs o\cs \cs +} +$$\ruled\btable\data$$ + +\bluehead Prototyping + +The dialogue with \TeX{} goes through the log file, also called transcript. + +The board is represented by the defs \cs{1}, \dots\cs{9} row-wise. +Each player owns a mark called \cs{markplayer} and \cs{markopponent}. +A user is prompted to input a value\Dash 1, 2, ... or 9\Dash +which indicates the field where to put his mark. +The program keeps track of the kind of mark, via a toggle. +To end the game the user can input 0. + +The above resulted in the following bare-to-the-bones +implementation of tic-tac-too. +\beginverbatim +\def\showboard{\immediate\write0{\1\2\3} + \immediate\write0{\4\5\6} + \immediate\write0{\7\8\9}} +\def\initialize{\def\1{-}\def\2{-}\def\3{-} + \def\4{-}\def\5{-}\def\6{-} + \def\7{-}\def\8{-}\def\9{-}} +\def\play{\initialize \loop\showboard + \ifx\mark\markplayer + \let\mark\markopponent\else + \let\mark\markplayer\fi + \immediate\write0{Supply index for \mark:} + \read0to\index \expandafter + \xdef\csname\index\endcsname{\mark} +\ifnum\index>0 \repeat}%end \play +\def\markplayer{+}\def\markopponent{o} +\endlinechar-1 %TB20.18 +\play \bye +!endverbatim +Remarks. +Because of the toggling of the \cs{mark} an \cs{xdef} was needed. + +One could code that the player and opponent are both +taking care of during each traversal of the loop. +However, apart from that it makes the code longer it is also clumsy, and +if careless one has to account for multiple exits of the loop. +I assumed states in which the loop is traversed. +The next steps are not for the faint of heart. + +\bluehead Real-life version + +Given the above prototype implementation we can refine, +add more bells-and-whistles. Basically these add-ons are in two directions +\bitem improve the user interface +\bitem let the program do more, such as deciding who has won. +\smallbreak + +\bluesubhead Improving the user interface + +Explain the conventions adopted, especially what the indices stand for. + +Always nice is to allow for personalization, i.e.\ the system prompt asks for +YOU, with your name. +This entails that the players must be asked to identify themselves and that +the toggling must be extended. + +Another feature is that the program prompts the remaining indices to choose from. + +And what about robustness? I decided not to implement robustness with respect +to lowercase or uppercase y or n, for example. +I also refrained from checking whether the supplied index is allowed.\ftn +{Not that difficult, actually, + because the set of allowed indices is maintained.} + +\bluesubhead Let the program do more + +The most important aspect is to add intelligence to the program to check +for a winner. + +The play restarts automatically + +\bluesubhead The code + +The board is represented by the defs +\cs{1}, \cs{2}, \dots \cs{9}, the $3{\times}3$ board row-wise. + + +The structure of the program is similar to the prototype, +with \cs{play} elaborated and the check \cs{checkforgameend} added. +\beginverbatim +\immediate\write0{Tic-tac-too + Aug 1995, cgl@rc.service.rug.nl} +\let\ea\expandafter +\newcount\k\newcount\value\newcount\checksum +\newif\ifsol +\newtoks\set %Index set +\def\del#1{\def\lop##1#1##2\pol{\set{##1##2}} + \ea\lop\the\set\pol} +% +\def\showboard{\immediate\write0{} +\immediate\write0{\1\2\3} +\immediate\write0{\4\5\6} +\immediate\write0{\7\8\9}} +% +%Initialization +\def\initialize{\set{123456789}\solfalse + \immediate\write0{New names of players? + (default \player\space and \opponent)} + \read0to\yorn + \if y\yorn + \immediate\write0{Name player} + \read0to\player + \immediate\write0{Name opponent} + \read0to\opponent + \fi\k0 + \loop\advance\k1 + \ea\def\csname\the\k\endcsname{-} + \ifnum\k<10 + \repeat + \immediate\write0{Empty board} +}%end initialization +%Test for solution +\def\sol#1#2#3{{\advance\count#1\count#2 + \advance\count#1\count#3 + \ifnum\count#1=\checksum \global\soltrue\fi}} +\def\checkforgameend{% +\sol123\ifsol\message{\who\space won}\k0 \else +\sol456\ifsol\message{\who\space won}\k0 \else +\sol789\ifsol\message{\who\space won}\k0 \else +\sol147\ifsol\message{\who\space won}\k0 \else +\sol258\ifsol\message{\who\space won}\k0 \else +\sol369\ifsol\message{\who\space won}\k0 \else +\sol159\ifsol\message{\who\space won}\k0 \else +\sol357\ifsol\message{\who\space won}\k0 \else +\fi\fi\fi\fi\fi\fi\fi\fi} +%Play +\def\play{\initialize\begingroup +\loop\showboard + \ifx\who\player\value-1 \checksum-3 + \let\who\opponent + \let\mark\markopponent + \else\value1 \checksum3 + \let\who\player + \let\mark\markplayer + \fi + \immediate\write0{\who, supply index + for \mark:} + \immediate\write0{Choose from: \the\set. + (0 terminates)} + \read0t\ea o\csname\who\endcsname + \k\csname\who\endcsname + \ea\xdef\csname\the\k\endcsname{\mark} + \count\k\value + \checkforgameend +\ifnum\k>0 \ea\del\ea{\the\k} +\repeat\endgroup +\immediate\write0{Play another game?} +\read0to\newplayyorn +\if y\newplayyorn\ea\play\fi}%end Play +% +%Defaults +\def\player{Kees} \def\opponent{Ina} +\def\markplayer{+} \def\markopponent{o} +% +\immediate\write0{} +\immediate\write0{Board numbering} +\immediate\write0{123} +\immediate\write0{456} +\immediate\write0{789} +% +\play \bye +!endverbatim +Remark. In order to get the personalized prompts \cs{Kees}, or \cs{Ina} +the following coding was needed. +\beginverbatim +\read0t\ea o\csname\who\endcsname +!endverbatim +The few lines that follow look unnecessary complex +but are entailed by the above. + +\bluehead What more? + +It is intrigueing to ponder about adding even more intelligence. +For example to let the game prompt for obligatory moves, +or to let the program terminate when draw is inevitable, that is when there +is no possible solution left. +In order to achieve this I chose to +\bitem maintain the set of possible solutions, instead of checking all possible + solutions\ftn{This entails that non-feasible candidates are eliminated + from the set of candidate solutions.} +\bitem update the set of solutions after each move, and + look for a solution or a draw +\bitem look for obligatory moves. +\smallbreak +With respect to robustness the input can be checked for whether the index +is allowed, casu quo a y(es) or n(o). + +\beginverbatim +\immediate\write0{Tic-tac-too + Aug 1995, cgl@rc.service.rug.nl} +\let\ea\expandafter \let\nx\noexpand +\newcount\k\newcount\kk +\newcount\value\newcount\checksum +\newcount\feasible\newcount\prompt +%Solution lines +\newcount\hi\newcount\hii\newcount\hiii +\newcount\vi\newcount\vii\newcount\viii +\newcount\di\newcount\dii +\newif\ifsol +\newif\ifnotfound +%Index set and deletion from index set +\newtoks\set %Index set +\def\del#1{\def\lop##1#1##2\pol{\set{##1##2}} + \ea\lop\the\set\pol} +% +\def\showboard{\immediate\write0{} +\immediate\write0{\1\2\3} +\immediate\write0{\4\5\6} +\immediate\write0{\7\8\9}} +% +%Initialization +\def\initialize{\set{123456789}\solfalse + \hi0 \hii0 \hiii0 \vi0 \vii0\viii0 + \di0 \dii0 \feasible8 \prompt0 +%Cell no associated with solution subsets +\ea\def\csname solset1\endcsname{% + \ls\hi\ls\vi\ls\di} +\ea\def\csname solset2\endcsname{% + \ls\hi\ls\vii} +\ea\def\csname solset3\endcsname{% + \ls\hi\ls\viii\ls\dii} +\ea\def\csname solset4\endcsname{% + \ls\hii\ls\vi} +\ea\def\csname solset5\endcsname{% + \ls\hii\ls\vii\ls\di\ls\dii} +\ea\def\csname solset6\endcsname{% + \ls\hii\ls\viii} +\ea\def\csname solset7\endcsname{% + \ls\hiii\ls\vi\ls\dii} +\ea\def\csname solset8\endcsname{% + \ls\hiii\ls\vii} +\ea\def\csname solset9\endcsname{% + \ls\hiii\ls\viii\ls\di} + \immediate\write0{New names of players? + (default \player\space and \opponent)} + \read0to\yorn + \if y\yorn + \immediate\write0{Name player} + \read0to\player + \immediate\write0{Name opponent} + \read0to\opponent + \fi\k0 + \loop\advance\k1 + \ea\def\csname\the\k\endcsname{-} + \ifnum\k<10 + \repeat + \immediate\write0{Empty board} +}%end initialization +% +%Test for solution +\def\ls#1{%#1 is a solution counter + \ifnum#1=0 \advance#1\value + \else\ifnum\sign#1=\value \advance#1\value + \else\advance\feasible-1 + \delete#1 %from solution sets + \ifnum\feasible=0 \showboard + \message{***Draw***}\k0 + \fi + \fi + \fi + %Check for solution + \ifnum#1=\checksum \showboard + \message{***\who*** won}\k0 + \fi} +% +\def\sign#1{\ifnum#1>0 1\else -1\fi} +\def\solsetk{\csname solset\the\k\endcsname} +% +\def\delete#1{%#1 is a solution counter to be + %deleted from all solution sets +{\kk0 +\def\ls##1{\ifx#1##1\else\nx\ls\nx##1\fi} +\loop\advance\kk1 +\ifnum\kk<10 +\ea\xdef\csname solset\the\kk\endcsname + {\csname solset\the\kk\endcsname} +\repeat}}%end \delete +% +\def\fifo#1{\ifx#1\ofif\ofif\fi + \process#1\fifo} +\def\ofif#1\fifo{\fi} +\def\lstry#1{%#1 is a counter denoting + %a solution + \ifnum#1=0 + \else\ifnum\sign#1=\value + \advance#1\value + %Check for solution + \ifnum#1=\checksum \global\prompt\k + \fi\fi + \fi} +\def\process#1{\ifnum\prompt=0 + {\k=#1 \let\ls\lstry \solsetk}\fi} +% +\def\readprocess#1{\if#1\csname\who\endcsname + \notfoundfalse\fi} +% +\def\readindex{{\let\process\readprocess + \loop\read0t\ea o\csname\who\endcsname + %\who value in \set? + \notfoundtrue\ea\fifo\the\set0\ofif + \ifnotfound + \immediate\write0{Please supply index + from \the \set} + \repeat + \global\k\csname\who\endcsname}} +% +%Play +\def\play{\initialize\begingroup +\loop\showboard%\show\ the\solset + \ifx\who\player\value-1 \checksum-3 + \let\who\opponent + \let\mark\markopponent + \else\value1 \checksum3 + \let\who\player + \let\mark\markplayer + \fi + %Is there a winning move? + %(Prefails obligatory move) + {\prompt0 \ea\fifo\the\set\ofif + \ifnum\prompt>0 \global\prompt0 \fi} + %The idea is that the player must see it + %him/herself. Of course the program knows + %about the winning move. + %Obligatory move? (criterion 0<\prompt (<10) + \ifnum\prompt>0 \immediate\write0{Sorry \who, + obligatory move \the\prompt}\k\prompt + \else + \immediate\write0{\who, supply index + for \mark:} + \immediate\write0{Choose from: \the\set. + (0 terminates)} + \readindex + \fi + %put mark on board + \ea\xdef\csname\the\k\endcsname{\mark} + %update solutions associated with \k + \solsetk +%k=0 is stopping criterion +\ifnum\k>0 \ea\del\ea{\the\k}% + %Look ahead for obligatory move: + % Can \who gain in next turn? + \prompt0 \ea\fifo\the\set\ofif +\repeat\endgroup +\immediate\write0{Play another game?} +\read0to\newplayyorn +\if y\newplayyorn\ea\play\fi}%end Play +% +%Defaults +\def\player{Kees} \def\opponent{Ina} +\def\markplayer{+} \def\markopponent{o} +%And off we go +\immediate\write0{} +\immediate\write0{Board numbering} +\immediate\write0{123} +\immediate\write0{456} +\immediate\write0{789} +\immediate\write0{} +\play \bye +!endverbatim + +\bluehead Is this all? + +Especially the code in the last section has become complex. Should we make it more complex? +For the moment I stopped. +However, it is tempting to increase the order to {\oldstyle4}, +and to extend the play to {\oldstyle3} dimensions. +My case rest. + +\bluehead Paradigms + +The following functionalites have been encountered and a way how to code +these in \TeX{} have been worked out. +\bitem loop traversal in various states +\bitem global Boolean, \cs{global}\cs{soltrue} +\bitem maintaining an index set, + deleting an element from a set +\bitem test for an empty set +\bitem high-level parameterization, for example + a personalized prompt within a state-dependent loop +\bitem \cs{read} with a {\em reference\/} to a prompt through\\ + |\read0t\ea o\csname\who\endcsname| +\bitem check on what is read is allowed. +\smallbreak +Starting from the bare-to-bones prototype it is quite something to arrive +at a solution, which carries some intelligence and robustness \smiley. +\medskip +Have fun, and all the best. +\makesignature +\pasteuptoc +\endscript diff --git a/info/laan/paradigm/paradigm.hea b/info/laan/paradigm/paradigm.hea new file mode 100644 index 0000000000..f4d52bde07 --- /dev/null +++ b/info/laan/paradigm/paradigm.hea @@ -0,0 +1,587 @@ +%November 1994, Aug 1995, March 1996 +%Paradigm: Headache? +%C.G. van der Laan, cgl@rc.service.rug.nl +\input blue.tex \loadtocmacros +\tolerance500\hbadness=499\hfuzz=5pt +\parindent=1pc +\everyverbatim{\emc} + +\bluetitle Paradigms: Headache? + +\blueissue \maps{94}2 (revision March\on1996) + +\beginscript + +\bluehead BLUe's Design II + +Hi folks. When using \LaTeX{} +I was plagued in the past by the little glob of white space +on the first line after a head. +It made me clear that `spaces are harmful,' to paraphrase Dijkstra. +When designing \bluetex{} I had to look at the problem again +among other things, and to +\bitem provide a simple suite, with hardly no knowledge of the user + assumed about parameter separators +\bitem gobble redundant spaces as much as possible +\bitem allow also processing on the fly of the title +\bitem choose a coding style, and +\bitem choose a `markup language.' +\smallbreak + +My starting point was \cs{beginsection} \TB~\on355. +I chose |head| as root name conform to TUGboat. + +\bluesubhead The revision + +is about the superfluousness of the \# +as last element of a parameter specification, +from a functional point of view. + +The treatment of \cs{chapterhead} from BLUe's Reports +has been appended of August \on1995. + +A quick and dirty LP functionality to exhibit a ToC +has been added of August \on1995. +This ToC is not meant to be published but just + to assist developing notes, + to keep track of the structure, the setup, +which\Dash as reality taught me\Dash +develops too while writing. + +Really handy, believe me\winksmiley. + +\bluehead Headers + +I will design \cs{beginhead} and \cs{endhead}, +next to the minimal markup variant |\head{ ...}|.\ftn +{The subhead variants are similar but different in detail. + Especially in undoing glue when heads follow-up + each other without intervening text. Beware!} + +\bluesubhead Design goals + +From a typography point of view I would like to +\bitem discourage to set the title alone at the end of a page +\bitem typeset (flexible) vertical space (big) before and after (med) the title +\bitem gobble spaces at the beginning of the title +\bitem set the title in bold face (and the current size) unindented +\bitem don't indent the first line of the text after. +\smallbreak + +\bluesubhead What are the problems? + +The markup language constructs have to be chosen. +In macro expansion the two-part macro +\TeX nique should be the basis. In blue's format I adopted +the pairs |\begin| and |\end|. + +In order to set the title loose from the context +we have to determine values for the glue, +and be sure that it disappears at the top of a page. +The coding solution below has different values for the +parameters as supplied in \cs{beginsection}. +From experiments it turned out that the values supplied by Knuth +don't give nice results with blue.fmt. +Too much glue was inserted for my taste. + +Another problem is to prevent the head title +to be printed at the bottom of a page on its own. +The latter is related to the `widow-orphan' phenomenon. + +The coding of the minimal markup variant without parsing +but with processing of the fly of +`the argument' has to be resolved in some elegant way. + +The idea of a |\pre| and |\post| is general. +It parameterizes the placement of a document element +within context. Important! Whether you talk about titles, +displays, tables, graphs, or you name it. Perhaps +this should be generalized in something like +|\pasteup|. + +\beginverbatim +\def\beginhead{\the\prehead\bgroup\headfont} +\def\endhead{\egroup\the\posthead} +%with auxiliaries +\prehead{\vskip0pt plus2ex + \penalty-250\vskip0pt plus1ex + \bigskip\noindent} +\posthead{\medskip\nobreak + \noindent\ignorewhitespace}%Mod Nov 94 +!endverbatim + +\bluesubhead Take a deep breath + +The minimal markup form, {\em with the same functionality}, reads + +\beginverbatim +\def\head{\beginhead\bgroup + \aftergroup\endhead + \afterassignment\ignorespaces + \let\dummy=} +!endverbatim + +Explanation. +The replacement text starts \cs{beginhead} and a group. +Immediately after the opening of the group \cs{aftergroup} +takes care that the second part of the two-part macro will be invoked +at the right place. +The opening brace after the invocation of \cs{head} +is read away by assigning it to \cs{dummy}. +Spaces after the opening brace are ignored, due to +\cs{afterassignment}\cs{ignorespaces}. +The \TeX nique---moving the group opening---has been +borrowed from plain's \cs{footnote}, \TB~\on363. +There it is used at the end of the replacement text of \cs{fo@t}. +\beginquote +What is the difference with the macro with a \# as last element of the +parameter specification?\ftn +{The \# as last character of the parameter text makes that + the opening brace and what follows + is placed after the replacement text of \cs{head}, \TB~\on204.} +\endquote +At first sight it looks identical. However, the difference is twofold. +The situation with the \# at the end of the parameter text differs +because +\bitem an opening brace after the invocation of \cs{head} is syntactically required +\bitem no braces are needed for the last argument, because $\{$ is + a parameter separator.\ftn{The example, \TB~\on204, + used the invocation + |\a3pt{x}|, while without \# as last element of the parameter list + the markup would have read |\a{3pt}{x}|.} +\smallbreak + +Because of these extra safeguards, +I stayed with the \# as end of the parameter list, +for building one-part macros on top of two-part macros. +Quite something isn't it? + +\bluesubhead Paradigm + +We should build upon two-part macros. +In order to add the short variant to {\em similar\/} two-part +macros the following template can be used. + +\beginverbatim +\def\#{\begin\bgroup + \aftergroup\end + \afterassignment\ignorespaces + \let\dummy=} +!endverbatim + +\bluesubhead Take a deeper breath + +When using the above template in practice, +it occurred to me that \TeX{} could handle that too. +For \cs{head} the desired functionality is that + +\beginverbatim +\onepartmacro{head} +!endverbatim + +will build the macro \cs{head} based upon +the two-part macros \cs{beginhead} and \cs{endhead}. + +The naive coding\Dash which does not work, but makes +the purpose quite clear\Dash reads + +\beginverbatim +\def\onepartmacro#1{\def\#1##{\begin#1 + \bgroup\aftergroup\end#1 + \afterassignment\ignorespaces + \let\dummy=}} +!endverbatim + +Several desired functionalities have to be coded +in \TeX's peculiar way, with as result + +\beginverbatim +\def\onepartmacro#1{{ +\ea\let\csname begin#1\endcsname=\relax +\ea\let\csname end#1\endcsname=\relax +\toks0={\bgroup\aftergroup} +\toks1={\afterassignment\ignorespaces + \let\dummy=} +\ea\xdef\csname#1\endcsname##{% + \csname begin#1\endcsname + \the\toks0 \csname end#1\endcsname + \the\toks1 }}} +!endverbatim + +Explanation. +A lot of the trickery about partial expansion, \TB~\on216, has been applied. + +First a \cs{csname} is used to compose the names from the root name. + +Second the one-part macro is defined via an \cs{xdef} +with suppression of the expansion of the +|\begin|, |\end|, and the other tags. +It is an \cs{xdef} to keep the auxiliaries used local. +The first is handled via the property that a control sequence +equal to a character, and in general to an unexpandable token, is not expanded. +The second is handled by the property that a \cs{the} +on a token list is a one-step expansion. + +\bluesubhead Some remarks + +Note that I did not gobble spaces at the end of the title argument. +In the headtitle they won't harm because +the title is set on a line of its own.\ftn +{In the other heads the space at the end of the argument can be there on purpose. + Watch out!} + +Processing a title on the fly is needed for verbatims +and in general when we don't like the `eyes' of \TeX{} +to set catcodes differently from those the script expects +when digested in the `stomach.' + +\bluesubsubhead The bad news + +Minimal markup for \cs{head} and the like can be +felt as an anachronism. +With \AllTeX{} intelligent editors we don't need minimal markup anymore. + +\bluesubsubhead Disclaimer + +The above template does not work for all two-part macros, +for example not for my btable (or any \cs{halign}).\ftn +{See however, `Paradigms: Two-part macros.'} + +\bluesubsubhead The good news + +Via this mechanism we can abstract +at the {\em user level\/} from token variables and definitions. +The user can supply the information as if it was a token variable. +The using of the long form or the minimal form has been reduced +to a matter of taste. And that is a good thing. + +\def\head{\beginhead\bgroup + \aftergroup\endhead + \let\dummy=} + +\bluehead Tests? + +This note itself contains examples of use in its original form. + +\thisverbatim{\catcode`\|=12 } +\beginverbatim +\beginhead|Head text + in verbatim|\endhead + Text after\\next line + +\head{Head text, with |this| + in verbatim} + Text after\\next line +!endverbatim + + with results +\medskip +\beginlines +\kern-\medskipamount + +\beginhead|Head text in verbatim|\endhead +%\head{{\tt Head text in verbatim}} + Text after\\next line + +\head{Head text, with |this| in verbatim} + Text after\\next line +\medskip +\endlines +\medbreak +Run it,\ftn{blue.tex is available form the CTAN, + as is the accompanying article BLUe's Format.} +and have fun. All the best. + +\bluehead Note added in proof + +In order to allow blank lines after the heading in the script, +I replaced \cs{ignorespaces} in \cs{endhead} by +\cs{ignorewhitespace}.\ftn{Due to Phil Taylor. + TUG's \cs{ignorespacesandpars} would probably do too.} + +A blank line after a heading is natural for a text without explicit markup. +Knuth started from natural markup and stayed close to that, IMHO. +His markup tags to format the chapter (titles and contents) in \TB{} +file are + +\beginverbatim +\beginchapter +\endchapter +!endverbatim + +Imagine ASCII text with visual layout, and in order to markup +the title {\em and text\/} insert the above commands, with the natural +blank line already there to end the arguments of \cs{beginchapter}. +Knuth's \cs{beginchapter} not only takes care of the title but also +handles the chapter contents {\em on the fly\/} until \cs{endchapter} +is encountered. +Really much different from \LaTeX's approach, to name but +one general set of markup tags. + +\bluesubhead Knuth and natural markup + +Imagine that the ASCII text of a section reads +\beginverbatim +Section 1. Title + +Now starts the section text +proper... +And this is the last line of it. +!endverbatim + +What is the simplest and most natural markup for this? +First the requirements +\bitem section should be flexible towards language variation +\bitem title should be processed on the fly. +\smallbreak + +A solution is the following extension heavily inspired by +\cs{beginchapter} of manmac. + +\beginverbatim +\def\beginsection#1 #2#3. {\bgroup + \def\par{\egroup\endhead}% + \beginhead#1 #2#3. } +\posthead{\nobreak\medskip + \noindent\ignorewhitespace} +% +\let\endsection\relax%or forget about it +% +\def\ignorewhitespace{\begingroup +%Due to Phil Taylor EuroTeX 94 +\catcode`\ =9 +\catcode`\^^I=9 +\catcode`\^^L=9 +\catcode`\^^M=9 +\futurelet\dummy\endgroup} +!endverbatim + +The marked up script is obtained by only inserting \cs{beginsection}! + +\beginverbatim +\beginsection Section 1. Title + +Now starts the section text +proper... +And this is the last line of it. +!endverbatim + +The beauty of the above approach, Knuth's IMHO, is that the total section +is handled, the title as well as the contents part, with the title +proper part processed on the fly. +Moreover, it is as close to natural markup as I can think of. +(trivial) Language problems are absent. +One can abstract from `Section' via a toks variable \cs{sectionname}. +Automatic numbering can be inserted too, but the question is +whether it is really handy, especially in view of subsections and the +like. + +\bluehead Copied from BLUe's Report + +In BLUe's Report I have dealt with more complicate header matters, +which show up when we like to reuse the title for inclusion in +the ToC, ToE and ilks. It turns out that `\cs{bluechapter}' +is much more complicated than `\cs{bluehead}.' +Below the storing of titles and their reuse is dealt with among other things. +Because of storing\Dash which fixes the catcodes\Dash +the titles are not processed on the fly. + +\bluesubhead Chapter head matters + +The required functionalities\Dash the specs so to say\Dash are to +\bitem start a new page +\bitem store the title for reuse (running head, table of contents) +\bitem maintain and store the chapter counter (for use with the exercises, + table of contents, and the like) +\bitem write the title and title counter value to the contents file +\bitem typeset the title on a new page with some white space after +\bitem reset counters which start anew per chapter (headings, exercise number, + and the like) +\bitem provide the right \cs{headline} and \cs{footline} with the title, + chapter title, and page number +\bitem suppress the headline on the first page of a chapter (or supply for + an otherwise special headline) +\bitem process the title on the fily to allow for example verbatim +\bitem condition the writing of the title and title counter value + to the examples file. +\smallbreak + +Quite something, isn't? +That is why title matters are not trivial. +The conditioning of writing the title to the examples file is there, +because we don't like the title etc. to appear in that file if the chapter +lacks examples. + +\beginverbatim +\def\beginchapterhead{\the\prechapterhead + \storechaptertitle} +% +\def\storechaptertitle#1\endchapterhead{% + \global\chaptertitle={#1}\endchapterhead} +% +\def\endchapterhead{\centerline{\chapterfont + \the\chapternumbering\the\chaptertitle} + \the\postchapterhead\ignorewhitespace} +!endverbatim + +This approach looks promising. +What has to be done before is the concern of \cs{prechapterhead}. +\cs{storechaptertitle} does what its name suggests. +The formatting of the number of the chapter is the concern +of \cs{chapternumbering}. +\cs{postchapterhead} takes care of leftovers. +Default \cs{chapternumbering} is empty, that is, no number will be typeset. + +Undoubtedly, the careful reader would object that the title is stored +and that the catcodes are set before processing. +That is right, of course, but via \cs{everychapterhead}\Dash in +\cs{prechapterhead}\Dash +we can guarantee that symbols will have the right catcodes. +\cs{storechaptertitle} is there to allow the short variant +|\chapterhead{...}|. +The combination of storing and in-line verbatim does not work. Beware.\ftn +{For me this does not hinder because I don't like these kinds of font changes + in a chapter header.} + +\beginverbatim +\prechapterhead{\newpage\null\vskip4pc + \bgroup\catcode`\^=7 + \the\everychapterhead\the\thischapterhead + \global\advance\chaptercnt1 } +% +\postchapterhead{\egroup + \headcnt0 \exercisecnt0 \examplecnt0 + \write\toc{\nx\separator + {\alfanum\the\chaptercnt} + {\the\chaptertitle}} + %suppress headline first page chapter + \headline{\global\headline + {\hbox to\pagewd + {\sl\the\chaptertitle\hfill + \the\title}}}% + \footline{\hbox to\pagewd{\small + \rlap{Draft \today}\hfill\dash + {\oldstyle\the\pagenumber}\dash + \hfill\llap{\copyright + \the\crowner}}}% +%Example is redefined here such that on +%first use if ever in the chapter, it +%redefines itself into the regular macro, +%while writing the chapter titles to the +%table-of-examples, ToE, file. +%In this way chapter titles of chapters +%without examples will not be written to +%the ToE. + \def\example{\write\toe{\nx\separator + {\alfanum\the\chaptercnt} + {\the\chaptertitle}} + \let\example\regularexample + \example} + \thischapterhead{}\vskip3pc} +!endverbatim + +The material is enclosed within a group to keep the effect +of \cs{thischapter} local. + +\cs{example} is defined such that only when it is used +the title and number of the chapter will be written to the file +associated with \cs{toe}. \cs{regularexample} writes the example title +and number to the file associated with \cs{toe}. + +Intriguing is \cs{alfanum}. The purpose is to control whether a number +or a letter should appear. This is particularly useful with appendices. +\beginverbatim +\def\setupappendices{\thischapterhead= + {\chaptercnt64 \gdef\alfanum{\char}% + \global\chapternumbering= + {\alfanum\the\chaptercnt: }}} +!endverbatim + +And what about the one-part macro on top? +The above was already complicated. +What is the problem for a one-part macro? +For most of the cases we can do with a simple variant. +However, when we like to process math, especially the circumflex, +as part of the title more work has to be done. The mechanism has been +explained in `Paradigm: Two-part macros.' + +\beginverbatim +\def\chapterhead{\bgroup + \def\storechaptertitle##1{\egroup + \global\chaptertitle{##1}% + \endchapterhead}\beginchapterhead} +!endverbatim + +As a tribute to manmac I also defined the following limited variant.\ftn +{The circumflex in math in the title will hiccup. Most of the time we + don't need that.} + +\beginverbatim +\def\bluechapter#1\par{\beginchapterhead + #1\unskip\endchapterhead} +!endverbatim + +A trivial user interface on top which counteracts the curly braces mania +at the expense of processing on the fly.\ftn +{What does on-the-fly mean anyway, when we have to store the title for multiple use? + The answer is that we would like to allow for math too. No verbatims however.} + +\bluehead A little LP functionality + +Of late with notes I needed to generate automatically a small rudimentary +ToC to assist my writing and developing notes. Just quick and dirty. +For that purpose I provided the following for the |\blue(sub(sub))head|-s.\ftn +{Be aware that these head titles are not processed on the fly. + In March \on1996 I replaced writing to a file by maintaing the toc in a toks variable, + because in general it is not a mouth-only process the writing can go astray. + It did with |$\longrightarrow$|. Actually, for this toc assitant I did not need + the output functionality of adding page numbers.} + +\beginverbatim +\newtoks\tocvar +\let\bh\bluehead +\long\def\bluehead#1\par{\bh#1\par +\tocvar\ea{\the\tocvar\par#1}} +\let\bsh\bluesubhead +\long\def\bluesubhead#1\par{\bsh#1\par +\tocvar\ea{\the\tocvar\par\quad#1}} +\let\bssh\bluesubsubhead +\long\def\bluesubsubhead#1\par{\bssh#1\par +\tocvar\ea{\the\tocvar\par\qquad#1}} +\let\be\blueexample +\long\def\blueexample#1\par{\be#1\par +\tocvar\ea{\the\tocvar\par\qquad ex: #1}} +!endverbatim + +For pasting up the ToC I supplied. +\beginverbatim +\long\def\pasteuptoc{\newcol + \bluehead Contents\par + \the\tocvar + \let\makesignature\relax} +!endverbatim + +Finally, I merged the above into BLUe's format system. +The toks storage allocation for \cs{tocvar} +and \cs{loadtocmacros} in blue.tex, and +the rest in tools.dat. + +The user can supply +\cs{loadtocmacros} at the beginning after |\input blue.tex|, and +\cs{pasteuptoc} just before \cs{endscript}. + +In this way these macros don't conflict, just an extra +to support your notes with a ToC at the end, to maintain +the overview.\ftn{Note that \cs{report} already provides for a ToC.} + +\bluehead Acknowledgements + +Phil Taylor is kindly acknowledged for his \cs{ignorewhitespace} +as generalization of \cs{ignorespaces}, and his suggestion to assign +\cs{relax} to tokens to inhibit expansion instead of a number. +The latter is done on \TB~\on216. + +Have fun, and all the best. +\makesignature +\pasteuptoc +\endscript \ No newline at end of file diff --git a/info/laan/paradigm/paradigm.itm b/info/laan/paradigm/paradigm.itm new file mode 100644 index 0000000000..e3e25928b9 --- /dev/null +++ b/info/laan/paradigm/paradigm.itm @@ -0,0 +1,216 @@ +%November 1994, +%Paradigm: plain's item extended +%C.G. van der laan, cgl@rc.service.rig.nl +\input blue.tex \loadtocmacros +\loadindexmacros\preindex{\head{Index}} +\tolerance500\hbadness=499\hfuzz=5pt +\parindent=1pc +\everyverbatim{\emc} + +\bluetitle Paradigms: Plain's \cs{item}-s extended + +\blueissue \maps{94}2 {\small revision March \on1996} + +\beginscript + +\bluehead A new series + +Hi folks. After having given birth to BLUe's Format\Dash yes YAF, +yet another format, to paraphrase YACC\Dash I considered it of +general interest to spread gems to the world outside +via MAPS and hopefully via TTN's `Hey \Dash{} It works' column. + +The reason for me doing so is that apparently trivial +design aspects need careful attention in this macro +expansion branch of software engineering. +We have to start allover from the basics---slowly and +carefully---and end up with paradigms of macro expansion +coding. + +I intend a series of backside of the envelope contributions. + +\bluehead BLUe's Design I + +^^|\item| +When you like plain's \cs{item}-s so much as I do then this is for you. +Hang on! +In practice we all like bulleted \cs{item}-s and +\cs{item}-s with automatic numbering and lettering. +It looks like---biased by \LaTeX---that we need some +|\begin| and |\end| to begin and end. +Not so! + +It can be done simpler, with nearly the same +minimal markup as with \cs{item}. +The extra is to end the list by \cs{smallbreak}, +which is nearly natural.\ftn{I use \cs{smallskip} after \cs{item}-s + for setting the list slightly apart from what follows. + When a header follows, or you just like to + end the list, say \cs{endlist} which \TeX nically ends + the group.} + +Remember \TB~\on102, where Knuth states +\beginquote +`It is customary to put \cs{medskip} before and after + a group of of itemized paragraphs, and to say \cs{noindent} +before any closing remarks that apply to all of the cases.' +\endquote +I decided not to include \cs{noindent} because +the list is set apart already. + +\bluesubhead Appetizer + +The coding of the bulleted item reads\ftn{\TB, exercise \on14.\on20.} + +\beginverbatim +\def\bitem{\item{$\bullet$}} +!endverbatim + +\bluesubhead Coding AN-items + +^^|\Aitem| +With automatic numbering and lettering we have +to stop the automatism of increasing the counter and +to reset the counter for subsequent use +at the end of the list. + +In \cs{item} nothing special had to be done. +Ending the paragraph via a blank line (or \cs{par}) +was enough. +We cannot modify \cs{par} locally +because \cs{par} starts the replacement text of +\cs{item} (and \cs{itemitem} as well). +So the natural markup to let a blank line (or \cs{par}) +end the list is not possible. + +I could not work along the remark made in \TB{} ex\on14.\on29{} either, +because this goes wrong with nesting, read with the use of \cs{itemitem}. + +My solution is a mixture of coding borrowed from +\cs{item} page \on355, +\cs{beginchapter} \on418, and of +\cs{d@nger} \on419{} of \TB.\ftn +{The more I come to think of it the more ways of doing boil up. + How to decide which one is the best?} + +\def\ftntxt{{\rm Do you see the extension for \cs{Aitem}?}} +\beginverbatim +\newcount\itemno +\def\nitem{\bgroup + \def\nitem{\advance\itemno1 + \item{\the\prenum + {\oldstyle\the\itemno + }\the\postnum}} + \def\smallbreak{\endgraf\egroup + \smallbreak} + \let\smallskip\smallbreak\nitem} +\def\aitem{\bgroup\itemno96!ftn!ftntxt + \def\aitem{\advance\itemno1 + \item{\char\itemno.}} + \def\smallbreak{\endgraf\egroup + \smallbreak} + \let\smallskip\smallbreak + \aitem} +\def\endlist{\endgraf\egroup} +%and the defaults +\prenum{(}\postnum{)} +!endverbatim + +We not only have to end the paragraph(s) but also to end the scope. + +\blueexample Numbered and nested items + +\prenum{}\postnum{.} +\beginverbatim +Text preceding\\next line +\prenum{}\postnum{.} +\nitem first numbered item\\next line +\itemitem- sublist\\next line +\nitem second numbered item\\next line +\itemitem- sublist\\next line +\smallbreak +Text in between\\next line +\aitem first lettered item\\next line +\aitem second lettered item\\next line +\smallbreak +Text after\\next line. +!endverbatim +with result +\medskip +Text preceding\\next line +\nitem first numbered item\\next line +\itemitem- sublist\\next line +\nitem second numbered item\\next line +\itemitem- sublist\\next line +\smallbreak +Text in between\\next line +\aitem first lettered item\\next line +\aitem second lettered item\\next line +\smallbreak +Text after\\ +next line. + +\bluesubhead Enumerated items + +Along the same line we can add an enumerated item as follows. + +\beginverbatim +\def\eitem{\bgroup + \def\eitem##1{\item{##1}}% + \def\smallbreak{\endgraf + \egroup\smallbreak}% + \let\smallskip\smallbreak + \eitem} +!endverbatim + +\bluesubhead Verbatim items + +Of late\ftn{In my tutorial flyer `Macro writing,' \on1995.} +I needed a list of items with each item only verbatim texts. + +To use \vrt{} at the end and the beginning of each line +and to add |\\| or so at the end is +in the spirit of \TB, as done with \cs{displaylines}. +Not bad but a nuisance to insert all those \vrt s. + +Another modular solution was to use \cs{bitem} and after that + +\beginverbatim +\preverbatim{}\postverbatim{}\beginverbatim +!endverbatim + +and to end each item entry by + +\thisverbatim{\catcode`\!=12 \catcode`\*=0 } +\beginverbatim +!endverbatim +*endverbatim + +The minimal markup solution is to provide a \cs{verbitem} tag which +assumes only verbatim text as entry. + +Pitfalls. +The second and so on tag must begin with !verbitem.\\ +The tag must appear on a line of its own.\\ +End with !smallbreak. + +\beginverbatim +\def\bitem{\begingroup + \def\bitem{\item{$\bullet$}}% + \def\smallbreak{\endverbatim + \endgraf\endgroup\smallbreak}% + \let\smallskip\smallbreak + \bitem + \def\item{\endverbatim%to close + \par\hang\textindent}% +} +\def\verbitem{\bitem +\preverbatim{}\postverbatim{}% +\beginverbatim} +!endverbatim + +Have fun, and all the best +\makesignature +\pasteuptoc +\sortindex\pasteupindex +\endscript diff --git a/info/laan/paradigm/paradigm.lin b/info/laan/paradigm/paradigm.lin new file mode 100644 index 0000000000..332b591ad8 --- /dev/null +++ b/info/laan/paradigm/paradigm.lin @@ -0,0 +1,755 @@ +%July 1995, modified Feb 1996 +%Paradigma: line bundle +%C.G. van der laan, cgl@rc.service.rug.nl +\input blue.tex +\loadtocmacros +\def\xytxt#1{%Function: place text #1 at x, y + \xy{\vbox to0pt{\vss + \hbox to0pt{\strut#1\hss}\kern0pt}}} +\tolerance500\hbadness=499\hfuzz=8pt +%\parindent0pt %=1pc +\everyverbatim{\emc} + +\bluetitle Paradigms: The winds and halfwinds + +\bluesubtitle Details matter + +\blueissue \maps{96}1 + +%\blueauthor Kees van der Laan + +\bluepictures\pythtreepic\spiralpic\windpic\trimodelpic\tritreepic + \bintreepic\rotatedbintreepic\chartpic + +\beginscript +\everyverbatim{\unmc} +\bluehead BLUe's Design V + +Hi folks. +How to draw lines at {\oldstyle45}$^\circ$ in \TeX{} is exercised. +This simple-looking and innocent problem touches on fundamental issues, +such as should we adhere to the Cartesian picture environment +approach,\ftn{The \LaTeX{} picture environment for example.} +or do we need something else now and then? + +This work emerged from studying Gurari's approach to graphics +incented by a suggestion in Jos Winnink's review, \maps{94}2. + +The discussion below explains what has been used in BLUe's format system +in the turtle graphics\ftn +{Knuth already used the `Turtle' idea in his dragon figures. + For those interested in turtle graphics consult for example + S. Papert: Mindstorms.} +macros, especially in the coding of +\cs{N}, \cs{E}, \cs{S}, \cs{W}, +\cs{NE}, \cs{SE}, \cs{SW}, \cs{NW}, next to +\cs{ESE}, and \cs{WSW}. +Examples are included which show what can be attained by these +basic functionalities. +It is also shown how the obtained pictures can be stored +in the picture database |pic.dat| for reuse +with different scaling or positioning. + +In the Appendix some tree diversions have been given. + +\bluehead What is the problem? + +\TeX's \cs{hrule} and \cs{vrule} primitives are a gem and very powerful. +It would be nice to have similar primitives for any direction. +In absence of these we can use line pieces provided in fonts. +However, the latter approach suffers from the following drawbacks +\bitem for a few discrete directions only +\bitem line lengths are discrete too +\bitem line thickness is inflexible. +\smallbreak + +\bluehead Why? + +The need for general and flexible line elements arose when I faced the problem how +to draw classical fractals.\ftn{Inspired by Gurari's work on \TeX{} and graphics.} +The very least is the possibility to draw lines at {\oldstyle45}$^\circ$\Dash the halfwinds. + +\blueexample Pythagorean tree + +$$\pythtreepic$$ +How to do this in \TeX\ftn +{For the coding of \cs{pythtree} see later. Or + Macro writing\Dash with confidence.}? + +Through the picture environment? +Too clumsy, and cumbersome when changing the order, for example. + +Through \PS? +This is possible, especially it provides for lines at all +orientations.\ftn{J V Romanovsky has provided a concise \PS{} program.} + +Through \MF? Definitely, see my \MF{} anthology. + +However, why not go for how far we can get just by \TeX? + +And what about the relevancy? I'm very pleased by the spin-off how to +typeset binary trees or charts, even rotated without the use of \PS. +See the Appendix or the Publishing with \TeX{} user's guide. + +What we need is not the Cartesian picture environment approach, +but the good old penplotter \TeX niques, better known +in the pedagogical world as `Turtle graphics.' + +\bluehead Turtle graphics + +The basic idea is that the position of the turtle is maintained in +the dimen variables \cs{x} and \cs{y}, +with the reference point left invariant. +The accompanying figure shows the effect of \cs{N1}: draw the line +(\cs{x}, \cs{y})\dash(\cs{x}, \cs{y}+1), i.e.\ the turtle moves up. +After completion \cs{y} has been increased by \cs{unitlength}. + +%Perhaps I better put it in pic.dat +\vskip2.5\bigskipamount +$$\unitlength.5ex + \y=0pt\x-10\unitlength + {\W{4}\E{40}}\S{4}% + {\advance\y-2\unitlength\xytxt{ Ref.\ point}}% + \N{20}\whiteE{20}\S4\whiteS4\xytxt{ (x,y)}$$ +\vskip1.5\bigskipamount +The movements\Dash our first steps in the turtle graphics world\Dash +can be achieved by the control sequences +\bitem \cs{N}, \cs{E}, \cs{S}, \cs{W} mean draw north, east, south and west, + similar for \cs{NE}, \cs{SE}, \cs{SW}, and \cs{NW} +\bitem \cs{whiteN}, \cs{whiteE}, \cs{whiteS}, \cs{whiteW} mean + {\em white}-draw north, east, south and west, i.e., the turtle just moves.\ftn{The + halfwinds can be composed from the winds in this case.} +\smallbreak + +\blueexample Spiral + +To get the flavour another classical picture, which shows +that we don't have to worry about coordinates. +$$\spiralpic$$ +The spiral is marked up essentially as follows\ftn{For the + placement within context details + consult \cs{spiralpic} in pic.dat.} +\beginverbatim +\unitlength.5ex \k30 +\loop\E{\the\k}\advance\k-1 + \S{\the\k}\advance\k-1 + \W{\the\k}\advance\k-1 + \N{\the\k}\advance\k-1 +\ifnum\k>4 \repeat +!endverbatim +\vskip-\medskipamount +\bluehead Basics + +Essential for the understanding is familiarity with \TeX's +{\em boxes of size zero}, to know the effect of \cs{kern}-s and +\cs{h/vss}-s inside, and of combinations of these boxes. +Before reading on peruse the following. + +\bluesubhead Kerns and stretchorshrink-s + +within boxes of size zero. + +\blueexample With and without boxes of size zero + +\beginverbatim +\newdimen\x \x=4ex \newdimen\y \y=2ex +.\hbox to 0pt{\kern\x a\hss}. +\kern10ex and \kern10ex +.\kern\x a. + +and + +.\hbox to0pt{\kern\x\vbox to0pt + {\vss\hbox{a}\kern\y}\hss}. +\kern10ex and \kern10ex +.\kern\x\raise\y\hbox{a}. +!endverbatim +with result +%\newdimen\x \newdimen\y +\bgroup +\x4ex \y2ex +$$.\hbox to0pt{\kern\x a\hss}. +\kern10ex and \kern10ex +.\kern\x a.$$ +and +$$.\hbox to0pt{\kern\x\vbox to0pt + {\vss\hbox{a}\kern\y}\hss}. +\kern10ex and \kern10ex +.\kern\x\raise\y\hbox{a}.$$ +\egroup +By this mechanism we can move to +any point on the page and put there what we wish. +The essential issue of the box of zero width is that +the {\em reference point is left invariant.} +It is the same before and after. + +\bluesubhead Putting it together + +In vertical mode the \cs{hbox}-es are aligned on the reference point, and +when the heights and depths are zero the \cs{hbox}-es overprint, +and the order of specification is immaterial. + +In (restricted) horizontal mode \cs{hbox}-es of width zero overprint +and can be given in any order, \TB{} {\oldstyle389}. + +In math mode the zero size boxes overprint. +In display math the invariant reference point is centered horizontally. + +Coding in \TeX{} simple? Forget it! +So unusual, but \dots con\-sequent, utmost consequent, sigh. + +\bluesubhead Coding flashbacks + +The codes which follow are the fifth or so version. +The zeroeth version was there to please me, excited me. +Recursive programming worked as I expected. +Then I had a version which served to try out as many examples as I could think of. +During the process of collecting examples I strove after consistency of the codes. +Why did I use integer arithmetic anyway? +I had no good reason and I decided to +use dimensions and do the arithmetic through the dimensions, +and widened en-passant the allowed arguments of the winds and +halfwinds to expand to `factor'-s. + +And what about the context? + +It seemed necessary to abstract from the multitude of boxes and to come up with +an enveloping hbox of width zero. + +Finally, details were taken care of, such as how do the macros behave in the various +contexts. +Do the winds and halfwinds behave the same? +It turned out that they did not. So I had to go back from where I started. +I considered the early versions as prototypes and started +anew guided by specs, +with simplicity and robustness as yardsticks, +stating precisely how the elements should behave. +By all means no sinecure, but IMHO with all respect, +a must in software engineering.\ftn{In fact I had this article nearly finished + when I realized that the vertical rules induce a vbox of the size of the + rules, while other directions when boxed yielded a box of size zero. + Not nice and confusing, although for the article and in my hands it was ok. + Nevertheless, I decided to go for a uniform approach. When boxed the dimensions + of the box should be zero.} +Indeed, a superficially, simple problem. + +Is that all? Essentially yes, but \dots details matter. + +\bluehead The winds and halfwinds + +The intuitive idea is to compose lines out of elements, from what I call atoms. +I used squares, casu quo rectangles, as atoms, and +stacked these as follows.\ftn{In order to make it visible + \cs{linethickness} has been set to 1ex. Experiments with bullets and \LaTeX's line fonts + did not yield the pleasing exact results.} + +Essential is how lines leave a mathematical point. +The accompanying model picture is obtained through the following macros. +\beginverbatim +\let\0\N \let\1\NE \let\2\E \let\3\SE +\let\4\S \let\5\SW \let\6\W \let\7\NW +\linethickness1ex +\setbox\hlfwndelm=\hbox{\vrule + width\the\linethickness + height\the\linethickness depth0pt} +\unitlength10ex +\def\draw{\csname\the\dir\endcsname1} +$$\loop\ifnum\dir<8{\draw}\advance\dir1\repeat$$ +!endverbatim + +\thispicture{\linethickness1ex} +$$\windpic$$ +Remarks. \cs{N} etc.\ draw in the implied directions with length of the argument +and \cs{unitlength} as scaling. + + + + +\bluehead Pondering aloud + +Can we attain compatibility with \TeX's rules primitives? +I don't think so, alas. On the other hand we have to +reconsider the leaving of the rules from a point. + +\bluesubhead Thickness + +What is meant by thickness if we stack instead of tile? +What is the perceived blackness? + +I presumed that stacking with square elements +of size \cs{linethickness}${\times}$\cs{linethickness}\Dash + like in the example figure\Dash +yields the same blackness as a rule of thickness \cs{linethickness}.\ftn{I also + supplied macros\Dash tiled variants\Dash for \cs{NW} and \cs{NE}.} + +\bluesubhead Size + +Usually the size along the x-axis must be provided. +I prefer to have the real size specified independently from the orientation +of the line. +However, the resulting size is not necessarily \#1${\times}$\cs{unitlength}.\ftn{To put + it in another way: the required length must be a multiple of the atom size.} +In general the result differs at most by half the atom size, +because it is composed of a multiple of the atomic element. +We have to correct by $\sqrt2$ to compensate for the direction, when we +pace along one of the axes. +In the example the required length is {\oldstyle10}ex, +with as result the stacking of {\oldstyle7} atoms of size {\oldstyle1}ex. + +For large lines one could think of combining \LaTeX's line{\oldstyle10} +line elements with the smaller elements. +I refrained from that for two reasons. +Firstly, the \LaTeX's NW line element\Dash the |\char'145|\Dash +did not fit exactly in the box, and +secondly, the inflexibility of the thickness of the font elements. + +\bluehead Design specs + +With awareness of the above I specified the following for the +microscopic level\Dash the wind and halfwind commands proper\Dash +and for the macroscopic level\Dash the placement within context. + +\bluesubhead Microscopics + +The functionality is +to draw a line of the specified length in the direction as implied by the +control sequence name. +The general specifications read as follows. +\bitem as argument a `factor' is expected, to yield the required length + \#1${\times}$\cs{unitlength}\ftn{The idea is that not only integer values + can be specified but also decimal fractions.} +\bitem parameterization is by \cs{linethickness} +\bitem after drawing, the position of the turtle is at the end of each line, + the reference point has been left invariant, and all + the boxes have zero width, height and depth. +\smallbreak +Extra for the four halfwinds the following. +\bitem parameterization is by \cs{hlfwndelm} and \cs{linethickness} + in there +\bitem draw a line of $\approx$ the specified size +\bitem the atoms are stacked diagonally, at the corners. +\smallbreak + +\bluesubhead Macroscopics + +The placement within context is the concern of the user. +Because of the zero dimensions of the boxes it is a nuisance +to skip or kern when using a picture to create the open space, +the niche for the picture. +Moreover, when the picture does not take dimensions we are in trouble +at page breaks. Therefore assistance is badly needed. +The picture environment idea combined with +databases come to rescue. +The {\it use\/} of prefab pictures has been simplified in this way, +while there is flexibility via \cs{thispicture} to override the defaults. + +Pictures can be stored in BLUe's format pic.dat database. +Within each database element the default placement within context can be povided for. +Through the use of \cs{everypicture} and/or \cs{thispicture} the defaults can be +overriden. +This approach complies with the general principles adopted in BLUe's format system. + +\bluehead Coding the winds and halfwinds + +In the fourth version, where emphasis was put on that all boxes have zero dimensions, +I also decided to separate to get at the (x, y) position from what is put there. +This is much in the spirit of the second \cs{point} macro of \TB{} {\oldstyle389}, and +adheres to the {\it separation of concerns\/} adage.\ftn{IMHO it makes the code more + trustworthy and circumvents pitfalls. + Especially, the mixing up of the kerns needed to get at (x, y) + with the kerns to position what has to be put at (x, y).} + +The dimension variables \cs{x} and \cs{y} have after completion the values +of the coordinates of the end of the line. +\beginverbatim +\newbox\hlfwndelm +\newdimen\linethickness \linethickness1ex%.2pt +\newdimen\auxdim %linesize +% +\def\xy#1{%Function: place #1 at x, y + \vbox to0pt{\kern-\y + \hbox to0pt{\kern\x#1\hss}\vss}} +% +\def\xytxt#1{%Function: place text #1 at x, y + \xy{\vbox to0pt{\vss + \hbox to0pt{\strut#1\hss}\kern0pt}}} +% +\def\N#1{\xy{\kern-.5\linethickness + \vbox to0pt{\vss + \hrule height#1\unitlength + width\linethickness}}% +\advance\y#1\unitlength} +% +\def\S#1{\advance\y-#1\unitlength{\N{#1}}} +% +\def\E#1{\xy{\vbox to0pt{\vss + \hrule width#1\unitlength + height\linethickness + depth0pt\vss +}}\advance\x#1\unitlength} +% +\def\W#1{\advance\x-#1\unitlength{\E{#1}}} +% +\def\NE#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-\wd\hlfwndelm +\ifdim\auxdim>-.5\wd\hlfwndelm + \xy{\vbox to0pt{\vss\copy\hlfwndelm}}% + \advance\x\wd\hlfwndelm + \advance\y\ht\hlfwndelm +\repeat} +% +\def\NW#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-\wd\hlfwndelm +\ifdim\auxdim>-.5\wd\hlfwndelm + \advance\x-\wd\hlfwndelm + \xy{\vbox to0pt{\vss\copy\hlfwndelm}}% + \advance\y\ht\hlfwndelm +\repeat} +% +\def\SW#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-\wd\hlfwndelm +\ifdim\auxdim>-.5\wd\hlfwndelm + \advance\x-\wd\hlfwndelm + \advance\y-\ht\hlfwndelm + \xy{\vbox to0pt{\vss\copy\hlfwndelm}}% +\repeat} +% +\def\SE#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-\wd\hlfwndelm +\ifdim\auxdim>-.5\wd\hlfwndelm + \advance\y-\ht\hlfwndelm + \xy{\vbox to0pt{\vss\copy\hlfwndelm}}% + \advance\x\wd\hlfwndelm +\repeat} +%For \NE and \NW the titled variants read +\def\NE#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-.5\wd\hlfwndelm +\ifdim\auxdim>-.25\wd\hlfwndelm + \xy{\vbox to0pt{\vss\copy\hlfwndelm}}% + \advance\x.5\wd\hlfwndelm + \advance\y.5\ht\hlfwndelm +\repeat} +% +\def\NW#1{\auxdim#1\unitlength\correction +\loop\advance\auxdim-.5\wd\hlfwndelm +\ifdim\auxdim>-.25\wd\hlfwndelm + \xy{\vbox to0pt{\vss + \llap{\copy\hlfwndelm}}}% + \advance\x-.5\wd\hlfwndelm + \advance\y.5\ht\hlfwndelm +\repeat} +!endverbatim + +\bluehead Coding a database element + +As promised in the Macroscopics section the visibility of the picture\Dash + that is the size\Dash +has to be added when the picture is stored in the database for (re)use. +In order to do so I added two extra layers. +The structure of a pic.dat database element, and +a picture environment on top of for example +gkp's environment to allow user flexibility. + +If we assume that the picture +proper has been created within gkp's +\beginverbatim +\def\gkpbeginpicture(#1,#2)(#3,#4)% +%#1, #2 xsize, ysize (dimensionless) +%#3, #4 xshift, yshift (dimensionless) +{...} +\def\gkpendpicture{...} +!endverbatim +then the flexibility layer reads +\thispicture{\emc} +\beginverbatim +\def\beginpicture{\bgroup + \the\everypicture\the\thispicture + \gkpbeginpicture(\the\xdim,\the\ydim)% + (\the\xoffset,\the\yoffset)% + } +\def\endpicture{...} +!endverbatim +A pic.dat database entry consists of a quadruple: +\cs{lst} list element tag, +\cs{pic} the name, +a group with defaults,\ftn{Demarcated by explicit braces.} and +the picture proper enclosed by +\cs{beginpicture} and \cs{endpicture}. +\beginverbatim +\lst\pic{} +\beginpicture + +\endpicture +!endverbatim + +\blueexample Coding the database element bintreepic + +The \cs{bintreepic} element of the pic.dat database reads as follows.\ftn{Note + that there is much flexibilty here. Also the \cs{bintree} macros can be + reused as such. \cs{bintreepic} comes down to an invoke of this macro + with some flexibilty added.} +\beginverbatim +\lst\bintreepic{\bgroup + \unitlength.5ex\kk32 + \xoffset{-32} \yoffset{-2}% + \xdim{66}\ydim{5}% + \def\eertnib##1\bintree{\fi} +\beginpicture\bintree\endpicture\egroup} +%with in the kernel blue.tex +\def\bintree{\S1\ifnum\kk=2 \eertnib\fi + \divide\kk2 {\W{\the\kk}\bintree}% + \E{\the\kk}\bintree} +%and accounting for the leaves +\def\eertnib#1\bintree{\fi\global\advance\k1 + \whiteS1\xytxt{ \csname\the\k\endcsname}} +!endverbatim + +\bluehead Coding recursion + +Long I believed that tail recursion\Dash as used for example in the +\cs{loop} \dots \cs{repeat}\Dash is not sufficient. We also have +to cope with `Ackermann-like splittings' of the recursion. +For the case of the Pythagorean tree for example, this means that at each recursion +level we have to take care of the left branch and the right branch, i.e.\ two invocations +must be done. +This interferes with how to handle the termination of the recursion. +A problem? \TeX{} too difficult? +Hang on there are at least two elegant and general solutions. + +\bluesubhead Recursion termination + +\blueexample $n$! + +As pedagogical example the calculation of $n$! +\beginverbatim +\n=... %counter var +\nfac=1 %default +\def\fac{\ifnum\n=1 \caf\fi + \multiply\nfac\n \advance\n-1 \fac} +\def\caf#1\fac{\fi} +!endverbatim +The termination is obtained because \cs{fac} is used as end terminator +in the definition of \cs{caf}. \cs{fac} is implicitly gobbled, and +the process backtracks, resulting finally in termination. + +\blueexample Pythagorean tree + +Without explanation the Pythagorean tree recursive macro +is given below.\ftn +{Hopefully, it is self-explanatory, at least + with respect to the main flow. By the way in what order + is the tree drawn?} +At each level we have two invocations\Dash the branching\Dash +to take care of the left and right branch. +\beginverbatim +\def\pythtree{\ifnum\level=1 \eerthtyp\fi + \advance\level-1 + \multiply\kk23\divide\kk32%\sqrt2 + {\leftbranch\draw\pythtree}% + \rightbranch\draw\pythtree} +\def\eerthtyp#1\pythtree{\fi} +!endverbatim +No build up of \cs{fi}-s, no use of \cs{expandafter} nor \cs{let}. +The \cs{let} mechanism has been used throughout in \TB. + +\bluesubhead A la Knuth + +In the coding of \cs{squine}\Dash a quadratic spline\Dash +Knuth showed how to terminate (tail) recursions in \TeX. +For \cs{fac} this results in the following. +\beginverbatim +\def\fac{\ifnum\n>1 \expandafter\dofac\fi} +\def\dofac{\multiply\nfac\n + \advance\n-1 \fac} +!endverbatim + +For the Pythagorean tree the result reads as follows. +\beginverbatim +\def\pythtree{\ifnum\level>1 + \expandafter\dopyth\fi} +\def\dopyth{\advance\level-1 + \multiply\kk23\divide\kk32 + {\leftbranch\draw\pythtree}% + \rightbranch\draw\pythtree} +!endverbatim +Earlier I noticed the elegance of introducing an extra level, especially +to circumvent too many \cs{expandafter}-s in a row. + +As an aside the use reads +\beginverbatim +\let\0\N \let\1\NE \let\2\E \let\3\SE +\let\4\S \let\5\SW \let\6\W \let\7\NW +\def\leftbranch{\advance\dir7 + \ifnum\dir>7 \advance\dir-8 \fi}%mod 8 +\def\rightbranch{\advance\dir1 + \ifnum\dir>7 \advance\dir-8 \fi}%mod 8 +\def\draw{\csname\the\dir\endcsname{\the\kk}} +\def\pythtree{\ifnum\level>1 + \expandafter\dopyth\fi} +\def\dopyth{\advance\level-1 + \multiply\kk23\divide\kk32 + {\leftbranch\draw\pythtree}% + \rightbranch\draw\pythtree} +$$\unitlength0.1pt\kk128 %Size + \level5%Order + \N{\the\kk} %Trunk + \pythtree$$ +\tracingstats1 +\bye +!endverbatim + +\bluehead Trinaries + +For {\oldstyle45}$^\circ$ lines I used square elements. +Why not use a rectangular element for {\oldstyle30}$^\circ$ lines +in conformance to the direction? + +{\catcode`\^=7 \blueexample Lines at {\oldstyle30}$^\circ$ + +} +$$\trimodelpic$$ +This model is obtained by +\beginverbatim +$$\x0pt\y0pt + {\N{10}}{\ESE{10}}{\WSW{10}}$$ +%with initializations +\linethickness1ex +\setbox\trielm=\hbox{\vrule + width1.74\linethickness + height\linethickness\relax} +%To account for element in 30 degrees direction +\unitlengthy\ht\trielm %default.2pt +\unitlengthx\wd\trielm %default.3482pt +\unitlength\unitlengthy%default.2pt +%and the macros +\def\WSW#1{\auxdim#1\unitlength\divide\auxdim2 + \loop\advance\auxdim-\unitlengthy + \ifdim\auxdim>-.5\unitlengthy + \advance\x-\unitlengthx + \advance\y-\unitlengthy + \xy{\vbox to0pt{\vss\copy\trielm}}% + \repeat} +% +\def\ESE#1{\auxdim#1\unitlength\divide\auxdim2 + \loop\advance\auxdim-\unitlengthy + \ifdim\auxdim>-.5\unitlengthy + \advance\y-\unitlengthy + \xy{\vbox to0pt{\vss\copy\trielm}}% + \advance\x\unitlengthx + \repeat} +!endverbatim + +\blueexample Trinary tree + +$$\N{128}\tritreepic$$ +\beginverbatim +$$\x0pt\y0pt\level6 \kk128\N{128}\tritree$$ +%with trinary tree macro +\def\tritree{\ifnum1=\level \eertirt\fi + \advance\level-1 \divide\kk2 + {\N{\the\kk}\tritree}% + {\ESE{\the\kk}\tritree}% + \WSW{\the\kk}\tritree} +\def\eertirt#1\tritree{\fi} +!endverbatim +Remark. The \cs{unitlength}-s are default + equal to the sides of the elementary rectangular block. + The size of the tree can be controlled by \cs{kk}. + +\bluehead Epilogue + +The lines at {\oldstyle45}$^\circ$ have little compatibility +with \TeX's rules, alas, especially with non-neglible thickness. +I was surprised to realize that \TeX's defaults for rules are +not symmetric around their axes in relation to the reference point. +\medskip\noindent +Have fun, and all the best. + +\makesignature\let\makesignature\relax + +\bluehead Appendix: Binary tree and chart + +\blueexample Binary tree + +\beginverbatim +\bluepictures\bintreepic\par +$$\bintreepic$$ +!endverbatim +with result +$$\bintreepic$$ + +How can we add leaves\ftn{See the PWT user guide for the answer.}? + +\bluesubhead Rotated tree + +Once we understand turtle graphics, rotating a tree can be done easily +by shifting the meaning of the directions, and adjusting the +positioning of the leaves.\ftn{A white lie. The tree is actually mirrored + because I like the leaves to be numbered from the top. + In general we can rotate via \PS.} + +\blueexample Rotated tree + +\begindemo +\thispicture{\def\1{cgl} + \def\2{PWT}\def\3{July} + \def\4{1995}\def\5{\dots} + \yoffset{-16}\ydim{28}} +$$\rotatedbintreepic$$ +!yields +\thispicture{\def\1{cgl}\def\2{PWT} + \def\3{July}\def\4{1995} + \def\5{\dots}\def\6{}\def\7{} + \yoffset{-16}\ydim{28}} +$$\rotatedbintreepic$$ +\enddemo +\cs{bintree} and \cs{eertnib} come with blue.tex, and +\cs{rotatedtreepic} is included in pic.dat. +The \cs{rotatedtreepic} entry reads as follows. +\beginverbatim +\lst\rotatedbintreepic{%July 1995, cgl +\bgroup\unitlength1ex% + \let\W\N \let\exchange\E + \let\E\S \let\S\exchange + \def\1{x}\def\2{y}\def\3{a}\def\4{b}% + \def\5{piet}\def\6{hans}\def\7{etc.}% + \k0\kk16\xdim{10}\ydim{30}% +\beginpicture\bintree\endpicture\egroup +\thispicture{}} +!endverbatim + +\bluesubhead Chart + +Through the \cs{bintree} macro we can also +obtain charts elegantly. + +\blueexample Chart, \TB{} ex{\oldstyle22}.{\oldstyle14} {\oldstyle248} + +$$\chartpic$$ +obtained via +\beginverbatim +%labels in preorder (default in \chartpic) +\def\1{LMB, 1912} +\def\2{MJHB, 1882}\def\5{PAME, 1884} +\def\3{JHB, 1838} \def\4{MDB, 1840} +\def\6{EFE, 1845} \def\7{CLW, 1850} +\ekk8 +\k0\unitlength2ex\x0pt\y0pt\kk8 +\hbox{\bintree} +%with auxiliaries +\let\Eold\E +\def\E{\global\advance\k1 + \xytxt{ \csname\the\k\endcsname}\Eold} +!endverbatim +Remark. An aid in finding the numbers of the branches is +to delete \cs{csname} and \cs{endcsname} in \cs{E} . +The way of traversal at hand is called preorder. + +When using \cs{chartpic} from |pic.dat| the texts along the branches +\Dash |\def\1{...} etc.|\Dash +have to be supplied within a \cs{thispicture}, +to override the defaults. +\medbreak +\makesignature +\pasteuptoc +\endscript diff --git a/info/laan/paradigm/paradigm.lps b/info/laan/paradigm/paradigm.lps new file mode 100644 index 0000000000..8f8ad6666d --- /dev/null +++ b/info/laan/paradigm/paradigm.lps @@ -0,0 +1,566 @@ +%Paradigm: Loops. Aug 1995, revised Feb 1996 +%C.G. van der laan, cgl@rc.service.rig.nl +\input blue.tex \loadtocmacros %\tolerance500\hbadness=499\hfuzz=5pt +\everyverbatim{\emc} + +\bluetitle Paradigms: Loops + +\blueissue \maps{96}2 + +\bluepictures\flowchartlooppic\pythpic + +%And to test van der Goot's variant it is supplied here +\def\loop#1\repeat{\def\body{#1}\doloop} +\def\doloop{\body\else\poolod\fi\doloop} +\def\poolod#1\doloop{\fi} +\beginscript + +\bluehead BLUe's Design VII + +Hi folks. +When you like plain's \cs{loop}-s so much as I do then this is for you. +Hang on! +\DeK's loop implements the flow, \TB{} \on219{} + +\begindemo +\def\loop#1\repeat{% + \def\body{#1}\iterate} +\def\iterate{\body + \let\next\iterate + \else\let\next\relax + \fi\next} +!yields +\flowchartlooppic +\enddemo + +with as pseudosyntax for the tags + +\cs{loop}$\langle pretst\rangle$\cs{if...}% +$\langle posttst\rangle$\cs{repeat}. + +Special cases result when either +$\langle pretst\rangle$, or +$\langle posttst\rangle$ is empty. +The former is equivalent to for example +PASCAL's {\bf while} \dots {\bf do} \dots, and the latter to +{\bf repeat}\dots {\bf until}. +From this I conclude that all those \cs{while} casu quo \cs{repeat} flavors +are not needed. +Syntactic sugar? Yes, IMHO, with all respect. + +In practice we all need repetitions either via a loop or +via tail recursion, which by the way are equivalent. +The loop notation is simpler to use than tail recursion, I guess. + +\bluehead Van der Goot's loop + +Van der Goot implemented the loop construction as a straight tail recursion. +An eye-opener! I have simplified it into the following.\ftn{The unusual in the coding + is the infinite loop. I have to unlearn much. In the old days of ALGOL \on60{} + I was taught to avoid side-effects and infinite loops of course. + With the expression language ALGOL \on68{} all storing was a side-effect. + Now with the interpretive languages it is beneficial to think in infinite loops.} + +\beginverbatim +\def\Loop#1\Pool{#1\Loop#1\Pool} +\def\Break#1\Pool{} +%a trivial example of use +\count0=10 +\Loop a \advance\count0 by-1 + \ifnum\count0=0 \expandafter\Break\fi +\Pool +\end +!endverbatim + +For more details see his Midnight suite, |loop.doc| and |loop.tex|.\ftn{Available + on the \TeX-Alive TUG CD.} + +Remark. Either \cs{expandafter} is needed or the \cs{Break} should take +\cs{fi} as replacement text. +The above with \cs{expandafter} is convenient with nesting of loops. + +\bluehead Loops in markup + +I used a loop in the markup for turtle graphics, especially for the +stochastic Sierpi\'nski carpets\Dash to throw the dice repeatedly\Dash +and for a spiral. In the markup for the spiral below +\cs{E}, \dots \cs{N} mean draw in the directions east, \dots north. + +\blueexample Spiral + +$$\vbox to3cm{\vss + \hsize0pt \offinterlineskip + \unitlength.5ex \y0pt \x0pt + \loop\N{\the\k}\advance\k+1 + \W{\the\k}\advance\k+1 + \S{\the\k}\advance\k+1 + \E{\the\k}\advance\k+1 + \ifnum\k<30 \repeat +\vss}$$ + +\thisverbatim{\unmc} +\beginverbatim +$$\vbox to3cm{\vss + \hsize0pt \offinterlineskip + \unitlength.5ex \y0pt \x0pt + \loop\N{\the\k}\advance\k+1 + \W{\the\k}\advance\k+1 + \S{\the\k}\advance\k+1 + \E{\the\k}\advance\k+1 + \ifnum\k<30 \repeat +\vss}$$ +!endverbatim + +Remark. One can also start at a corner. However, for reuse of these kinds of pictures +I consider it more convenient to start at the center of symmetry. + +Most of the time I use the tail recursion via my FIFO or (binary) +tree macros. +My favorite FIFO example is the outline exercise +\TB{} ex{\oldstyle11}.{\oldstyle5}. +I solved this via nested FIFO + processing +\item{-} words via \cs{fifow}, and +\item{-} characters via \cs{fifo}. +\smallbreak + +\blueexample Outlines + +\beginverbatim +\fifow Tough exercise \wofif \unskip. +%with +\def\fifow#1 {\ifx\wofif#1\wofif\fi + \processw{#1}\fifow} +\def\processw#1{\fifo#1 \ofif\ } +\def\process#1{\boxit#1} +\def\boxit#1{\setbox0=\hbox{#1}% + \hbox{\lower\dp0\vbox{\hrule + \hbox{\vrule\phantom#1\vrule}% + \hrule}}} +!endverbatim +\def\fifow#1 {\ifx\wofif#1\wofif\fi + \processw{#1}\fifow} +\def\processw#1{\fifo#1\ofif\ } +\def\process#1{\boxit#1} +\def\boxit#1{\setbox0=\hbox{#1}% + \hbox{\lower\dp0\vbox{\hrule + \hbox{\vrule\phantom#1\vrule}% + \hrule}}} +\qquad\qquad\qquad +\fifow Tough exercise \wofif \unskip. + +Another nice example is writing lines verbatim to a file, that is manmac's +\cs{copytoblankline} recast in FIFO terms.\ftn{See FIFO and LIFO sing the BLUes.} + +\blueexample Sorting citation lists + +Suppose, we have +\beginverbatim +\def\lst{\\\ia\\\ib\\\ic} +\def\ia{314}\def\ib{27}\def\ic{1} +!endverbatim +{%scope for \\ +\newif\ifnoe +\def\ia{314}\def\ib{27}\def\ic{1} +\def\lst{\\\ia\\\ib\\\ic} +\def\\{ } \immediate\write16{Numbers unsorted \lst} +% +\def\dblbsl#1{\ifnum#1<\min\let\min=#1\fi} +% +then sorting \cs{lst} yields +\loop\ifx\empty\lst\noefalse + \else\noetrue\fi +\ifnoe\def\\{\let\\=\dblbsl\let\min=} + \lst%find true minimum + \min%typeset minimum + {\def\\##1{\ifx\min##1\else + \noexpand\\\noexpand##1\fi}% + \xdef\lst{\lst}}%delete minimum +\repeat. +}%end scope for \\ + +The above is obtained as follows. + +\thisverbatim{\unmc} +\beginverbatim +\def\dblbsl#1{\ifnum#1<\min\let\min=#1\fi} +% +\Loop\ifx\empty\lst\expandafter\break\fi + \def\\{\let\\=\dblbsl\let\min=} %space + \lst%find minimum + \min%typeset minimum + {\def\\#1{\ifx#1\min \else\nx\\% + \nx#1\fi}\xdef\lst{\lst}}% +\Pool +%with auxiliaries +\def\Loop#1\Pool{#1\Loop#1\Pool} +\def\break#1\Pool{} +!endverbatim + +The coding implements the looping of the basic steps +\item- find minimum (via \cs{lst}, + and suitable definition of \DeK's active list separator |\\|) +\item- typeset minimum (via \cs{min}) +\item- delete minimum from the list (via another appropriate + definition of the list element tag). +\smallbreak + +Remarks. +\cs{dblbsl} is mnemonics for double backslash. +The deletion of elements from the list works with \cs{ifx}. +The variant with \cs{ifnum} does not work as such (!) +because a \cs{relax} is inserted by \TeX.\ftn +{The \cs{relax} can be suppressed by inserting an unexpandable token + like \cs{noexpand} \cs{empty}. Courtesy Bernd Raichle.} + +The problem occurred in sorting citation lists of bibliography references +which are specified by their symbolic names.\ftn +{In BLUe's bibliography I have explained how to circumvent + the sorting of citation lists of references.} + +\blueexample Reading a file line by line + +\beginverbatim +\Loop\ifeof\readfile\Break\fi + \read\readfile to\inputline + +\Pool +%with auxiliary +\def\Break#1\Pool{\fi} +!endverbatim + +This use occurred in the Convertor Assistant BLUe-2-\LaTeX, +well \dots it is the main loop. + +\bluesubhead Relevancy + +From my experience as exemplified above, +I conclude that loops are mainly of interest for macro writers and +not so much for the casual \AllTeX{} user. + +\bluehead Macro writers attention + +Knuth's loop does not allow for the use of \cs{else} in the exit code +because it is already part of the macro \cs{loop}. +Kabelschacht \on1987\Dash and Spivak \on1989\Dash needed the use of \cs{else}. + +\blueexample Kabelschacht's loop + +Kabelschacht removed the \cs{else} from the loop code as follows. + +\beginverbatim +\def\loop#1\repeat{\def\iterate{#1\ea + \iterate\fi}\iterate} +%a trivial example of use +\count0=10 +\loop\advance\count0 by-1 + \ifnum\count0=0 + \else do what has to be done +\repeat +!endverbatim + +Remarks. +The exit is via the then-branche in contrast with Knuth's loop. +Suppressed are some efficiency aspects with respect to storage. +Kabelschacht's claim that his +loop is a {\em generalization\/} of plain's loop must be seen +in the light of not being restricted to quit a loop via the else-branch. + +The reason, I can think of, +for introducing another loop macro, while the most +general form has been implemented already, +is the existence of commands like \cs{ifvoid}, and \cs{ifeof}, and +the absence of their negatives \cs{ifnonvoid}, respectively \cs{ifnoneof}. +In those cases we like to continue the loop via the \cs{else} branch. +For the latter case this means to continue +the loop when the file is {\em not\/} ended. +This can be obtained via modifying the loop \`a la Kabelschacht or more elegantly +via van der Goot's macro. + +Another approach is to use a \cs{newif} parameter, +better known as `boolean' or `logical' in other programming languages, +together with Knuth's loop. +A \cs{newif} parameter, \cs{ifneof}, +can be used to test for an end of file or casu quo, an end of a list. + +\beginverbatim +\ifx\lst\empty\neofalse\else\noetrue\fi\ifneo +!endverbatim + +\blueexample Reading a list via Knuth's loop + +\beginverbatim +\newif\ifneo +\def\lst{a b c}\neotrue +\loop\ifx\lst\empty\neofalse\fi + \ifneo \def\lst{} +\repeat +!endverbatim + +Related to the above coding of the logical $\neg$, are the codings +of the logical and, $\wedge$, and or, $\vee$, via + +$$\vbox{\offinterlineskip\halign{#\enspace\hfil\vrule&\enspace#\hfil\strut\cr +\strut Functional code&\TeX\ coding\cr +\noalign{\hrule} +$\neg$|\if...| + &|\if...\notfalse\else|\cr + &|\nottrue\fi\ifnot|\cr +|\if...|$\wedge$|\if...| + &|\andtrue\if...\if...| \cr + &|\else\andfalse| \cr + &|\else\andfalse\fi\fi| \cr + &|\ifand| \cr +|\if...|$\vee$|\if...| + &|\ortrue| \cr + &|\if...\else\if...\else| \cr + &|\orfalse\fi\fi \ifor| \cr + &|%alternative| \cr + &|\orfalse| \cr + &|\if...\ortrue\fi| \cr + &|\if...\ortrue\fi| \cr + &|\ifor| \cr +}}$$ +with the \cs{newif}-s: \cs{ifnot}, \cs{ifand}, and \cs{ifor}.\ftn +{By the way, now I have you on the line about Booleans, + did you ever understand the macro \cs{newif}? + If not let me tell you that \cs{global} |\true| and its false + counterpart make sense, but \cs{global} \cs{newif} |\if| does not. + \TeX{} {\em does not\/} complain but the `allocation' remains non-global. + A bit inconsistent with the global allocations of other data like + counters\smiley.} + + +\bluehead Nesting of loops + +My favorite example of nesting of loops is the bubble sort.\ftn{\cs{cmp} + stands for comparison. \cs{xch} stands for exchange. + For a pseudocode see Paradigms: Sorting.} + +\thisverbatim{\unmc} +\beginverbatim +\def\bubblesort{%Data in defs \1, \2,...\. +{\loop\ifnum1<\n{\k\n + \loop\ifnum1<\k \advance\k-1 + \cmp{\deref\k}{\deref\n}% + \ifnum1=\status\xch\k\n\fi + \repeat}\advance\n-1 + \repeat}}%end \bubblesort +%with auxiliary +\def\deref#1{\csname\the#1\endcsname} +\let\cmp\cmpn %from blue.tex or provide +%\def\cmp#1#2{%Yields +% status=0, 1, 2 for =, >, < +%{...} +!endverbatim + +\bluesubhead Inconsistency pitfall + +I experience the non-expansion of a counter variable\Dash + or the non-dereference of it as you wish\Dash +within a \cs{csname} counter-intuitive. +The counter must be preceded by \cs{the}, see \cs{deref}. +I understand the difference with the situation +that a value might be assigned but in this constructs this is out of order. + +Another nesting of `loops' is in the earlier mentioned linear sorting fo citation lists, +where the inner loop is the \cs{xdef}. + +\bluesubhead Braces around inner loops are mandatory + +Pittman argued that there is a need for other loop codings. +\beginquote +`Recently, I encountered an application that required a set of nested loops +and local-only assignments and definitions. +\TeX's \cs{loop} \dots \cs{repeat} con\-struc\-tion proved to be +inadequate because of the requirement +that the inner loop be grouped.' +\endquote +In `Syntactic Sugar' I have shown that his problem can be solved +from a table point of view.\ftn{It is also in the tables chapter of PWT.} + +However, Pittman was definitely right with respect to bracing the inner loop, +because of the parameter separator \cs{repeat}. +If braces are omitted, the first \cs{repeat} is mistaken for the outer one, +with the result that the text of the outer loop will +{\em not\/} become the first \cs{body}. +The good way is, to make the inner \cs{repeat} invisible for the +outer loop level, by enclosing the inner loop in braces. + +With non-explicit nesting\Dash for example the inner loop is the +replacement text of a macro\Dash we still need scope braces, +because otherwise the \cs{body} of the outer loop +will be silently redefined by the body of the inner loop. + +\bluesubhead Dialogue with \TeX + +Nestings of loops occur when in dialogue with \TeX{} only certain answers +are allowed. + +\blueexample Checking user input + +\beginverbatim +%Insist on allowed answers only +\def\iw{\immediate\write0} +\def\readyesornotoanswer{{% + \def\yes{yes}\def\no{no} + \Loop\iw{Please provide yes or no:} + \read-1 to\answer + \ifx\answer\yes\ea\Break\fi + \ifx\answer\no \ea\Break\fi + \Pool\xdef\answer{\answer}}} +% +\let\yes\Break\let\no\relax +\endlinechar-1 %TB20.18 +\Loop\message{Are you happy? } + \readyesornotoanswer + \ea\csname\answer\endcsname + \iw{Too bad, I insist...} +\Pool +\bye +!endverbatim +Remarks. The \cs{xdef} makes the answer globally available. +En-passant a little `switch functionality in \TeX' is realized via \cs{csname}. + +\bluehead Hidden counter + +I like a hidden counter very much.\ftn{As in ALGOL \on68{}, METAFONT/MetaPost, or PostScript.} +In \TeX{} we don't have a garbage collector and therefore +there is no gains in storage. However, to alleviate +the user from the details of the allocation of +storage of the counter I provided the following.\ftn{Bernd Raichle has implemented local + storage allocation macros. Although I can see the benefits of his robust approach especially + together with push-the-button packages like \LaTeX, I refrained from it, because + for my applications I know that the bounds\Dash only {\oldstyle 256} locations are + available\Dash are not severe. Moreover, intelligibility is hampered, and I like to add + just a little to \TeX, as little as possible.} +\beginverbatim +\def\preloop{%To create loopcnt, a + %local loopcounter + \bgroup \advance\count10 by 1 + \countdef\loopcnt=\count10 + %Symbolic name + \loopcnt=1 %(default) + }%end \preloop +\def\postloop{\loopcnt=0 %Restore + \egroup}%end \postloop +!endverbatim + +I used the above in the coding of the Tower of Hanoi game. +The paradigm in there is that it is used together with \cs{aftergroup}\Dash shortcut \cs{ag}\Dash +to create {\em dynamically\/} a data structure, i.e.\ the tower of which the size is specified +by the user. +\thisverbatim{\unmc} +\beginverbatim +% \def\I{\disksep\i\disksep\ii +% \disksep\iii...\disksep\`n'} +%next to the defs for \i,\ii,...\`n'. +\preloop\ag\def\ag\I\ag{% + \loop + \ea\xdef\csname\romannumeral\loopcnt + \endcsname{\the\loopcnt} + \ag\disksep\ea\ag\csname + \romannumeral\loopcnt\endcsname + \ifnum\loopcnt<\n + \advance\loopcnt by1 + \repeat \ag} +\postloop +!endverbatim +Note that \cs{disksep} is \DeK's active list separator, which I use abundantly in macro writing. +I call it the list element tag, because it is also needed before the first element.\ftn{I use + them also with more than one argument, + especially in selective loading of entries from a database. + The above construction of a list is also used in my test example for sorting random + words. Each character is obtained randomly and placed after the loop to form words of + random length. Neat.} + +\bluehead Flip-flop traversal + +In programming it occurs that loops are traversed with the first +traversal different from the others. In practice I needed\Dash + well, it was more elegant\Dash +in a play to handle only one player in each traversal but toggle the players: +player, opponent, player, opponent, etc. +\def\data{+\cs o\cs+\rs \cs o\cs+\rs o\cs \cs +} +$$\ruled\btable\data$$ +The play at hand was tic-tac-toe, and the prototype implementation +which demonstrates the toggling reads as follows. +\beginverbatim +\def\play{\initialize +\loop\showboard + \ifx\mark\markplayer\let\mark\markopponent + \else\let\mark\markplayer + \fi\iw{Supply index for \mark:} + \read0to\index + \ea\xdef\csname\index\endcsname{\mark} +\ifnum\index>0 +\repeat} +\def\markplayer{+}\def\markopponent{o} +\endlinechar-1 %TB20.18 +\play \bye +%with auxiliaries +%(\iw is shortcut for \immediate\write0) +\def\showboard{\iw{\1\2\3}...\iw{\7\8\9}} +\def\initialize{\def\1{-}...\def\9{-}} +!endverbatim + +In a general sense I need often in a repetitive situation to do something different +at the beginning or at the end. Examples are my implementation of +\item-\cs{nitem}\Dash +numbered item and ilks +\item-to suppress the first headline of a chapter, and +\item-the |\\| in the linear sorting at the beginning. + +\bluehead Trees + +Another intriguing repetitive or tail-recursive situation occurs when +coding trees in \TeX.\ftn{Well also in METAFONT and PostScript.} +For fun\Dash though the undertone is serious\Dash +I have added a tree from the Pythagorean family, borrowed from |pic.dat|. + +$$\thispicture{\level6 \ydim{70}}\pythpic$$ + +The essence of the implementation in \TeX{} of the repetition is shown below. +For the full coding consult |pic.dat|. +\beginverbatim +\let\drawsq\ldrawsq %left drawing square +\def\pyth{\ifnum\level=1 \htyp\fi + \drawsq\advance\level-1 + \multiply\kk18\divide\kk25 + {\turn7\x\leftx \y\lefty + \let\drawsq\ldrawsq\pyth}% + \turn1\x\rightx \y\righty + \let\drawsq\rdrawsq\pyth} +\def\htyp##1\pyth{\fi} +!endverbatim +\cs{turn} turns over a multiple of {\oldstyle45}$^\circ$. +(\cs{leftx}, \cs{lefty}) and (\cs{rightx}, \cs{righty}) +contain the coordinates to start drawing a left square and +a right square, respectively. + +\bluehead Conclusion + +Many slightly different codings for a loop are around. +This contributes to the reasons why understanding macro collections is so hard. +It is so easy to come up with a variant, inhibiting intelligibility and trustworthyness. + +I consider van der Goot's loop the simplest and most general, +though Knuth's loop is usually sufficient for me. + +\bluehead Looking back + +It is fun to flashback at for example Child's \TeX{} Selftest, \on1989, +and to conclude that much of the perceived important \TeX ing nitty-gritties +is not needed\Dash not to mention all those essential issues which are lacking\Dash +when developing something like BLUe's format system. + +This is precisely the reason why I pay so much attention to flashbacks, +to summarize the paradigms, to bring to light what is needed in practical work, +in such a way that the essence can be reused easily. +Towards a discipline of \TeX ing. +My case rest. +\medbreak +Have fun, and all the best +\makesignature +\pasteuptoc +\endscript \ No newline at end of file diff --git a/info/laan/paradigm/paradigm.opt b/info/laan/paradigm/paradigm.opt new file mode 100644 index 0000000000..e44d9d414f --- /dev/null +++ b/info/laan/paradigm/paradigm.opt @@ -0,0 +1,463 @@ +%November 1994, March 1996. +%Paradigm: Parameterization---Options +%C.G. van der laan, cgl@rc.service.rug.nl +\input blue.tex \loadtocmacros +\tolerance500\hbadness=499\hfuzz=9pt +\parindent=1pc + +\everyverbatim{\emc} + +\bluetitle Paradigms: Parameterization I + +\bluesubtitle Options + +\blueissue \maps{95}1 + +\beginscript + +\bluehead BLUe's Design IV + +Hi folks. Much parameterization in \TeX{} has already been +taken care of via the various modes of \TeX, that is by the states +script elements can be processed in. +How ingenious and handy that may be, it is not sufficient. + +Knuth also provided switching commands for fonts, formats and +language.\ftn{For example \cs{eightpoint}, \cs{report} (well in + \bluetex), + and \cs{language1}. Similar to the font switching macros I used + \cs{english}, \cs{dutch} and the like, to activate all + language dependent parameters for typesetting bridge + with the right words. Early \LaTeX{} had several + words `hardwired' in the code in English. + The latter was the reason for Johannes Braams to give birth + to Babel, to parameterize and concentrate language specific + issues, and to allow easy switching + from one language to another.} + +Then there are the various parameters\Dash integer, dimen, +glue, muglue\Dash as listed in \TB{} \on272\dash\on274. + +Markup tags can be parameterized via (at most \on9) arguments. +However, there exist also for this purpose (global) token variables\Dash +the |\every|s\Dash with \cs{output} and \cs{errhelp} as special cases. + +To remind the reader of Knuth's \cs{every}s, I have +enumerated them below. +\beginverbatim +\everypar +\everymath, and \everydisplay +\everyhbox, and \everyvbox +\everyjob +\everycr +!endverbatim +For using them, it is important to know where the token variables are +precisely inserted.\ftn{For example, in a setbox the right-hand + side of \cs{afterassignment} + is inserted after the opening brace of the box and + followed by the tokens of |\everyh/vbox|.} + +For my taste Knuth's |\every|s +have not been appreciated as they should have been, the more so +when extended by the analogons |\this|s.\ftn{This functionality of |\this| + can be obtained via the use of |\every| within a group. However, readability + of the marked up script is served by the use of |\this|-s.} +This in contrast with the abundant use of arguments, +especially the so-called optional arguments. + +\bluesubhead Why? + +The purpose of this note is to show that +optional arguments have led to cumbersome \TeX{} coding, while +the same functionality can be attained more easily via the use of +|\this|s. +In general one can devote a monograph to markup language +parameterization, I guess. + +\bluehead Examples of use of \cs{every}s + +I inspected \TB{} for examples of use by Knuth himself. + +\bluesubhead \cs{everypar} + +An example of use is given in Appendix~D \on381, about +verbatim listings with line numbers. In \bluetex{} I enriched this +approach by allowing selective line numbering. +I mean by the latter that I can number parts, +starting with any suitable number. +This is handy when macro sets are accompanied by a table of contents +(as should always be the case), which contains references to +the line numbers of the macro set. +From \bluetex{} the following. + +\thisverbatim{\catcode`\*=0 + \catcode`\!=12 } +\beginverbatim +\def\setupverbatim{\makeactive\`% + \let\!=!\makeescape\!%Knuth&Levy + \def\par{\leavevmode\endgraf}%381 + \obeylines \uncatcodespecials + \obeyspaces} +% +\def\numvrb{\vrblin0 + \everypar{\advance\vrblin1 + \llap{\sevenrm\the\vrblin\quad}}} +% +\def\nonum{\everypar={}} +*endverbatim + +Note that the line numbers can be adjusted via modifying the counter \cs{vrblin}. + +Another example is provided on \on393, in Paragraph maneuvers. +It is about automatically inserting \cs{hangindent} and \cs{hangafter}. + +In manmac it is used in +\bitem \cs{endchapter}, as |\everypar{\sl}|, to set the quotations slanted. +\bitem \cs{beginlines}, as |\everypar{\strut}|, to insert a strut. +\smallbreak + +\bluesubsubhead A pitfall + +What is the unexpected result of + +\beginverbatim +\par%or other ending of a paragraph +{\bf New paragraph} blah blah +!endverbatim + +with |\everypar{\hang}| active\ftn{Courtesy Alan Reese}? +And why?\ftn{Courtesy Jeremy Henty.} +Note that \cs{bf} is only there to make the pitfall look realistic. + +Answer. +Without braces the text comes out as a block. With the braces at the +beginning there is no effect of the automatically inserted \cs{hang}. +The explanantion reads as follows. +When processing ordinary text, \TeX{} does not enter horizontal mode +until it encounters a letter. In the troublesome paragraph the first +letter is inside a group. When the group ends all local assignments +are undone, and the effect of the \cs{hang} instruction\Dash +the contents of \cs{everypar} is inserted within the group\Dash +is forgotten. +A solution is to precede the group by \cs{leavevmode}, +because the \cs{everypar} will be executed before the group then. + +\bluesubhead \cs{everydisplay} + +This is used in the solution of exercise \on19.\on4 to obtain non-centered displays. + +\beginverbatim +\def\leftdisplay#1$${\leftline + {\indent$\displaystyle{#1}$}$$} +\everydisplay{\leftdisplay} +!endverbatim + +This is refined in Appendix~D \on376, to allow for equation numbers as well. +In `Math into BLUes' I have worked on the Appendix~D version, and also indicated how +a single formula can be non-centered. +This is also included in \bluetex. + +\bluesubhead \cs{everyjob} + +The example is exercise \on24.\on5. +In Salomon's courseware an example is given to open automatically +files at the beginning of each \TeX{} job. + +\bluesubhead \cs{everycr} + +A practical example is given in \TB~\on140, to inhibit a page break. + +\beginverbatim +$$\everycr{\noalign{\penalty10000}} +\halign{\indent#\hfil\qquad&...\cr +If a letter is in style&then...\cr +\noalign{\vskip 2pt} +$D,D',T,T'$&text size&\cr +$S,S'$&script size&\sevenrm\cr +$\SS,\SS'$&scriptscript size& + \fiverm\cr}$$ +!endverbatim + +It is also used in plain, Appendix~B \on362, in the macro \cs{displ@y}. + +In \TB{} file I did not find examples of use of +\cs{everymath}, +\cs{everyhbox}, and +\cs{everyvbox}. + +In \bluetex{} I introduced \cs{everyscript}. +My use is to allow for more than one script to be processed, +via |\everyscript{\notlastscript}|. +I also introduced \cs{everyverbatim}, and some more. + +\head{Options via |\this|s}%Needed processing on the fly, so no \bluehead +First an example. I used it for the first time with verbatims. + +\thisverbatim{\emc\catcode`\*=0 + \catcode`\!=12 } +\beginverbatim +\thisverbatim{\emc}%enable metacode +\beginverbatim +\def\{... + ...} +!endverbatim%! is the escape character +*endverbatim + +Not only can metalinguistic variables be handled nicely +within verbatims, but also the changing of catcodes and +file verbatim inclusion go easy with the use of these token variables. + +The verbatim suite of \bluetex{} can be used with \AllTeX, because +the mechanism is simple, and not in conflict. +File verbatim inclusion goes as follows\ftn +{It is true, that I need one escape character.} + +\thisverbatim{\emc\catcode`\*=0 + \catcode`\!=12 } +\beginverbatim +\thisverbatim{\input } +\beginverbatim +Some text after the file. +!endverbatim +*endverbatim + +\bluehead The parsing of options + +Eijkhout in `\TeX{} by Topic' gives a template for coping with +optional parameters.\ftn{I adapted the macros a little.} +The work is done by \cs{OptArgCom}, with as optional +argument either the default or the one supplied. +The markup starts with \cs{Com} followed either +by a left bracket\Dash a convention to start an option\Dash +or the argument. + +\thisverbatim{\emc} +\beginverbatim +\def\Com{\futurelet\testchar\MaybeOptArgCom} +\def\MaybeOptArgCom{\ifx[\testchar + \expandafter\OptArgCom\else + \expandafter\NoOptArgCom\fi} +\def\OptArgCom[#1]#2{...} +\def\NoOptArgCom{\OptArgCom[]} +%with use +\Com[...]{...}!qquad!hbox!bgroup or!egroup!qquad\Com{...} +!endverbatim + +With the concept of \cs{thisCom} the coding template and +markup might look like the following. + +\thisverbatim{\emc} +\beginverbatim +\thisCom{} +\def\Com#1{...\the\thisCom... + \thisCom{}}%restore default +%with use +\thisCom{...}%Provides option(s), if any +\Com{...} +!endverbatim + +Explanation. +The contents of the token variable +is available to the macro. It can be virtually anything. +At the end of the macro the default is restored. +IMHO, with all respect, the latter approach is simpler +than the parsing of optional arguments. + +\bluehead Head example + +\bluetex{} allows as markup + +\beginverbatim +\beginhead...\endhead!qquad !hbox!bgroup or!egroup!qquad\head{ ...} +!endverbatim + +And what about the coding? +In the `Paradigms: Headache?' I have shown the \bluetex{} coding + +\beginverbatim +\def\beginhead{\the\prehead\bgroup\headfont} +\def\endhead{\egroup\the\posthead} +%with auxiliaries +\prehead{\vskip0pt plus2ex + \penalty-250\vskip0pt plus1ex + \bigskip\noindent} +\posthead{\medskip\nobreak + \noindent\ignorewhitespace} +%and minimal variant +\def\head#{\beginhead\bgroup + \aftergroup\endhead + \afterassignment\ignorespaces + \let\dummy=} +!endverbatim + +Note that in \bluetex, I also introduced the token variables +|\pre|, and |\post|, to parameterize +the placement within context. The advantage of doing so is +that these tags have only one function and can therefore +be customized easily.\ftn +{A white lie. In \cs{report} format I also reused the headtitle + in the ToC, ToE, and in the running header.} + +\bluesubhead Relation with tugboat.sty + +Submissions for TUGboat need as markup for headings the following. + +\beginverbatim +\head...\endhead!qquad !hbox!bgroup or!egroup!qquad\head*...* +!endverbatim + +where in the short variant the spaces around the *s are neglected. +TUGboat provides as toplevel coding +\beginverbatim +\def\head{\begingroup + \def\CurrentTag{head}% + \@allowindentfalse + \@defaultoptions + \@savingargumenttrue + \def\\{\break}% + \@checkoptions} +\def\endhead{\endgraf + \ifcase\headlevel\or + \@domainhead \or + \@dosubhead \or + \@dosubsubhead\fi + \endgroup\@next} +!endverbatim + +What can be seen from the above is that both codings are based +on two-part macros. The coding for TUGboat uses general +mechanisms not restricted to \cs{head}, +and is therefore difficult to understand.\ftn +{An example is finding the answer to the question whether the `argument' is processed + on the fly. \cs{@savingstrue} suggests that it is stored. Try to confirm + the assumption in the code, and you will agree that even reading + the code is difficult, let alone to adapt it. To borrow + macros for use in other collections is also inhibited, as Wietse + Dol communicated to me. Of course, it is a good thing to go for + general mechanisms in macro writing. But the right balance between + metacodes and single shot coding is the royal road, IMHO, with all respect.} +Especially, when one realizes that next to the parsing of options, +the minimal variant is also handled. (The parsing looks for *s). +Clever, very clever. +But the functionality can be attained simpler, with the extra bonus of +easy maintenance and customization, IMHO, with all respect. + +\bluesubhead Relation with ams.ppt + +Submissions to AMS (in ams.ppt) need as markup for headings + +\beginverbatim +\head...\endhead +!endverbatim + +The coding reads + +\beginverbatim +\outer\def\head#1\endhead{% + \add@missing\endroster + ... + \add@missing\endproclaim + \penaltyandskip@{-200}\aboveheadskip + {\headfont@\raggedcenter@ + \interlinepenalty\@M + #1\endgraf}\headmark{#1}% + \nobreak\vskip\belowheadskip} +% +\let\headmark\eat@ +!endverbatim + +The \cs{end@missing} checks whether the head occurs within the environment. +\cs{eat@} gobbles its argument. +There is no \cs{nofrillscheck}. This is done, however, in \cs{subhead}. +The coding of the check is difficult to understand, not in the least because it +allows for options.\ftn +{I was told that AMS considers to abandon \cs{nofrills} altogether.} + +\bluesubhead \LaTeX's \cs{section} + +The style defines \cs{section} as an invocation to \cs{@startsection}. +From latex.doc the following. + +\beginverbatim +%\@startsection{name}{level}{indent} +% {beforeskip}{afterskip}{style} +% optional * [altheading]% +% {heading} +%Generic command to start a section. +%Name : e.g. subsection +%Level : a number, denoting depth of +% section e.g., chapter=1, +% section=2 etc. +%Indent: Indentation of heading from +% left margin +%Beforeskip: Absulute value is skip to +% leave above the heading. +% If negative, then paragraph +% indent of text following +% heading is suppressed. +%Afterskip : if positive then skip to leave +% below heading, else negative of +% skip to right +% of run-in heading. +%Style : commands to set style. +%If * missing then increments the counter. If +%it is present, then there should be no +%[altheading] argument. Use the counter +%`secnumdepth' whose value is the highest +%section level that is to be numbered. +!endverbatim + +This is just the top of the iceberg, but generic it is for sure. +My choice would be the following. +To go first for making it as simple as possible, +and perhaps if the need is still there, +use generic coding in order to save on development and maintenance costs. + +\bluehead Knuth's options after an opening tag + +There is a beautiful example of allowing for options in manmac. +It is used in \TB~\on29. +All what follows after the opening tag \cs{begindisplay} up to the end-of-line +is taken as (optional) argument, and inserted in the +alignment display between \$\$ and \cs{halign}.\ftn +{No curly braces nor other opening and closings like [ and ]. + And when you don't need the option functionalty you won't notice. + It does not hinder or impose on you. + Minimal markup? Yes, definitely.} + +\beginverbatim +\begindisplay\hbadness10000 +\hbox spread-.666667em{The badness + of this line is 100.}& + \quad(very tight)\cr +... +\enddisplay +!endverbatim + +This example shows what Knuth had on his mind with respect to +options and explains why he did not introduce |\this|s. +The coding is a litlle more complicated but systematic. + +Can it be applied applied throughout a format? +With \cs{beginverbatim} I stumbled upon problems in +applying options to the in-line verbatim \vrt\dots\vrt. + +\bluehead Epilogue + +The paradigm is that too general, monolithic, codes are difficult +to understand and to maintain. +Borrowing macros from these collections is near to impossible. +|\this| is a simple alternative for +coping with optional arguments, and is used in \bluetex. + +Knuth suggested a solid naming convention for two-part macros: +|\begin|, |\end|, and +for the second step macro |\start|, if any. + +This naming convention has been adopted in \bluetex, +next to |\| for one-part minimal variants. + +Have fun, and all the best. +\makesignature +\pasteuptoc +\endscript \ No newline at end of file diff --git a/info/laan/paradigm/paradigm.postscript b/info/laan/paradigm/paradigm.postscript new file mode 100644 index 0000000000..c92955bf0c --- /dev/null +++ b/info/laan/paradigm/paradigm.postscript @@ -0,0 +1,1483 @@ +%Started May 1996, C.G. van der laan, cgl@rc.service.rug.nl +%Version June 1996 +\newif\ifdraft\drafttrue +\draftfalse +\ifdraft\else\input psfig \fi +%Watch out for double ! in verbatim, especially with %!!PS +\input blue.tex \loadtocmacros\tolerance500\hbadness=499\hfuzz=5pt + \parindent=1pc\everyverbatim{\unmc} +%Needed EPS files: baker.eps, barnwindowii.eps, bentley.eps, +% eschera.eps, escherb.eps, escherknotmf.eps, +% escherknotiii.epsabr, flower.eps, +% gurariabc.eps, gurarisq.eps +% jvr.eps, linebundle.eps, malbork.eps, +% polygon.eps, polygonii.eps, prpie.eps, +% sine.eps, sinedisks.eps, seal.eps, +% textalongarc.eps, textalongspiral.eps. + +\bluetitle Paradigms: Just a little bit of PostScript + +\blueissue \maps{96}2 + +\bluepictures\metapostpic\pstexpic + +\blueabstract It is all about creating EPS\Dash with graphics\Dash + to be merged with \AllTeX{} scripts. + The emphasis is on creating raw PostScript for simple symmetrical pictures. + Asides, like + incorporating accurate graphs of math functions, + typesetting text along curved paths, or + tables set sideways have been addressed. + A poor man's mftoeps approach is touched upon: + (declarative) METAFONT into (imperative) PostScript. + +\bluekeywords Declarative program, education, EPS, Escher, graphics, + imperative code, \AllTeX, + math graphs, METAFONT, merging EPS and \AllTeX, + MetaPost, mftoeps, PostScript, + sideways tables, text along curved paths. + +\beginscript + +\bluehead BLUe's Design X + +Hi folks. +The user's guide which comes with BLUe's format system\Dash +Publishing with \TeX, PWT for short\Dash +is processed {\em completely\/} by \TeX, {\em no\/} other tools such as +\PS{} are needed.\ftn{Nobody knows what the future has in store, but for + the moment I consider it a good thing that the PWT guide can be processed + just by \TeX, well \dots with BLUe's format.} +However, of late I exercised \MF +\Dash well, eventually MetaPost with the help of Jos Winnink\Dash +for graphics to be included in \TeX{} documents, and finally embarked PostScript +straightaway to create EPS pictures. + +$$\metapostpic$$ + +\PS{} is involuntary needed to (electronically) paste up the graphics, and +as resulting file format.\ftn{For exchange the {\tt.tex} and + (hand-coded) {\tt.eps} files are much better suited + because of their conciseness. This can't be beaten, not even by + Adobe's PDF\Dash Portable Document Format.} + +If we come to think of graphics as +$$\vbox{\hbox{just doing the `right' strokes or fills}}$$ +then \PS{} provides the means for this: + lines, splines and circular arcs, +to be drawn or filled.\ftn{PostScript II also provides for colors and + processing in a network.} +I use the sidestep +$$\vbox{\hbox{\MF{} $\rightarrow $MetaPost $\rightarrow$ EPS}}$$ +for general pictures but also for obtaining the right (control) points +explicitly from a decalarative specification in \MF, +as shown by Escher's knot at the end.\ftn{Another way + for arriving at the EPS code is + to use Jackowski's |mftoeps| package or to use MetaPost.} + +$$\pstexpic$$ + +With respect to graphics \PS{} can be seen as a {\em little\/} language +in the UNIX tradition.\ftn{See Bentley's Little languages in + `More programming pearls\Dash\-Confes\-sions from a coder.' Addison-Wesley.} +A little bit of \PS{} adheres the 80\%--20\% adage: +80\% of the effects (or more) with +20\% of the energy (or less). + +One can with a little knowledge of \PS{} code graphics immediately +and {\em completely\/} in \PS. +The more so because of the ubiquitous public domain GhostScript +previewers to verify the result, +next to of course the \PS{} laser printers. + +Furthermore, text is just a special case of graphics, and merging +just a little bit of text\Dash malenki Russians would say\Dash +with the graphics goes equally simple at first glance. + +And to end the lovesong the inclusion of accurate graphs of mathematical functions +goes well via coding these in \PS{} and including these as figures. +(Of course Hobby's graph extension could be used as well, or other advanced + graphics packages.) +This is illustrated by a graph of the sine function to convey the idea. + +PStricks is about {\em interfacing}. Not assuming knowledge of \PS. +This note discusses mainly {\em merging}. +Is about extending your \TeX pertise +with just a little\Dash tsjut-tsjut Russians would say\Dash +knowledge of \PS{} rewarded by high returns. + +Below I'll summarize what is needed from \PS, and illustrate the use of it +with a few examples, introducing en route the operators we need given the example. + +\bluehead PostScript + +\bluesubhead Processing + +\PS{} comes with a user's guide (cookbook) and reference manual, +the so-called blue and red books in the Adobe \PS{} series. +For processing \PS{} an interpreter is needed, such as +a \PS{} laser printer or a GhostScript previewer. +For inclusion in \AllTeX{} I use the psfig macros.\ftn{Courtesy Trevor J. Darrell.} +Goossens in his PostScript and \AllTeX, \maps{92}1, nicely details about +inclusion of PostScript.\ftn{See also the \LaTeX{} Companion.} + +As with PDF I consider the post-processing capability {\em independently\/} from +the tool which created the \PS{} source, very powerful and flexible. + +\bluesubhead Subset 0 from the language + +\PS{} is stack-oriented. +This means that operations are prescribed in polish-reverse notation, +also known as prefix notation, +similar to the HP pocket calculators. +Addition\Dash use of operator |add|\Dash for example is notated as follows. + +\beginverbatim +2 3 add%yields 5 on the stack, 2 3 consumed +!endverbatim + +\PS{} is artificially structured via structure information in +comments, double \%-ed comments. Programs which obey the Adobe +structure are called conforming and this is usually needed for inclusion +within \AllTeX, especially the BoundingBox line is required. + +\blueexample Conforming EPS structure + +\beginverbatim +%!!PS EPS +%%Title: +%%Creator: +%%CreationData: +%%BoundingBox: +%%DocumentFonts: (atend) +%%EndComments + +%%EndProlog +%%Page: 0 1 + +%%Page: 1 2 + +%%Trailer +<...> +%%DocumentFonts: Times-Roman ... +%%Pages: 3 +%%EOF +!endverbatim + +Creating and drawing paths is done by separate operators. +For creating paths operations like +|moveto| are provided while drawing goes via |stroke|. + +\beginverbatim +0 0 moveto 0 10 lineto%create path +stroke%draw a v-line of 10pt height +!endverbatim + +Variables\Dash names to be associated with their values\Dash +are handled via the so-called dictionaries. +The functionality can also be obtained via procedures. + +\beginverbatim +/size {10} def +!endverbatim + +The so-called literal name is preceded by a slash to distinguish the declaration +from its invoke. The invoke is done by just the name, also called executable name. +The procedure text is surrounded by curly braces. +Parameters are absent too. The (operand) stack is used. + +For graphics we have a CurrentTransformMatrix\Dash CTM\Dash which maps the +user space on the device space, the printer or screen. +Equally powerful is the concept of encapsulating graphics via +|gsave| and |grestore|, that is the graphics state is local\Dash encapsulated\Dash +after |gsave| until |grestore|. + +Next to the CTM \PS{} maintains the currentpoint and currentpath. + +Batagelj, \maps{95}1\Dash Combining \TeX{} and \PS\Dash +provides an in a nutshell overview.\ftn + {Nice are the hints to remove repeated parts from files which are + generated by CorelDRAW and Mathematica, in order to reduce the size + of the automatically generated and to be included files. + (The idea is to remove duplicate `dictionaries' which are included with each result.) + The example of how to include graphs of math functions in a document is + {\em very\/} useful. + However, with respect to his first picture I would prefer to use the + inherent symmetry in the data as opposed to providing all the data.} +Another introduction is in Fokker en van Oostrum's `Plaatjes in een tekst,' +\maps{94}2, next to a survey of drawing software. +\bluesubhead Summary of (graphics) commands + +The following snapshot is borrowed from Gurari, well \dots a little modified.\ftn{% + Gurari E.M (1994): + \TeX{} \& \LaTeX\Dash Drawing \& Literate Programming. + McGraw Hill. ISBN 0-07-025208-4.} +Its main purpose is to show that the number of relevant graphics primitives +is low. +The functionalities will be dealt with along the way in the examples. +For the details of the commands or the list of operators +see the red book.\ftn{A complete list with functional summaries is + in the red book section 6.2 Operator summary.} + +$$\everyverbatim{\emc} +\vbox{\halign{\hfil#\cr +\bf Arithmetic and math operators\hfill\cr +|| || mul $num$ \cr +|| sine $num$ \cr +% +\bf Path construction operators\hfill\cr +currentpoint $x$ $y$ \cr +|| || moveto \cr +|| || rmoveto \cr +|| ||lineto \cr +|| || rlineto \cr +$\langle q_{1x}\rangle$ $\langle q_{1y}\rangle$ $\langle q_{2x}\rangle$ + $\langle q_{2y}\rangle$ $\langle p_{2x}\rangle$ $\langle p_{2y}\rangle$ + curveto \cr +$\langle c_x\rangle$ $\langle c_y\rangle$ $\langle r\rangle$ + $\langle ang_1\rangle$ $\langle ang_2\rangle$ arc \cr +% +\bf String operators\hfill\cr +|| || || getinterval \cr +% +\bf Character and font operators\hfill\cr +{\tt\char92}|| findfont \cr + \ || scalefont setfont \cr +|| show \cr +|{}| || kshow \cr +% +\bf Graphics state operators\hfill\cr +|| setgray \cr +|| setlinewidth \cr +% +\bf Dictionary operators\hfill\cr +/| {}| def \cr +% +\bf Coordinate system and matrix operators\hfill\cr +|| || translate \cr +|| || scale \cr +|| rotate \cr +% +\bf Relational, boolean, and bitwise operators\hfill\cr +||\||| ||\||| le $bool$\cr +% +\bf Control operators\hfill\cr +| {} {}| ifelse \cr +| {}| repeat \cr +| {}| for \cr } +}$$ + +With prefix + $\langle in\rangle\> \langle operator\rangle\>\langle result\rangle$ +is elegant. + +\bluesubhead What is not allowed as EPS? + +I'm not knowledgeable enough to answer that question, nor do I know of +a full-blown definition of EPS. +For the moment it is some subset which works with all interpretors, +with my subset 0 in there. +When one restricts oneself to the basics of graphics, arithmetic and similar +operations then the boundary area between EPS and full \PS\Dash +or its various implementations\Dash is not in sight. + +\bluesubhead Documentation + +The red book\Dash the reference manual\Dash is generally recommended, though +the blue book\Dash the tutorial and cookbook\Dash is also nice.\ftn{I used the + \PS I red book and this is well-suited to get the flavour. + For \TeX{} and METAFONT %\MF{} %font not available + this is similar. To grasp the basic ideas + Knuth's first book is a more concise survey of the main lines of thought than + \TB{} and {\sl The METAFONTbook}.} + +\blueexample Pie chart from the blue book + +$$\ifdraft\vbox to3in{\vss\hbox{Pie chart}\vss} +\else\psfig{file=prpie.eps,height=3in} +\fi$$ + +The invoke is essentially as follows and shows that the codes can be used +straightforwardly.\ftn{It is not standard \PS. We have to construct some kind of + library to use the PostScript programs from. + Maybe the CTAN as global network library? + Copied on the various CD-ROMS?} +It is no longer necessary to mesh around with the picture environment or so, +to achieve the effect. + +\beginverbatim +%preliminary matter +(January Pie Sales) + 24 12 %... array size + [ [(Blueberry) .12 ] + [(Cherry) .30 ] + [(Apple) .26 ] + [(Boston Cream) .16 ] + [(Other) .04 ] + [(Vanilla Cream) .12 ] + ] 306 396%translate center to + 140 %size + DrawPieChart +showpage +!endverbatim + +There is also a \PS-FAQ, consult + +|ftp wilma.cs.brown.edu:|\\ +\null\qquad \qquad |pub/comp.lang.postscript|. + +It contains an annotated bibliography as well. + +The examples from Adobe's blue book are available on the net. + +\bluesubhead Proofing + +For previewing or printing, {\em as such\/} +I have to include a shift to move the picture away from the lower left corner, +say + +\beginverbatim +300 500 translate +!endverbatim + +\bluesubhead Inclusion + +I usually build a figure symmetrically around the origin and then include +it via + +\beginverbatim +$$\psfig{file=,height=}$$ +!endverbatim + +A unit can be |in|(ch), |cm|, and ilks. \cs{psfig} is very vulnerable to + spaces because of \TeX's parsing. So no spaces in there. +Now and then I forget to inactivate the |translate| needed while previewing. +No real problem. + +\bluesubsubhead BoundingBox + +Providing the right BoundingBox coordinates has all to do with +proper placement within context, the look-and-feel. +Default \PS{} assumes the origin\Dash in user space\Dash +at the lower left corner of the paper\Dash in device space. + +Surround the picture by as-if lines and supply the coordinates, in points as units +in user space coordinates, +of the lower left corner and the upper right corner in the +BoundingBox specification. +Simple is to build a picture around its symmetry point\Dash +and let this coincide with the origin\Dash +with as pleasing result that the horizontal positioning comes out centered, +when used within math display. +Vertically, I add a 10 or so +extra on either side in the BoundingBox specification, +but that depends on the character of the picture. + +Some preview systems can measure the BoundingBox and allow adjustment +interactively.\ftn{For a summary of tools to assist finding the BoundingBox + coordinates see, Reckdahl K (1995): Using EPS graphics in \LaTeX{} + documents. reckdahl@leland.stanford.edu.} + +\bluesubhead Writing PostScript + +A line bundle and a variant of it are introduced to +show how to create simple EPS. + +\bluesubsubhead A line bundle + +$$\ifdraft\vbox to1in{\vss\hbox{Line bundle}\vss} +\else\psfig{file=linebundle.eps,height=1in} +\fi$$ + +How to do this in \PS? A line as such is simple. +First a |moveto| and then a |lineto|. So a way is to create a loop and repeatedly +draw from the origin to the end of the various lines. +This can be done elegantly by using appropriately the CTM. + +\beginverbatim +%!!PS EPS +%%Title: Line bundle +%%Creator: cgl +%%CreationDate: June 4 1996 +%%BoundingBox: -40 -45 40 45 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +/r 36 def +10{0 0 moveto r 0 lineto + 36 rotate +}repeat stroke showpage +!endverbatim + +Explanation. +The idea is that first a simple line is draw, for example along the x-axes. +What happens if after that we rotate? Right, the mapping is changed. +And what happens if we supply the {\em same\/} line after this? +Indeed, it will show up rotated. Because \PS{} is an interpretive +language we can realize this specification after the rotate via a loop, +which for this simple case reads |10{...}repeat|.\ftn{Do you see the variant + for drawing a polygon? This duality linebundle and polygon has been used + by Gabo and is about what he called stereometry versus perimetry, + the structure versus the surface} + +\beginquote +Appropriately maintaining the CTM for symmetrical pictures can yield simple +looking \PS{} programs. +\endquote + +\bluesubsubhead A flower + +$$\ifdraft\vbox to1in{\vss\hbox{Flower}\vss} +\else\psfig{file=flower.eps,height=1in} +\fi$$ + +This exercises the use of |arc|. + +\beginverbatim +%!!PS EPS +%%Title: Flower +%%Creator: cgl (Courtesy Papert) +%%CreationDate: June 4 1996 +%%BoundingBox: -40 -45 40 45 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +/r 36 def +10{r r moveto%begin drawing point + r 0 r 90 180 arc + currentpoint%origin + 0 r r 270 360 arc + 36 rotate +}repeat stroke showpage +!endverbatim + +Explanation. +We have the same structure as the previous program but the `line' is now +a little more elaborated: two arcs of a circle. +\PS{} provides an operator for drawing circular arcs, called arc. +The arc has $(x,y)$ as centre, r as radius, +$ang_1$ the angle of a vector from $(x,y)$ of length $r$ +to the first endpoint of the arc, and +$ang_2$ the angle of a vector from $(x,y)$ of length $r$ +to the second endpoint of the arc.\ftn{The arc is drawn counter clockwise. + |arcn| draws clockwise.} +These arguments are expected to be on the stack. + +\beginverbatim +x y r ang1 ang2 !bf arc +!endverbatim + +Important is to realize that arc {\em counts\/} its angle from (x, 0) and that +the {\em drawing\/} starts from the point on the stack + +The specification of the flower in \MF/\MP{} reads essentially as follows. + +\beginverbatim +for k:= 1 upto 10: +draw(origin{up}..{right}(up+right){down}.. + {left}origin) rotated 36k; +endfor +!endverbatim + +Explanantion. +\MF{} allows for specification of the directions\ftn{There is also a + quartercircle which apart from orientation is drawn similarly.} +$up =(0,1), right=(1,0)$. + +IMHO, with all respect the \MF{} and \PS{} programs are similar +modulo some syntactic sugar. +However, the extra possibility of specifying the directions is more convenient +than using control points. +But perhaps that is a matter of taste, although the handling of control points +is powerful as B\'ezier himself has shown in the past. +From this I conclude that for these simple kinds of pictures we can as well use +\PS{} straightaway. + +\bluehead Some more Graphics + +\blueexample Malbork window + +This is all about using |curveto|, especially choosing suitable control points. + +$$\ifdraft\vbox to1in{\vss\hbox{Malbork window}\vss} +\else\psfig{file=malbork.eps,height=1in} +\fi$$ + +\beginverbatim +%!!PS EPS +%%Title: Malbork Window +%%Creator: cgl +%%CreationDate: May 21 1996 +%%BoundingBox: -40 -40 40 40 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +45 rotate 10 0 moveto +4{20 0 37.5 12.5 25 25 curveto + 12.5 37.5 0 20 0 10 curveto + 90 rotate +}repeat%inside lops next +5 0 moveto +4{5 35 35 5 0 5 curveto + 90 rotate +}repeat%enclosing circle next +36 0 moveto +0 0 36 0 360 arc +stroke showpage +!endverbatim + +Explanation. +|translate| changes the CTM, +with the effect that the device coordinates are shifted. (Useful for +use of \PS{} alone out of context.) + +|rotate| changes the CTM, and because of being an interpretive language +the various loop traversals map the {\em same\/} user coordinates on the +rotated device coordinates. + +$\langle number\rangle \{\dots\}$ |repeat| is a loop to be traversed +$\langle number\rangle$ of times. + +|curveto| adds a spline to the current path +from the currentpoint to the last point on the stack. +The first two points are the so-called control points of the spline.\ftn{Much similar + as in METAFONT. Choosing for the inner lop the control + points in this way is borrowed from + Haralambous Y (1995): Some METAFONT techniques. + \tubissue{16}(1), 46\dash53. It is also supplied in the description + of |curveto| in the red book.} + +|arc| adds a circular arc to the current path from the currentpoint. + +The details of the arguments for the operators are nicely documented in the +red book. + +\blueexample Escher's impossible triangle + +This is all about {\em wrong\/} projections. +However, these kinds of pictures are intriguing and fun. +I consider them well-suited to illustrate \PS's drawing capabilities. + +$$\ifdraft\vbox to1in{\vss\hbox{Escher's impossible triangle}\vss} +\else\psfig{file=eschera.eps,height=1in} +\fi$$ + +\beginverbatim +%!!PS EPS +%%Title: Escher's impossible triangle +%%Creator: cgl (inspired by Guy Shaw) +%%CreationDate: May 23 1996 +%%BoundingBox: -40 -40 40 40 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +3{25 34 moveto + 25 -34 lineto + 17 -38.2 lineto + 17 20 lineto + -17.6 0 lineto +120 rotate +}repeat stroke showpage +!endverbatim + +\on5{} points, the right stroke and a rotation or two, that's it. +End of story. + +However, it is all about finding those \on5{} points. + +$$\ifdraft\vbox to1in{\vss\hbox{the 5 points}\vss} +\else\psfig{file=escherb.eps,height=1in} +\fi$$ + +\beginverbatim +%!!PS EPS +%%Title: Essential stroke +%%Creator: cgl (inspired by Guy Shaw) +%%CreationDate: May 23 1996 +%%BoundingBox: -40 -40 40 40 +%%Pages: 1 +%%EndProlog +%%Page: 0 1 +25 34 moveto currentpoint +0 -68 rlineto currentpoint%down + -120 rotate +25 34 lineto%preserve symmetry + 120 rotate currentpoint +17 20 lineto currentpoint +-17.6 0 lineto currentpoint +%labels +/Courier findfont 8 scalefont setfont +moveto -5 -3 rmoveto (5) show +moveto 1 1 rmoveto (4) show +moveto 2 -5 rmoveto (3) show +moveto 2 0 rmoveto (2) show +moveto 2 0 rmoveto (1) show +stroke showpage +!endverbatim + +Explanation. +The essential stroke figure also illustrates the integration +of text in this case digits. +|currentpoint| pushes the point on the stack. +The last |moveto|-s pop these coordinates up. +|rmoveto| moves {\em relatively.} + +\smallbreak +And what about their relationships, and +what about the minimal information to be prescribed? + +Looking more closely it turns out that {\em only\/} the first point is all +that is needed. +The rest is implicit to the nature of the figure.\ftn{Of course + one can also think of other equivalent parameters like size and thickness.} + +\beginverbatim +%!!PS EPS +%%Title: Escher's Impossible triangle II +%%Creator: cgl +%%CreationDate: May 23 1996 +%%BoundingBox: -40 -40 40 40 +%%Pages: 1 +%%EndProlog +%%Page: 1 1 +%Parameterized over p1 +/point {25 34} def%note x