1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
%%
%% This is file `crosswrd.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% crosswrd.dtx (with options: `package')
%% 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
%%
%% distribution consist of
%%
%% crosswrd.dtx source
%% crosswrd.ins installation script
%% 00readme
%%
%% 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}
[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
\abovedisplayshortskip \z@ plus2pt
\belowdisplayshortskip 4pt plus2pt minus 2pt
\def\@listi{\itemsep 0pt
\parsep \z@ plus 1pt
\topsep 4pt plus 2pt minus 2pt
}}
\newif\ifnumberit
\newcount{\gridr@ws}\newcount{\gridc@ls}
\newcount{\p@rsize}\newcount{\p@csize}
\newcount{\Down}
\newcount{\Across}
\newwrite\tf@acr
\newwrite\tf@dwn
\def\OpenClueFiles{%
\immediate\openout \tf@acr \jobname.acr\relax
\immediate\openout \tf@dwn \jobname.dwn\relax
\@writefile{acr}{\begin{minipage}[t]{\cluewidth}}%
\@writefile{acr}{ \centerline{\textbf{\ACROSStext}}}%
\@writefile{acr}{ \sloppy}%
\@writefile{acr}{ \cluesize}%
\@writefile{acr}{ \begin{ClueList}}%
\@writefile{dwn}{\begin{minipage}[t]{\cluewidth}}%
\@writefile{dwn}{ \centerline{\textbf{\DOWNtext}}}%
\@writefile{dwn}{ \sloppy}%
\@writefile{dwn}{ \cluesize}%
\@writefile{dwn}{ \begin{ClueList}}}
\newcommand\ACROSStext{ACROSS}
\newcommand\DOWNtext{DOWN}
\def\CloseClueFiles{%
\@writefile{acr}{ \end{ClueList}}%
\@writefile{acr}{\end{minipage}}%
\@writefile{dwn}{ \end{ClueList}}%
\@writefile{dwn}{\end{minipage}}%
\immediate\closeout\tf@acr \let\tf@acr\relax
\immediate\closeout\tf@dwn \let\tf@dwn\relax
\endgraf
}
\def\ClueListlabel#1{\hspace\labelsep {\bf #1}\hss}
\def\ClueList{\list{}{\labelwidth\leftmargin
\advance \labelwidth by -\labelsep
\let\makelabel\ClueListlabel}}
\let\endClueList\endlist
\def\PrintClues{%
\centerline{%
\begin{tabular}{ c | c }
\@input{\jobname.acr}
&
\@input{\jobname.dwn}
\end{tabular}
}\endgraf
}
\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{#3}%
\SetUpGrid{#1}{\c@ls}}
{\endgraf
\centerline{\Header}%
\hbox{\FinishGrid}%
\ifthenelse {\equal{\Preamble}{}} {}
{\centerline{\parbox{\textwidth}{\Preamble}}\medskip}
\CloseClueFiles
\hbox{\PrintClues}%
\egroup
}
\newenvironment{crossword*}[3][\c@ls]{%
\def\c@ls{#2}
\unitlength 4mm\numberitfalse
\def\barwidth{0.1}
\endgraf\leavevmode
\vtop\bgroup
\def\Header{{\bf\strut #3}}%
\def\answer{Y}%
\let\tf@dwn=\relax \let\tf@acr=\relax
\SetUpGrid{#1}{#2}}
{\endgraf
\centerline{\Header}%
\hbox{\FinishGrid}%
\egroup
}
\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 \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
\fi
\nextlet{#1}}
\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
\global\Barcode=2
\ifthenelse{\equal{\@empty}{#7}}{}{
\ifx\tf@acr\relax\else
\@writefile{acr}{ \item[#1] #6 (#7)}%
\fi}
\let\Direction=\Across
\else
\ifx#2D
\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
command must be `A' or `D'}
\errmessage{Illegal direction (#1) specification
for \string\clue.}
\fi
\fi
\global\lettercount=0
\nextletter{\Direction}#5\@nil
\ignorespaces
}
\newcount\clueNumber
\def\special@gobble #1\@nil{}
\def\findnumber#1{%
\afterassignment \special@gobble \clueNumber=0#1 \@nil
\ifnum\clueNumber=0
\errhelp{The first parameter of the \string\clue\space command
must commence with a digit}
\errmessage{Illegal clue number (#1) specified
for \string\clue.}
\fi
}
\def\cluenumber{\the\clueNumber}
\def\blackenrow{\let\savediterate\iterate
\loop\relax\ifnum\Across>\z@
\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#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=\gridc@ls
\ifnum\Down>\z@
\blackenrow
\advance\Down by \m@ne
\repeat
}
\def\f@rst#1#2.{#1}
\def\TestAnswers#1{\edef\next{\def\noexpand\answer{#1}}%
\lowercase\expandafter{\next}%
\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 n.}%
}
\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]{\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
\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@rsize)(1,-\p@rsize)
\loop\ifnum\Down>\z@
\put(1,-\Down){\line(1,0){\the\gridc@ls}}
\Across=\gridc@ls
{\loop \ifnum\Across>\z@
\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
\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\gridr@ws}}
\advance\Across by \m@ne
\repeat
\end{picture}%
}%
}
\endinput
%%
%% End of file `crosswrd.sty'.
|