diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx | 369 |
1 files changed, 356 insertions, 13 deletions
diff --git a/Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx b/Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx index d97e650f3dc..efd2c7d27ac 100644 --- a/Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx +++ b/Master/texmf-dist/source/latex/crossword/cwpuzzle.dtx @@ -1,10 +1,10 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% $Id: cwpuzzle.dtx,v 1.7 2009/09/06 15:16:53 gene Exp gene $ +%% $Id: cwpuzzle.dtx,v 1.8 2009/09/13 08:32:34 gene Exp gene $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\CWP@RCS$#1: #2 #3${#2} \def\filename{cwpuzzle.dtx} -\xdef\fileversion{\CWP@RCS$Revision: 1.7 $} -\xdef\filedate{\CWP@RCS$Date: 2009/09/06 15:16:53 $} +\xdef\fileversion{\CWP@RCS$Revision: 1.8 $} +\xdef\filedate{\CWP@RCS$Date: 2009/09/13 08:32:34 $} \let\docversion=\fileversion \let\docdate=\filedate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -12,7 +12,7 @@ \typeout{% %% Purpose: Package: cwpuzzle \filedate\space\fileversion\space - for typesetting crossword puzzles. + for typesetting crossword puzzles and more. }% %% %% Documentation: @@ -59,7 +59,7 @@ %\fi % % \title{A \LaTeX\ Package for Typesetting\\ Crossword -% Puzzles\thanks{This file documents \filename\ version +% Puzzles and More\thanks{This file documents \filename\ version % \fileversion\ as of \filedate.}} % \author{Gerd Neugebauer\\ % Im Lerchels\"ohl 5\\ @@ -73,22 +73,23 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% \DoNotIndex{\ ,\",\',\.,\,,\[,\\,\],\^,\`,\~,\@,\@dottedtocline} +% \DoNotIndex{\ ,\|,\",\',\.,\,,\[,\\,\],\^,\`,\~,\@,\@dottedtocline} % \DoNotIndex{\@empty,\@namedef,\@nameuse,\advance,\begin,\begingroup} % \DoNotIndex{\catcode,\csname,\def,\else,\end,\endcsname,\endgroup} % \DoNotIndex{\fi,\filedate,\footnotesize,\framebox,\gdef,\global} % \DoNotIndex{\hfill,\if,\ifx,\large,\let,\makebox,\mbox,\newcommand} % \DoNotIndex{\newcount,\newdimen,\newenvironment,\newif,\noindent} -% \DoNotIndex{\normalsize,\null,\par,\put,\relax,\renewcommand,\rm,\rule} +% \DoNotIndex{\normalsize,\null,\par,\put,\raggedright,\raggedleft} +% \DoNotIndex{\relax,\renewcommand,\RequirePackage,\rm,\rule} % \DoNotIndex{\scriptsize,\sf,\small,\textsf,\textwidth} -% \DoNotIndex{\the,\unitlength,\uppercase,\xdef,\ProvidesPackage} +% \DoNotIndex{\the,\tiny,\unitlength,\uppercase,\xdef,\ProvidesPackage} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % \changes{1.3}{1996/10/28}{First public release.} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \CheckSum{469} +% \CheckSum{637} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% \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 @@ -646,7 +647,6 @@ % \end{PuzzleClues}% % \end{minipage}% % -% % \DescribeEnv{PuzzleClues} % The clues in the classical crossword puzzle are typeset with the % use of the environment |PuzzleClues|. This environment takes one @@ -719,6 +719,159 @@ % \end{verbatim} % % +% \section{Other Grid-based Puzzles} +% +% In addition to the crossword puzzles other puzzles based on a +% grid can also be typeset with this package. The basic principle +% is the same. Just some minor simplifications have been provided. +% +% \subsection{Sudoku} +% +% A Sudoku is a puzzle on a $9\times9$ grid. It is filled with nine +% numbers. Each number occurs only once in each row, each column +% and each of the nine $3\times3$ boxes. Initially some of the +% numbers are shown. The goal is to fill in all missing digits. +% \medskip +% +% \begin{Sudoku} +% | 7|*2| 4| 1| 3| 5| 6|*9| 8|. +% |*3| 8|*1|*9| 7|*6|*5| 4|*2|. +% | 9| 6| 5|*8| 2|*4| 1| 3| 7|. +% | 2|*9| 6| 7| 1| 8| 3|*5| 4|. +% |*5| 1| 8|*2| 4|*3| 9| 7|*6|. +% | 4|*7| 3| 6| 5| 9| 8|*2| 1|. +% | 6| 3| 9|*4| 8|*7| 2| 1| 5|. +% |*8| 4|*2|*5| 9|*1|*7| 6|*3|. +% | 1|*5| 7| 3| 6| 2| 4|*8| 9|. +% \end{Sudoku} +% +% \DescribeEnv{Sudoku} +% The input for a Sudoku is given in a specialized environment. +% Since the size is fixed there is no need to specify a size. We +% separate the cells with a pipe symbol and mark the end of a line +% with a dot. To mark those cells contianing the hints we preceed +% the number with an asterisk. +% +% The Sudoku shown above is typeset from the following source: +% +% \begin{verbatim} +% \begin{Sudoku} +% | 7|*2| 4| 1| 3| 5| 6|*9| 8|. +% |*3| 8|*1|*9| 7|*6|*5| 4|*2|. +% | 9| 6| 5|*8| 2|*4| 1| 3| 7|. +% | 2|*9| 6| 7| 1| 8| 3|*5| 4|. +% |*5| 1| 8|*2| 4|*3| 9| 7|*6|. +% | 4|*7| 3| 6| 5| 9| 8|*2| 1|. +% | 6| 3| 9|*4| 8|*7| 2| 1| 5|. +% |*8| 4|*2|*5| 9|*1|*7| 6|*3|. +% | 1|*5| 7| 3| 6| 2| 4|*8| 9|. +% \end{Sudoku} +% \end{verbatim} +% +% As for crossword puzzles the macro |\PuzzleSolution| can be used +% to switch to solution mode. Then all numbers are shown. The +% parameters to modify the appearance of a puzzle work here as well. \medskip +% +% {\PuzzleSolution\PuzzleUnitlength=14pt\footnotesize\sf +% \begin{Sudoku} +% | 7|*2| 4| 1| 3| 5| 6|*9| 8|. +% |*3| 8|*1|*9| 7|*6|*5| 4|*2|. +% | 9| 6| 5|*8| 2|*4| 1| 3| 7|. +% | 2|*9| 6| 7| 1| 8| 3|*5| 4|. +% |*5| 1| 8|*2| 4|*3| 9| 7|*6|. +% | 4|*7| 3| 6| 5| 9| 8|*2| 1|. +% | 6| 3| 9|*4| 8|*7| 2| 1| 5|. +% |*8| 4|*2|*5| 9|*1|*7| 6|*3|. +% | 1|*5| 7| 3| 6| 2| 4|*8| 9|. +% \end{Sudoku}} +% +% +% \subsection{Kakuro} +% +% In a Kakuro the cells are filled with digits. Each ``word'' +% consists of different digits; i.e. a number can not be repeated +% in a consecutive horizontal or vertical sequence of numbers. +% +% The hints for the ``words'' are the sums of the digits. +% +% \begin{Kakuro}{6}{9} +% | - |<:13> |<:37> | - |<:41> |<:7> | - |. +% |<4:> |* 3 | 1 |<14:> | 8 | 6 | - |. +% |<13:> | 9 |* 7 |<3:20>| 2 | 1 | - |. +% |<11:> | 1 | 2 | 3 | 5 | - | - |. +% | - |<23:> | 6 |* 8 | 9 | - | - |. +% | - |<29:3>| 8 | 9 | 7 | 5 | - |. +% |<11:> | 2 | 9 |<6:> |* 4 | 2 | - |. +% |<5:> |* 1 | 4 |<7:> | 6 | 1 | - |. +% | - | - | - | - | - | - | - |. +% \end{Kakuro} +% +% \DescribeEnv{Kakuro} +% The input for a Kakuro is given in a specialized environment. It +% takes the width and the height as arguments. +% We separate the cells with a pipe symbol and mark the end of a line +% with a dot. To mark those cells contianing the initial digits we +% preceed the digit with an asterisk. +% +% The hints are enteres in angle brackets. They contain the +% horizontal and vertical sums separated by a colon. The sums can +% be empty if none should be typeset. +% +% The Kakuro shown above is typeset from the following source: +% +% \begin{verbatim} +% \begin{Kakuro}{6}{9} +% | - |<:13> |<:37> | - |<:41> |<:7> | - |. +% |<4:> |* 3 | 1 |<14:> | 8 | 6 | - |. +% |<13:> | 9 |* 7 |<3:20>| 2 | 1 | - |. +% |<11:> | 1 | 2 | 3 | 5 | - | - |. +% | - |<23:> | 6 |* 8 | 9 | - | - |. +% | - |<29:3>| 8 | 9 | 7 | 5 | - |. +% |<11:> | 2 | 9 |<6:> |* 4 | 2 | - |. +% |<5:> | 1 | 4 |<7:> | 6 | 1 | - |. +% | - | - | - | - | - | - | - |. +% \end{Kakuro} +% \end{verbatim} +% +% As for crossword puzzles the macro |\PuzzleSolution| can be used +% to switch to solution mode. Then all numbers are shown. +% +% \begin{minipage}{.25\textwidth} +% {\PuzzleSolution +% \PuzzleUnitlength=14pt +% \footnotesize\sf +% \begin{Kakuro}{6}{9} +% | - |<:13> |<:37> | - |<:41> |<:7> | - |. +% |<4:> |* 3 | 1 |<14:> | 8 | 6 | - |. +% |<13:> | 9 |* 7 |<3:20>| 2 | 1 | - |. +% |<11:> | 1 | 2 | 3 | 5 | - | - |. +% | - |<23:> | 6 |* 8 | 9 | - | - |. +% | - |<29:3>| 8 | 9 | 7 | 5 | - |. +% |<11:> | 2 | 9 |<6:> |* 4 | 2 | - |. +% |<5:> | 1 | 4 |<7:> | 6 | 1 | - |. +% | - | - | - | - | - | - | - |. +% \end{Kakuro}} +% \end{minipage}\hfill +% \begin{minipage}{.7\textwidth}\footnotesize +% \begin{verbatim} +% \PuzzleSolution +% \PuzzleUnitlength=14pt +% \footnotesize\sf +% \begin{Kakuro}{6}{9} +% | - |<:13> |<:37>| - |<:41>|<:7> | - |. +% |<4:> |* 3 | 1 |<14:> | 8 | 6 | - |. +% |<13:>| 9 |* 7 |<3:20>| 2 | 1 | - |. +% |<11:>| 1 | 2 | 3 | 5 | - | - |. +% | - |<23:> | 6 |* 8 | 9 | - | - |. +% | - |<29:3>| 8 | 9 | 7 | 5 | - |. +% |<11:>| 2 | 9 |<6:> |* 4 | 2 | - |. +% |<5:> | 1 | 4 |<7:> | 6 | 1 | - |. +% | - | - | - | - | - | - | - |. +% \end{Kakuro} +% \end{verbatim} +% \end{minipage} +% +% % \section{Parameters and Options} % % The package cwpuzzle can be controlled by a rich set of macros. @@ -900,9 +1053,22 @@ % This macro contains the content of a cell during formatting this % cell. This enables the cell formating macro to access it. % +% \DescribeMacro{\SudokuLinethickness} +% This macro contains the thickness of the thick lines in a sudoku. +% +% \DescribeMacro{\KakuroNumberFont} +% This macro contains the definition of the font switching macros +% used when typesetting a Kakuro hint. +% +% \DescribeMacro{\KakuroHintTypeKakuroNumberFont} +% This macro contains the cell type used when typesetting a Kakuro +% hint. It can be used to redefine the appearance. +% % % \section{Further Plans} % +% \subsection{General} +% % Maybe I will add a mode for further variants of crossword puzzles % sometimes. % @@ -922,9 +1088,8 @@ % since this program requires dictionaries which I can not % distribute legally. % -% The examples in this documentation have been computed with the -% help of the |cwp| program. -% +% The crossword examples in this documentation have been computed +% with the help of the |cwp| program. % % % \StopEventually{} @@ -950,6 +1115,11 @@ % \begin{macrocode} \ProvidesPackage{cwpuzzle}[\filedate gene] % \end{macrocode} +% Next we load the package amssymb beended for the triangles used +% in Kakuros +% \begin{macrocode} +\RequirePackage{amssymb} +% \end{macrocode} % % The dimen register |\PuzzleUnitlength| stores the height and % width of a box of the puzzle. The default is |20pt| which is @@ -1692,6 +1862,7 @@ % \begin{macrocode} \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 @@ -1707,6 +1878,7 @@ % letters are suppressed and the clues are shown. % \begin{macrocode} \newcommand\PuzzleUnsolved{% + \let\Kakuro@HINT\Kakuro@hint \let\PuzzleClues\Puzzle@Clues@@normal \let\endPuzzleClues\endPuzzle@Clues@@normal \let\PuzzleWords\Puzzle@Words@@normal @@ -1724,6 +1896,177 @@ \Puzzle@SolutionNumberedfalse % \end{macrocode} % +% \subsection{Sudoku} +% +% The challenge for the sudoku is to implement a convenient input syntax. +% +% \begin{environment}{Sudoku} +% The environemnt |Sudoku| is used to typeset the puzzle. +% The implementation defines the begin and end macro separately. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\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 +% \end{macrocode} +% +% The macro |\endSudoku| contains the code to be expanded at the +% end of the environment. It draws the field with the $3\times3$ +% boxes. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\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}} +% \end{macrocode} +% \end{environment} +% +% \begin{macro}{\SudokuLinethickness} +% The macro |\SudokuLinethickness| contains the thickness od thick +% lines in a Sudoku. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\newcommand\SudokuLinethickness{2pt} +% \end{macrocode} +% \end{macro} +% +% +% \subsection{Kakuro} +% +% \begin{macro}{\KakuroNumberFont} +% The macro |\KakuroNumberFont| is used to typeset the hints, i.e. +% the horizontal and vertical sums. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\newcommand\KakuroNumberFont{\sf\tiny} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@cell} +% The macro |\Kakuro@cell| is used to typeset the cells. It +% analyzes the argument and acts accordingly. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\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 +}% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@always} +% The macro |\Kakuro@always| is used to draw a cell with an inital number. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\def\Kakuro@always{\Puzzle@pipe[][fS]}% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@empty} +% The macro |\Kakuro@empty| is used to drae an empty cell. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\def\Kakuro@empty{\Puzzle@pipe{}}% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@hint} +% The macro |\Kakuro@hint| is used to draw hints. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\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]{ }}% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@nohint} +% The macro |\Kakuro@nohint| is used to suppress hints in solution mode. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\def\Kakuro@nohint#1:#2>{% + \Puzzle@pipe[][,]{ }}% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\Kakuro@HINT} +% The macro |\Kakuro@HINT| contains the definition to be used to +% typeset hints. This indirection is needed to suppress hints in +% solution mode. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\let\Kakuro@HINT\Kakuro@hint +% \end{macrocode} +% \end{macro} +% +% +% \begin{environment}{Kakuro} +% The environemnt |Kakuro| is used to typeset the puzzle. +% The implementation defines the begin and end macro separately to +% cope with catcode changes. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\begingroup +\catcode`\|=13 +\gdef\Kakuro#1#2{\begin{Puzzle}{#1}{#2}% + \catcode`\|=13 + \let\Puzzle@pipe=| + \let|=\Kakuro@cell +} +\endgroup +% \end{macrocode} +% +% The macro |\endKakuro| contains the code to be expanded at the +% end of the environment. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\def\endKakuro{\end{Puzzle}} +% \end{macrocode} +% \end{environment} +% +% \begin{macro}{\KakuroHintType} +% The macro |\KakuroHintType| contains the cell type for +% typesetting hint cells. It can be used to achieve a different +% look and feel. +% \changes{1.8}{2009/09/13}{New} +% \begin{macrocode} +\def\KakuroHintType{,} +% \end{macrocode} +% \end{macro} +% +% +% \subsection{Initialization} % % Finally we arrange that the default behavior is to typeset an % unsolved crossword puzzle. |