%%
%% This is file `cwpuzzle.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% cwpuzzle.dtx 
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from cwpuzzle.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file cwpuzzle.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
\def\filename{cwpuzzle.dtx}
\def\fileversion{1.11}
\def\filedate{2022/09/13}
\let\docversion=\fileversion
\let\docdate=\filedate
\typeout{%
%% Purpose:
        Package: cwpuzzle \filedate\space\fileversion\space
        for typesetting crossword puzzles and more.
}%
%%
%% Documentation:
%%      The documentation  can be generated   from the original  file
%%      cwpuzzle.dtx  with  the  doc  style/package.   LaTeX the file
%%      cwpuzzle.dtx to get the full documentation in dvi format.
%%
%%
%% Author: Gerd Neugebauer
%%         Im Lerchels\"ohl 5
%%         64521 Gro\ss-Gerau
%% Mail:   gene@gerd-neugebauer.de
%%
%% Copyright (c) 1995-2022 Gerd Neugebauer
%%
%%  cwpuzzle.dtx  is distributed in  the hope that  it will be useful,
%%  but  WITHOUT  ANY WARRANTY.    No  author or  distributor  accepts
%%  responsibility to  anyone for the  consequences of using it or for
%%  whether  it serves any particular purpose  or works at all, unless
%%  he says so in writing.
%%
%%  Everyone  is granted permission  to copy,  modify and redistribute
%%  cwpuzzle.dtx,  provided this  copyright  notice  is preserved  and
%%  any modifications are indicated.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\ProvidesPackage{cwpuzzle}[\filedate gene]
\RequirePackage{amssymb}
\newdimen\PuzzleUnitlength
\PuzzleUnitlength=20pt
\newcommand\PuzzleClueFont{\footnotesize}
\newcommand\PuzzleFont{\rmfamily\normalsize}
\newcommand\PuzzleNumberFont{\sffamily\scriptsize}
\let\PuzzleHook=\relax
\newcount\Puzzle@X
\newcount\Puzzle@Y
\begingroup
\catcode`\|=13
\gdef\Puzzle@@solution{
  \let|=\Puzzle@Box@@solution
  \let\Frame=\Puzzle@Frame@@solution
}
\gdef\Puzzle@@normal{
  \let|=\Puzzle@Box@@normal
  \let\Frame=\Puzzle@Frame@@normal
}
\endgroup
\newenvironment{Puzzle}[2]{\PuzzlePre
  \catcode`\|=13
  \@nameuse{Puzzle@@\Puzzle@TYPE}%
  \unitlength=\PuzzleUnitlength
  \linethickness{\PuzzleLineThickness}%
  \Puzzle@Y=#2
  \begin{picture}(#1,#2)
    \Puzzle@Box@@normal.
}{%
    \PuzzleHook
  \end{picture}\PuzzlePost
}
\newcommand\PuzzleLineThickness{.25pt}
\newcommand\PuzzlePre{%
    \par\noindent\mbox{}\hfill
}
\newcommand\PuzzlePost{%
    \hfill\null\par\noindent
}
\newcommand\Puzzle@Frame@@normal[5]{\put(#1,#2){\framebox(#3,#4){%
      \begin{minipage}{#3\unitlength}\begin{center} #5
      \end{center}\end{minipage}}}}
\newcommand\Puzzle@Frame@@solution[5]{}
\newcommand\PuzzleBlackBox{\rule{\PuzzleUnitlength}{\PuzzleUnitlength}}
\newcommand\Puzzle@Box@@normal[1][]{%
  \def\Puzzle@tmp@{#1}%
  \Puzzle@Box@@normal@
}
\newcommand\Puzzle@Box@@normal@[2][f]{%
  \def\PuzzleContent{#2}%
  \def\Puzzle@tmp{#2}%
  \if\Puzzle@tmp.
    \Puzzle@X=0
    \advance\Puzzle@Y-1
  \else
    \ifx\Puzzle@tmp\@empty
    \else
      \if\Puzzle@tmp*
        \Puzzle@Cell@Loop *#1{}%
      \else
        \Puzzle@Cell@Loop #1{}%
      \fi
    \fi
    \ifx\@empty\Puzzle@tmp@\else
      \PuzzlePutNumber{\Puzzle@X}{\Puzzle@Y}{\Puzzle@tmp@}%
    \fi
    \advance\Puzzle@X 1
  \fi
}
\def\PuzzlePutNumber#1#2#3{%
  \put(#1,#2){\makebox(1,.95)[tl]{\PuzzleNumberFont\,#3}}%
}
\def\Puzzle@Cell@Loop#1{%
  \def\Puzzle@tmp{#1}%
  \ifx\Puzzle@tmp\@empty
    \let\Puzzle@tmp\relax
  \else
    \expandafter\ifx\csname Puzzle@Cell@@#1\endcsname\relax
      \typeout{cwpuzzle: Cell type #1 is undefined. I am ignoring it}%
    \else
      \csname Puzzle@Cell@@#1\endcsname{\Puzzle@X}{\Puzzle@Y}%
    \fi
    \let\Puzzle@tmp\Puzzle@Cell@Loop
  \fi
  \Puzzle@tmp
}
\newcommand\Puzzle@Box@@solution[1][]{%
  \def\Puzzle@tmp@{#1}%
  \Puzzle@Box@@solution@
}
\newcommand\Puzzle@Box@@solution@[2][f]{%
  \def\Puzzle@tmp{#2}%
  \if\Puzzle@tmp.
    \Puzzle@X=0
    \advance\Puzzle@Y-1
  \else
    \ifx\Puzzle@tmp\@empty
    \else
      \if\Puzzle@tmp*
        \Puzzle@Cell@Loop *#1{}%
      \else
        \Puzzle@Cell@Loop #1{}%
        \put(\Puzzle@X,\Puzzle@Y){\PuzzleSolutionContent{#2}}%
      \fi
    \fi
    \def\Puzzle@tmp{#1}%
    \ifx\Puzzle@tmp\@empty\else
      \ifPuzzle@SolutionNumbered
        \PuzzlePutNumber{\Puzzle@X}{\Puzzle@Y}{\Puzzle@tmp@}%
      \fi
    \fi
    \advance\Puzzle@X 1
  \fi
}
\def\PuzzleSolutionContent#1{\makebox(1,1){\uppercase{#1}}}
\newcommand\PuzzleDefineCell[2]{
  \global\@namedef{Puzzle@Cell@@#1}##1##2{#2}%
}
\newcommand\PuzzleDefineColorCell[2]{
  \global\@namedef{Puzzle@Cell@@#1}##1##2{%
    \fboxsep=0pt
    \put(##1,##2){\makebox(1,1){\colorbox{#2}{\makebox(1,1){}}}}
   }%
}
\def\PuzzleThickline{\linethickness{2pt}}
\PuzzleDefineCell{T}{{%
  \advance#2 1
  \PuzzleThickline
  \put(#1,#2){{\line(1,0){1}}}
}}
\PuzzleDefineCell{t}{{%
  \put(#1,#2){\framebox(1,1){}}
  \advance#2 1
  \PuzzleThickline
  \put(#1,#2){{\line(1,0){1}}}
}}
\PuzzleDefineCell{B}{{%
  \PuzzleThickline
  \put(#1,#2){{\line(1,0){1}}}
}}
\PuzzleDefineCell{b}{{%
  \put(#1,#2){\framebox(1,1){}}
  \PuzzleThickline
  \put(#1,#2){{\line(1,0){1}}}
}}
\PuzzleDefineCell{l}{{%
  \put(#1,#2){\framebox(1,1){}}
  \PuzzleThickline
  \put(#1,#2){{\line(0,1){1}}}
}}
\PuzzleDefineCell{L}{{%
  \PuzzleThickline
  \put(#1,#2){{\line(0,1){1}}}
}}
\PuzzleDefineCell{r}{{%
  \put(#1,#2){\framebox(1,1){}}
  \advance #1 1
  \PuzzleThickline
  \put(#1,#2){{\line(0,1){1}}}
}}
\PuzzleDefineCell{R}{{%
  \advance #1 1
  \PuzzleThickline
  \put(#1,#2){{\line(0,1){1}}}
}}
\PuzzleDefineCell{f}{{%
  \put(#1,#2){\framebox(1,1){}}
}}
\PuzzleDefineCell{S}{{%
  \put(#1,#2){\makebox(1,1){\expandafter\uppercase{\PuzzleContent}}}
}}
\PuzzleDefineCell{.}{}
\PuzzleDefineCell{O}{{%
  \put(\the#1.5,\the#2.5){\oval(1,1){}}
}}
\PuzzleDefineCell{o}{{%
  \put(#1,#2){\framebox(1,1){}}
  \put(\the#1.5,\the#2.5){\oval(1,1){}}
}}
\PuzzleDefineCell{*}{%
  \put(#1,#2){\framebox(1,1){\PuzzleBlackBox}}
}
\PuzzleDefineCell{/}{{%
  \put(#1,#2){{\line(1,1){1}}}
}}
\PuzzleDefineCell{,}{{%
  \advance#2 1
  \put(#1,#2){{\line(1,-1){1}}}
}}
\newcommand\Puzzle@Clue@@normal[3]{\textsf{#1} #3 }
\newcommand\Puzzle@Clue@@solution[3]{}
\newenvironment{Puzzle@Clues@@normal}[1]{%
  \let\Clue\Puzzle@Clue@@normal
  \PuzzleCluePre
  \PuzzleClueFont{#1}%
}{\PuzzleCluePost }
\newcommand\PuzzleCluePre{%
  \null\hfill
  \begin{minipage}[t]{.45\textwidth}%
}
\newcommand\PuzzleCluePost{
  \end{minipage}\hfill\null
}
\newenvironment{Puzzle@Clues@@solution}[1]{%
  \let\Clue\Puzzle@Clue@@solution
}{}
\newcommand\PuzzleWordsText[1]{Words of length #1: }
\newenvironment{Puzzle@Words@@normal}[1]{%
  \PuzzleWordsText{#1}%
  \let\Word\relax
}{\par}
\newenvironment{Puzzle@Words@@solution}[1]{%
  \newcommand\Word[1]{}%
}{}
\newcommand\PuzzleNumbers[1]{\begingroup
  \@nameuse{Puzzle@@\Puzzle@TYPE}%
  \Puzzle@Y=0
  \Puzzle@X=1
  \unitlength=\PuzzleUnitlength
  \Puzzle@Numbers#1.\endgroup}
\begingroup
\catcode`\|=13
\gdef\Puzzle@Numbers#1{%
  \if#1.
    \let\next\relax
  \else
    \begin{picture}(1,1)
      \xdef\X{\the\Puzzle@X}%
      \Puzzle@X=0
      |[\X]{#1}%
    \end{picture}%
    \let\next\Puzzle@Numbers
    \advance\Puzzle@X 1
  \fi
  \next
}
\endgroup
\newcommand\PuzzleLettersText{The following letters are used: }
\newcommand\PuzzleLetters[1]{\PuzzleLettersText #1\par}
\newcommand\Puzzle@TYPE{normal}
\newcommand\PuzzleSolution[1][false]{%
  \@nameuse{Puzzle@SolutionNumbered#1}%
  \let\Kakuro@HINT\Kakuro@nohint
  \let\PuzzleClues\Puzzle@Clues@@solution
  \let\endPuzzleClues\endPuzzle@Clues@@solution
  \let\PuzzleWords\Puzzle@Words@@solution
  \let\endPuzzleWords\endPuzzle@Words@@solution
  \def\Puzzle@TYPE{solution}%
}
\newcommand\PuzzleUnsolved{%
  \let\Kakuro@HINT\Kakuro@hint
  \let\PuzzleClues\Puzzle@Clues@@normal
  \let\endPuzzleClues\endPuzzle@Clues@@normal
  \let\PuzzleWords\Puzzle@Words@@normal
  \let\endPuzzleWords\endPuzzle@Words@@normal
  \xdef\Puzzle@TYPE{normal}}
\newif\ifPuzzle@SolutionNumbered
\Puzzle@SolutionNumberedfalse
\begingroup
\catcode`\|=13
\gdef\Sudoku{\begin{Puzzle}{9}{9}%
  \let\Puzzle@pipe=|%
  \def\PPa{\Puzzle@pipe[][fS]}%
  \def|##1{\ifx##1*\let\next\PPa\else
    \Puzzle@pipe{##1}\let\next\relax\fi\next}
}
\endgroup
\gdef\endSudoku{%
  \multiput(0,0)(1,0)9{\framebox(1,1){}}
  \multiput(0,1)(1,0)9{\framebox(1,1){}}
  \multiput(0,2)(1,0)9{\framebox(1,1){}}
  \multiput(0,3)(1,0)9{\framebox(1,1){}}
  \multiput(0,4)(1,0)9{\framebox(1,1){}}
  \multiput(0,5)(1,0)9{\framebox(1,1){}}
  \multiput(0,6)(1,0)9{\framebox(1,1){}}
  \multiput(0,7)(1,0)9{\framebox(1,1){}}
  \multiput(0,8)(1,0)9{\framebox(1,1){}}
  \linethickness{\SudokuLinethickness}%
  \put(0,0){\framebox(9,9){}}
  \put(3,0){\framebox(3,9){}}
  \put(0,3){\framebox(9,3){}}
\end{Puzzle}}
\newcommand\SudokuLinethickness{2pt}
\newcommand\KakuroNumberFont{\sffamily\tiny}
\def\Kakuro@cell#1{%
  \ifx#1.       \def\next{\Puzzle@pipe.}%
  \else\ifx#1<  \let\next\Kakuro@HINT
  \else\ifx#1*  \let\next\Kakuro@always
  \else\ifx#1-  \let\next\Kakuro@empty
  \else\Puzzle@pipe#1 \let\next\relax
  \fi\fi\fi\fi
  \next
}%
\def\Kakuro@always{\Puzzle@pipe[][fS]}%
\def\Kakuro@empty{\Puzzle@pipe{}}%
\def\Kakuro@hint#1:#2>{%
  \def\x{#2}%
  \ifx\x\empty\else
  \put(\Puzzle@X,\Puzzle@Y){%
    \makebox(1,.8)[r]{\parbox{.95\unitlength}{%
      \raggedright\KakuroNumberFont
        $\blacktriangledown$\\#2}}}
  \fi
  \def\x{#1}%
  \ifx\x\empty\else
  \put(\Puzzle@X,\Puzzle@Y){%
    \makebox(1,1.2){\parbox{.95\unitlength}{%
      \raggedleft\KakuroNumberFont
        #1 $\blacktriangleright$\\\mbox{}}}}
  \fi
  \Puzzle@pipe[][\KakuroHintType]{ }}%
\def\Kakuro@nohint#1:#2>{%
  \Puzzle@pipe[][,]{ }}%
\let\Kakuro@HINT\Kakuro@hint
\begingroup
\catcode`\|=13
\gdef\Kakuro#1#2{\begin{Puzzle}{#1}{#2}%
  \catcode`\|=13
  \let\Puzzle@pipe=|
  \let|=\Kakuro@cell
}
\endgroup
\def\endKakuro{\end{Puzzle}}
\def\KakuroHintType{,}
\PuzzleUnsolved
\DeclareOption{numbered}{\Puzzle@SolutionNumberedtrue}
\DeclareOption{nocenter}{\let\PuzzlePre=\relax
  \let\PuzzlePost=\relax}
\DeclareOption{unboxed}{\let\PuzzleCluePre=\relax
  \let\PuzzleCluePost=\relax}
\DeclareOption{normalsize}{\PuzzleUnitlength=20pt
  \def\PuzzleFont{\rmfamily\normalsize}}
\DeclareOption{small}{\PuzzleUnitlength=16pt
  \def\PuzzleFont{\rmfamily\small}}
\DeclareOption{large}{\PuzzleUnitlength=24pt
  \def\PuzzleFont{\rmfamily\large}}
\DeclareOption{german}{%
  \renewcommand\PuzzleWordsText[1]{Worte der L\"ange #1: }%
  \renewcommand\PuzzleLettersText{Benutzte Buchstaben: }%
}
\DeclareOption{ngerman}{%
  \renewcommand\PuzzleWordsText[1]{Worte der L\"ange #1: }%
  \renewcommand\PuzzleLettersText{Benutzte Buchstaben: }%
}
\ProcessOptions\relax
\endinput
%%
%% End of file `cwpuzzle.sty'.
