diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty | 275 |
1 files changed, 153 insertions, 122 deletions
diff --git a/Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty b/Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty index 2ce9fec99f9..69c18210116 100644 --- a/Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty +++ b/Master/texmf-dist/tex/latex/crosswrd/crosswrd.sty @@ -5,34 +5,36 @@ %% The original source files were: %% %% crosswrd.dtx (with options: `package') -%% -%% Copyright 1989 Brian Hamilton Kelly -%% updated for LaTeX2e by Frank Mittelbach 96/12/06 +%% Copyright C 1989 Brian Hamilton Kelly %% %% crossword macros for LaTeX +%% updated for LaTeX2e by Frank Mittelbach 96/12/06 +%% substantially extended by Dirk Laurie 08/01/18 %% %% for documentation run latex crosswrd.dtx %% -%% This work may be distributed and/or modified under the -%% conditions of the LaTeX Project Public License, either version 1.3 -%% of this license or (at your option) any later version. -%% The latest version of this license is in -%% http://www.latex-project.org/lppl.txt -%% and version 1.3 or later is part of all distributions of LaTeX -%% version 2005/12/01 or later. +%% distribution consist of %% -%% This work has the LPPL maintenance status `unmaintained'. +%% crosswrd.dtx source +%% crosswrd.ins installation script +%% 00readme %% -%% This work consists of the files crosswrd.dtx, crosswrd.ins and README -%% and the derived files test0.tex, test1.tex, grid0.tex, grid1.tex and crosswrd.sty. +%% don't distribute this file without distributing the above +%% files as well %% %% crosswrd.dtx %% Copyright 1989 Brian Hamilton Kelly %% updated for LaTeX2e by Frank Mittelbach 96/12/06 %% Updated for LPPL 1.3c or later by Clea F. Rees (for Frank Mittelbach), 2008/10/06. +%% +%% Upgraded with many new features by Dirk Laurie 2010/02/01 \NeedsTeXFormat{LaTeX2e}[1995/12/01] +\RequirePackage{ifthen} \ProvidesPackage{crosswrd} - [1996/12/06 v2.8b Generating crosswords (BHK)] + [2010/02/01 v3.0 Generating crosswords (BHK,DPL)] + + + \def\ninept{\@setsize\ninept{11pt}\ixpt\@ixpt \abovedisplayskip 8.5pt plus 3pt minus 4pt \belowdisplayskip \abovedisplayskip @@ -43,8 +45,8 @@ \topsep 4pt plus 2pt minus 2pt }} \newif\ifnumberit -\newcount{\gr@dsize} -\newcount{\p@csize} +\newcount{\gridr@ws}\newcount{\gridc@ls} +\newcount{\p@rsize}\newcount{\p@csize} \newcount{\Down} \newcount{\Across} \newwrite\tf@acr @@ -52,15 +54,15 @@ \def\OpenClueFiles{% \immediate\openout \tf@acr \jobname.acr\relax \immediate\openout \tf@dwn \jobname.dwn\relax - \@writefile{acr}{\begin{minipage}[t]{70mm}}% + \@writefile{acr}{\begin{minipage}[t]{\cluewidth}}% \@writefile{acr}{ \centerline{\textbf{\ACROSStext}}}% \@writefile{acr}{ \sloppy}% - \@writefile{acr}{ \ninept}% + \@writefile{acr}{ \cluesize}% \@writefile{acr}{ \begin{ClueList}}% - \@writefile{dwn}{\begin{minipage}[t]{70mm}}% + \@writefile{dwn}{\begin{minipage}[t]{\cluewidth}}% \@writefile{dwn}{ \centerline{\textbf{\DOWNtext}}}% \@writefile{dwn}{ \sloppy}% - \@writefile{dwn}{ \ninept}% + \@writefile{dwn}{ \cluesize}% \@writefile{dwn}{ \begin{ClueList}}} \newcommand\ACROSStext{ACROSS} \newcommand\DOWNtext{DOWN} @@ -87,104 +89,101 @@ \end{tabular} }\endgraf } -\def\crossword#1#2{% +\newenvironment{crossword}[3][\c@ls]{% + \def\c@ls{#2} \endgraf\leavevmode \vtop\bgroup \unitlength 6mm\numberittrue \def\Header{}% + \def\Preamble{}% + \def\cluewidth{70mm} + \let\numbersize\tiny + \let\cluesize\ninept + \def\barwidth{0.1} \OpenClueFiles - \TestAnswers{#2}% - \SetUpGrid{#1}} -\def\endcrossword{\endgraf + \TestAnswers{#3}% + \SetUpGrid{#1}{\c@ls}} +{\endgraf \centerline{\Header}% \hbox{\FinishGrid}% + \ifthenelse {\equal{\Preamble}{}} {} + {\centerline{\parbox{\textwidth}{\Preamble}}\medskip} \CloseClueFiles \hbox{\PrintClues}% \egroup } -\expandafter\def\csname crossword*\endcsname#1#2{% +\newenvironment{crossword*}[3][\c@ls]{% + \def\c@ls{#2} \unitlength 4mm\numberitfalse + \def\barwidth{0.1} \endgraf\leavevmode \vtop\bgroup - \def\Header{{\bf\strut #2}}% + \def\Header{{\bf\strut #3}}% \def\answer{Y}% \let\tf@dwn=\relax \let\tf@acr=\relax - \SetUpGrid{#1}} - -\expandafter\def\csname endcrossword*\endcsname{\endgraf + \SetUpGrid{#1}{#2}} +{\endgraf \centerline{\Header}% \hbox{\FinishGrid}% \egroup } -\def\laterletter#1{\setsquare{\lettersquare{#1}}} +\def\ind@x#1#2{R\romannumeral #1C\romannumeral#2} +\def\arr@yref#1#2#3{\csname #1\ind@x{#2}{#3}\endcsname} +\def\value#1[#2,#3]{\arr@yref{#1}{#2}{#3}} +\def\assign#1[#2,#3]=#4;% +{\expandafter\edef\csname #1\ind@x{#2}{#3}\endcsname{#4}} +\newcount\accumulat@r +\def\addto#1[#2,#3]+=#4;% +{\accumulat@r=\value #1[#2,#3] \advance\accumulat@r by #4 + \assign #1[#2,#3]=\the\accumulat@r;} + + + +\newcount\lettercount +\newcount\Barcode + \def\nextletter#1#2{% \ifx#2\@nil \let\nextlet=\@gobble - \else\letterput{#2}\advance#1 by \@ne + \else \immediate\edef\Before{\value Letter[\Down,\Across]} + \assign Letter[\Down,\Across]=#2; + \immediate\edef\After{\value Letter[\Down,\Across]} + \if \Before ! \else \if \Before \After + \else \errhelp{You mistyped an answer, or miscounted the coordinates.} + \errmessage{Letter "\After" conflicts with earlier "\Before" + in row \the\Down, column \the\Across} + \fi \fi + \ifnum \lettercount>0 \addto Bar[\Down,\Across]+=-\Barcode; \fi + \@gobble{#2} \advance#1 by \@ne \global\advance \lettercount by \@ne \let\nextlet=\nextletter - \let\letterput=\laterletter \fi \nextlet{#1}} -\def\blacktest{\blacksquare} -\newif\ifneed@d -\newif\ifNoerr -\Noerrtrue -\newtoks\Number \newtoks\Plain -\def\blank#1{\Plain} -\def\numbered#1#2{\Number} -\def\letterinsquare#1{#1} -\def\letterinnumbersquare#1#2{#2} -\def\setsquare#1{% - \need@dfalse - \ifx#1\blacksquare - \need@dtrue - \else - \expandafter\ifx\csname\ther@w\thec@l\endcsname\blacktest - \need@dtrue - \else - \let\lettersquare=\letterinsquare - \let\numbersquare=\letterinnumbersquare - \expandafter\if\csname\ther@w\thec@l\endcsname#1 - \else - \ifNoerr - \errhelp{Two intersecting lights tried to - put different letters^^Jin the same square! - You've probably confused their coordinates.^^J - Carry on, and examine the printout.} - \errmessage{Illegal redefinition of square \ther@w\thec@l. - Was: \expandafter\meaning\csname\ther@w - \thec@l\endcsname. - Now: \noexpand #1} - \Noerrfalse - \fi - \fi - \let\lettersquare=\blank - \let\numbersquare=\numbered - \expandafter\ifx#1\Number - \need@dtrue - \fi - \fi - \fi - \ifneed@d - \expandafter\edef\csname\ther@w\thec@l\endcsname{\noexpand #1} - \fi -} \def\clue#1#2#3#4#5#6#7{% + \Across=#3 \Down=#4 \findnumber{#1} + \immediate\edef\Before{\value Number[\Down,\Across]} + \assign Number[\Down,\Across]=\cluenumber; + \immediate\edef\After{\value Number[\Down,\Across]} + \ifnum \Before>0 \ifnum \After=\Before + \else \errhelp + {You probably made a mistake when typing in one of the clues.} + \errmessage{Number {\After} conflicts with earlier {\Before} + in row \the\Down, column \the\Across} + \fi \fi \ifx#2A - \if\@empty#7\relax\else + \global\Barcode=2 + \ifthenelse{\equal{\@empty}{#7}}{}{ \ifx\tf@acr\relax\else \@writefile{acr}{ \item[#1] #6 (#7)}% - \fi - \fi + \fi} \let\Direction=\Across \else \ifx#2D - \if\@empty#7\relax\else - \ifx\tf@dwn\relax\else - \@writefile{dwn}{ \item[#1] #6 (#7)}% - \fi - \fi + \global\Barcode=1 + \ifthenelse{\equal{\@empty}{#7}}{}{ + \ifx\tf@dwn\relax\else + \@writefile{dwn}{ \item[#1] #6 (#7)}% + \fi} \let\Direction=\Down \else \errhelp{The second parameter of the \string\clue\space @@ -193,10 +192,7 @@ for \string\clue.} \fi \fi - \Across=#3 \Down=#4 - \edef\letterput##1{\noexpand\setsquare - {\noexpand\numbersquare - {\noexpand\cluenumber}{##1}}}% + \global\lettercount=0 \nextletter{\Direction}#5\@nil \ignorespaces } @@ -214,77 +210,112 @@ \def\cluenumber{\the\clueNumber} \def\blackenrow{\let\savediterate\iterate \loop\relax\ifnum\Across>\z@ - \setsquare{\blacksquare}% + \assign Bar[\Down,\Across]=3; + \assign Letter[\Down,\Across]=!; + \assign Number[\Down,\Across]=0; \advance\Across by \m@ne \repeat \let\iterate\savediterate } -\def\SetUpGrid#1{% - \gr@dsize=#1 - \p@csize=#1 \advance\p@csize by \@ne - \Down=\gr@dsize +\def\SetUpGrid#1#2{% + \gridr@ws=#1\gridc@ls=#2 + \p@rsize=#1 \advance\p@rsize by \@ne + \p@csize=#2 \advance\p@csize by \@ne + \typeout{Grid has #1 rows and #2 columns.} + \Down=\gridr@ws \loop - \Across=\gr@dsize + \Across=\gridc@ls \ifnum\Down>\z@ \blackenrow \advance\Down by \m@ne \repeat } -\def\thec@l{C\romannumeral\Across} -\def\ther@w{R\romannumeral\Down} \def\f@rst#1#2.{#1} \def\TestAnswers#1{\edef\next{\def\noexpand\answer{#1}}% \lowercase\expandafter{\next}% - \edef\answer{\expandafter \f@rst \answer .}% + \edef\answer{\expandafter \f@rst \answer n.}% \if\answer y \else \if\answer n \else \typein[\answer]{Make answers visible? [Y/N]: }\fi \fi \edef\next{\def\noexpand\answer{\answer}}% \uppercase\expandafter{\next}% - \edef\answer{\expandafter \f@rst \answer .}% + \edef\answer{\expandafter \f@rst \answer n.}% } -\def\letter#1{{\put(\Across,-\Down){\makebox(1,1){\sffamily #1}}}} -\def\numberedsquare#1#2{% - \put(\Across,-\Down){% +\def\putletter{{\put(\Across,-\Down){\makebox(1,1) + {\sffamily \value Letter[\Down,\Across]}}}} +\newcount\oldnumber \oldnumber=0 +\newif\ifseqtest \seqtestfalse +\def\putnumber{\immediate\def\Number{\value Number[\Down,\Across]} + \ifnumberit \ifnum\Number>0 + \put(\Across,-\Down){% \begin{picture}(1,1)(0,0) - \put(0.05,0.05){\makebox(0.9,0.9)[tl]{\tiny #1}} - \end{picture}% - } - \letter{#2}} -\def\unnumberedsquare#1{\letter} -\def\FinishGrid{% - \if\answer Y \else \let \letter=\@gobble \fi - \ifnumberit - \let\numbersquare=\numberedsquare - \else - \let\numbersquare=\unnumberedsquare + \put(0.05,0.05){\makebox(0.9,0.9)[tl]{\numbersize\Number}} + \end{picture}} + \ifnum \oldnumber>0 \advance\oldnumber by\m@ne + \ifnum \oldnumber=\Number {\seqtesttrue} \else + \ifseqtest + \errhelp{Clues should be numbered consecutively from top left + to bottom right.} + \errmessage{Found clue number \Number, but expected \the\oldnumber} + \seqtestfalse + \else\seqtesttrue\fi + \fi \fi - \let\lettersquare=\letter - \def\blacksquare{% - \put(\Across,-\Down){\rule{\unitlength}{\unitlength}}} - \Down=\gr@dsize + \global \oldnumber=\Number +\fi \fi +} +\newcount \pr@vious +\newcount \c@de +\def\putbars{ \linethickness{\barwidth\unitlength} + \c@de=\value Bar[\Down,\Across] + \ifnum \c@de>1 \advance\c@de by -2 + \ifnum \Across>1 + \pr@vious=\Across \advance \pr@vious by -1 + \immediate\def\pr@vlet{\value Letter[\Down,\pr@vious]} + \if \pr@vlet ! \else \put(\Across,-\Down){\line(0,1){1}} + \fi \fi \fi + \ifnum \c@de>0 + \ifnum \Down>1 + \pr@vious=\Down \advance \pr@vious by -1 + \immediate\def\pr@vlet{\value Letter[\pr@vious,\Across]} + \if \pr@vlet ! \else \put(\Across,-\pr@vious){\line(1,0){1}} + \fi \fi \fi +} +\def\FinishGrid{% + \if\answer Y \else \let\putletter\relax \fi + \Down=\gridr@ws \centerline{% - \begin{picture}(\p@csize,\p@csize)(1,-\p@csize) + \begin{picture}(\p@csize,\p@rsize)(1,-\p@rsize) \loop\ifnum\Down>\z@ - \put(1,-\Down){\line(1,0){\the\gr@dsize}} - \Across=\gr@dsize + \put(1,-\Down){\line(1,0){\the\gridc@ls}} + \Across=\gridc@ls {\loop \ifnum\Across>\z@ - \csname\ther@w\thec@l\endcsname + \immediate\def\lett@r{\value Letter[\Down,\Across]} + \if \lett@r ! \put(\Across,-\Down){\rule{\unitlength}{\unitlength}} + \else \putletter \putnumber \putbars + \fi \advance\Across by \m@ne \repeat }% \advance\Down by \m@ne \repeat - \put(1,0){\line(1,0){\the\gr@dsize}} + \ifthenelse{\equal{\the\oldnumber}1}{} + {\ifnumberit\errhelp{Clues should be numbered consecutively + from top left to bottom right.} + \errmessage{First clue number is \the\oldnumber, not 1} \fi} + \put(1,0){\line(1,0){\the\gridc@ls}} \Across=\p@csize \loop\ifnum\Across>\z@ - \put(\Across,0){\line(0,-1){\the\gr@dsize}} + \put(\Across,0){\line(0,-1){\the\gridr@ws}} \advance\Across by \m@ne \repeat \end{picture}% }% } + + + \endinput %% %% End of file `crosswrd.sty'. |