summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/logicpuzzle/hakyuu/hakyuu.tex
blob: d4577cd2a2a74f9ee1b738d2ddf282859d1cb3a2 (plain)
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
\documentclass[a4paper]{ltxdoc}%
\usepackage[english]{babel}%
\usepackage[latin1]{inputenc}%
\usepackage[T1]{fontenc}%
\usepackage{textcomp}%
\usepackage{lmodern}%
\usepackage{bera}%
\usepackage{ccicons}
\usepackage{microtype}%
\usepackage{ltxdocext}%
\usepackage{listings}
\usepackage{marginnote}%
\usepackage[svgnames,rgb]{xcolor}%
\usepackage[automark,nouppercase]{scrpage2}
\usepackage[width=5cm,scale=0.84,fontsize=normalsize]{hakyuu}%
\usepackage{hyperref}
%
\setlength{\headheight}{1.1\baselineskip}%
%
\hypersetup{colorlinks=true,urlcolor=NavyBlue,linkcolor=NavyBlue,citecolor=CornflowerBlue,naturalnames=true,hypertexnames=false}%
\lstset{language=[LaTeX]TeX,numbers=left,numberstyle=\tiny,basicstyle=\ttfamily\scriptsize,frame=single,backgroundcolor=\color{LightGoldenrodYellow},keywordstyle=\color{Blue},emph={puzzlebackground,puzzleforeground,center,hakyuu,left,shape,fill,inner,sep,draw,rounded,corners,thick}, emphstyle=\color{Tomato},emph={[2]Wheat,HotPink,GreenYellow,LightBlue,LightSalmon,LightYellow,green,sudoku,rows,columns,scale},emphstyle={[2]\color{OliveDrab}},morekeywords={framearea,fillarea,hakyuucell,setrow,LP@cvoffset,titleformat,definecounterstyle,marginnote,tikz,node,puzzlecounter,color,[,]}}
\makeatletter
\renewcommand{\maketitle}%
{%
  \thispagestyle{empty}%
  \pagecolor{Ivory}%
  \begin{titlepage}%
    \begin{tikzpicture}[remember picture,overlay]%
      \node[yshift=-2cm] at (current page.north west)%
      {%
        \begin{tikzpicture}[remember picture, overlay]%
          \draw[fill=CornflowerBlue,color=CornflowerBlue] (0,0) rectangle%
            (\paperwidth,2cm);%
          \draw[anchor=west,yshift=-4cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\RaggedRight\Huge\sffamily\textbf{\@title}}};%
          \draw[anchor=west,yshift=-6cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\huge\sffamily\textbf{\@fileversion}}};%
          \draw[anchor=west,yshift=-9cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\RaggedRight\huge\sffamily\textbf{\@subtitle}}};%
          \draw[anchor=west,yshift=-13cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\includegraphics[height=5cm]{logo.png}};%
          \draw[anchor=west,yshift=-17cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\huge\sffamily\textbf{\@date}}};%
          \draw[anchor=west,yshift=-20cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\Large\sffamily{\@authorline\\\textbf{\@author}}}};%
        \end{tikzpicture}%
      };%
      \node[yshift=0cm] at (current page.south west)%
      {%
        \begin{tikzpicture}[remember picture, overlay]%
          \draw[fill=NavyBlue,color=NavyBlue,yshift=6cm,xshift=2cm] (0,0) rectangle (0.2cm,19cm);%
          \draw[fill=CornflowerBlue,color=CornflowerBlue] (0,0) rectangle (\paperwidth,2cm);%
          \draw[anchor=west,yshift=1cm,xshift=3cm,color=NavyBlue] (0,0) node%
            {\parbox{15cm}{\large\sffamily{\@refline}}};%
        \end{tikzpicture}%
      };%
    \end{tikzpicture}%
  \end{titlepage}%
  \pagecolor{white}%
}%
%
\newcommand*{\@tikzhead}[1]%
{%
  \begin{tikzpicture}[remember picture,overlay]%
    \node[yshift=-2cm] at (current page.north west)%
    {%
      \begin{tikzpicture}[remember picture, overlay]%
        \draw[fill=CornflowerBlue] (0,0) rectangle (\paperwidth,2cm);%
        \draw[anchor=west,yshift=1cm,xshift=1.5cm,color=NavyBlue] (0,0) node%
          {\parbox{15cm}{\LARGE\sffamily\textbf{\@title}}};%
        \node[anchor=east,xshift=.9\paperwidth,rectangle,%
              rounded corners=15pt,inner sep=11pt,fill=NavyBlue]%
              {\color{white}\textsc{#1}};%
      \end{tikzpicture}%
    };%
  \end{tikzpicture}%
}%
\clearscrheadings%
\ihead{\@tikzhead{\headmark}}%
\cfoot{\upshape\thepage}%
\pagestyle{scrheadings}%
%
%\newcommand*{\headline}[1]{\@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}%
\newcommand*{\Headline}[1]{\@mkboth{#1}{#1}}%
%
\renewcommand{\headfont}{\normalfont\mdseries\scshape}
%
\gdef\@subtitle{}%
\providecommand*{\Subtitle}[1]{\gdef\@subtitle{#1}}%
\gdef\@fileversion{}%
\providecommand*{\Fileversion}[1]{\gdef\@fileversion{#1}}%
\gdef\@author{}%
\providecommand*{\Author}[1]{\gdef\@author{#1}}%
\gdef\@authorline{Package author:}%
\providecommand*{\Authorline}[1]{\gdef\@authorline{#1}}%
\gdef\@refline{}%
\providecommand*{\Refline}[1]{\gdef\@refline{#1}}%
\gdef\and{\unskip{}, }%
\newcommand\doubledash{-\kern0.5pt-}
\def\enoteformat{\rightskip\z@ \leftskip\z@ \parindent=1em\leavevmode\llap{\makeenmark}}
\makeatother
%
\def\filename{hakyuu.sty}%
\def\XeLaTeX{Xe\LaTeX}%
%
\newenvironment{optionlist}
{\begin{trivlist}\setlength\leftskip{2em}}
{\end{trivlist}}
\newcommand\optitem[3]{\item [\texttt{\textbf{\textcolor{DodgerBlue}{#1}} \lbrack\textcolor{Crimson}{#2}\rbrack}] #3}
%
\makeatletter%
\renewcommand\tableofcontents%
{%
  %\section*{\contentsname}%
  \@mkboth{%
  \MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
  \@starttoc{toc}%
}%
%
\newcommand\styleoption{\name@idx{style option}}%
\newcommand\stylename{\name@idx{document style}}%
\def\name@idx#1#2{%
 {\ttfamily#2}%
 \index{#2\space#1=\string\ttt{#2}\space#1}\index{#1>#2=\string\ttt{#2}}%
}%
\newcommand*\margcs[1]{\marginnote{\raggedleft\scriptsize #1}}%
\newcommand*\package[1]{\texttt{#1}\index{#1=\string\ttt{#1}}}%
\newcommand*\mco[1]{\mbox{\LANGLE\itshape#1\RANGLE}\index{#1, class option value}\index{class option value>#1}}%
%
\renewcommand\@biblabel[1]{\makebox[1.5cm][l]{[#1]}}
%\renewcommand*\l@subsection{\@dottedtocline{2}{1.2em}{2.8em}}
%\renewcommand*\l@subsubsection{\@dottedtocline{3}{2.4em}{3.7em}}
\makeatother
%
\setlength\parindent{0pt}%
\hypersetup{pdfauthor={Josef Kleber},pdftitle={A style file for typesetting Hakyuu logic puzzles},pdfsubject={Documentation for LaTeX style \filename}}%
%
\begin{document}
\title{\filename}%
\Subtitle{A style file for typesetting Hakyuu logic puzzles}%
\author{Josef Kleber}
\Fileversion{v1.0}
\Refline{\href{mailto:josef.kleber@gmx.de}{\texttt{josef.kleber@gmx.de}}\\\href{https://bitbucket.org/kleberj/logicpuzzle/}{\texttt{https://bitbucket.org/kleberj/logicpuzzle/}}}
\maketitle
\tableofcontents
\clearpage

\section{The puzzle}

Fill the cells of an area with numbers from 1 to SIZE of the area. If there are two cells with the same number N in a row or a column, there must be at least N cells between those two cells. Here's a little self-explanatory example:

\begin{center}
  \begin{hakyuu}
    \hakyuucell{1}{5}{2}
    \hakyuucell{3}{5}{6}
    \hakyuucell{4}{5}{5}
    \hakyuucell{4}{4}{4}
    \hakyuucell{1}{3}{3}
    \hakyuucell{2}{2}{2}
    \hakyuucell{5}{2}{5}
    \hakyuucell{4}{1}{1}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,4)--(2,4)--(2,1)--(1,1)}
      \fillarea{HotPink!30}{(1,4)--(1,6)--(6,6)--(6,5)--(3,5)--(3,4)--(1,4)}
      \fillarea{GreenYellow}{(2,4)--(3,4)--(3,5)--(5,5)--(5,4)--(4,4)--(4,3)--(2,3)--(2,4)}
      \fillarea{LightBlue}{(5,5)--(6,5)--(6,3)--(4,3)--(4,4)--(5,4)--(5,5)}
      \fillarea{LightSalmon!50}{(2,2)--(2,3)--(5,3)--(5,2)--(2,2)}
      \fillarea{LightYellow}{(2,1)--(2,2)--(5,2)--(5,3)--(6,3)--(6,1)--(2,1)}
    \end{puzzlebackground} 
  \end{hakyuu}
  \hspace{1,5cm}
  \begin{hakyuu}
    \setrow{5}{2,3,6,5,4}
    \setrow{4}{1,7,3,4,2}
    \setrow{3}{3,1,2,1,3}
    \setrow{2}{1,2,1,3,5}
    \setrow{1}{2,3,4,1,2}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,4)--(2,4)--(2,1)--(1,1)}
      \fillarea{HotPink!30}{(1,4)--(1,6)--(6,6)--(6,5)--(3,5)--(3,4)--(1,4)}
      \fillarea{GreenYellow}{(2,4)--(3,4)--(3,5)--(5,5)--(5,4)--(4,4)--(4,3)--(2,3)--(2,4)}
      \fillarea{LightBlue}{(5,5)--(6,5)--(6,3)--(4,3)--(4,4)--(5,4)--(5,5)}
      \fillarea{LightSalmon!50}{(2,2)--(2,3)--(5,3)--(5,2)--(2,2)}
      \fillarea{LightYellow}{(2,1)--(2,2)--(5,2)--(5,3)--(6,3)--(6,1)--(2,1)}
    \end{puzzlebackground} 
  \end{hakyuu}
\end{center}

\bigskip
\begin{lstlisting}
\begin{center}
  \begin{hakyuu}
    \hakyuucell{1}{5}{2}
    \hakyuucell{3}{5}{6}
    \hakyuucell{4}{5}{5}
    \hakyuucell{4}{4}{4}
    \hakyuucell{1}{3}{3}
    \hakyuucell{2}{2}{2}
    \hakyuucell{5}{2}{5}
    \hakyuucell{4}{1}{1}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,4)--(2,4)--(2,1)--(1,1)}
      \fillarea{HotPink!30}{(1,4)--(1,6)--(6,6)--(6,5)--(3,5)--(3,4)--(1,4)}
      \fillarea{GreenYellow}{(2,4)--(3,4)--(3,5)--(5,5)--(5,4)--(4,4)--(4,3)--(2,3)--(2,4)}
      \fillarea{LightBlue}{(5,5)--(6,5)--(6,3)--(4,3)--(4,4)--(5,4)--(5,5)}
      \fillarea{LightSalmon!50}{(2,2)--(2,3)--(5,3)--(5,2)--(2,2)}
      \fillarea{LightYellow}{(2,1)--(2,2)--(5,2)--(5,3)--(6,3)--(6,1)--(2,1)}
    \end{puzzlebackground} 
  \end{hakyuu}
  \hspace{1,5cm}
  \begin{hakyuu}
    \setrow{5}{2,3,6,5,4}
    \setrow{4}{1,7,3,4,2}
    \setrow{3}{3,1,2,1,3}
    \setrow{2}{1,2,1,3,5}
    \setrow{1}{2,3,4,1,2}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,4)--(2,4)--(2,1)--(1,1)}
      \fillarea{HotPink!30}{(1,4)--(1,6)--(6,6)--(6,5)--(3,5)--(3,4)--(1,4)}
      \fillarea{GreenYellow}{(2,4)--(3,4)--(3,5)--(5,5)--(5,4)--(4,4)--(4,3)--(2,3)--(2,4)}
      \fillarea{LightBlue}{(5,5)--(6,5)--(6,3)--(4,3)--(4,4)--(5,4)--(5,5)}
      \fillarea{LightSalmon!50}{(2,2)--(2,3)--(5,3)--(5,2)--(2,2)}
      \fillarea{LightYellow}{(2,1)--(2,2)--(5,2)--(5,3)--(6,3)--(6,1)--(2,1)}
    \end{puzzlebackground} 
  \end{hakyuu}
\end{center}
\end{lstlisting}
\lstset{basicstyle=\ttfamily\normalsize}
\clearpage

\section{Options}
\begin{optionlist}
  \optitem{\styleoption{rows}}{5}{defines the number of rows in the grid.}
  \optitem{\styleoption{columns}}{5}{specifies the number of columns in the grid}
  \optitem{\styleoption{width}}{5.1cm}{sets the width of the minipage, in which the grid is typeset.}
  \optitem{\styleoption{scale}}{1}{scales the size of the grid in the minipage.}
  \optitem{\styleoption{fontsize}}{Large}{specifies the size of the numbers next to the grid. Here, the usual \LaTeX\ sizes are used. Possible values: \texttt{tiny}, \texttt{scriptsize}, \texttt{footnotesize}, \texttt{small}, \texttt{normalsize}, \texttt{large}, \underline{\texttt{Large}}, \texttt{LARGE}, \texttt{huge}, \texttt{Huge}}
  \optitem{\styleoption{title}}{}{sets the title of a puzzle.}
  \optitem{\styleoption{titleindent}}{0cm}{defines the indent of the title.}
  \optitem{\styleoption{titlewidth}}{5.1cm}{specifies the width of the box the title is set in.}
  \optitem{\styleoption{bgcolor}}{}{sets the background color of the grid.}
  \optitem{\styleoption{counterstyle}}{none}{defines the counter style. Predefined styles: none, left, right}
  \optitem{\styleoption{cvoffset}}{-22pt}{sets the vertical offset of the counters in the margin.}
\end{optionlist}

\section{Environments}
\subsection{\texttt{hakyuu}}
The \env{hakyuu} environment\marginnote{\hbadness=10000\RaggedLeft\scriptsize\envb{hakyuu}\oarg{options}\\\dots\\\enve{hakyuu}} is the central core of the style file. With the optional argument of the environment, you can reset the options with local scope. Here, a blank grid is created.
\subsection{\texttt{puzzlebackground}}
The \env{puzzlebackground} environment\marginnote{\hbadness=10000\RaggedLeft\scriptsize\envb{puzzlebackground}\\\dots\\\enve{puzzlebackground}} allows you to place elements behind the main layer. This is for example usefull for the \cmd\fillarea\ command.
\subsection{\texttt{puzzleforeground}}
The \env{puzzleforeground} environment\marginnote{\hbadness=10000\RaggedLeft\scriptsize\envb{puzzleforeground}\\\dots\\\enve{puzzleforeground}} allows you to place elements in front of the main layer. This is for example usefull for the \cmd\framearea\ command.
\clearpage
\section{Commands}
\subsection{In the grid and around}
\subsubsection{\texttt{hakyuucell}}
The command \cs{hakyuucell}\margcs{\cmd\hakyuucell\{\marg{column}\}\{\marg{row}\}\\\{\marg{number}\}} sets the \marg{number} of the grid cell \marg{column}\marg{row}.
\subsubsection{\texttt{setrow}}
The command \cs{setrow}\margcs{\cmd\setrow\{\marg{row}\}\{\marg{csv list}\}} sets the contents of \marg{row}. It expects a comma-separated list.
\subsubsection{\texttt{setcolumn}}
The command \cs{setcolumn}\margcs{\cmd\setcolumn\{\marg{column}\}\{\marg{csv list}\}} sets the contents of \marg{column}.
\subsubsection{\texttt{framearea}}
The command \cs{framearea}\margcs{\cmd\framearea\{\marg{color}\}\{\marg{\cmd\tikz\ path}\}} frames the area given by \marg{\cmd\tikz\ path} with color \marg{color}. The reference for coordinates is the bottom left corner of the cell.

\begin{lstlisting}
\framearea{green}{(2,2)--(2,3)--(3,3)--(3,2)--(2,2)}
\end{lstlisting}

This command will color the frame of the grid cell \texttt{(2,2)} green. You should consider using this command in the \env{puzzleforeground} environment.

\subsubsection{\texttt{fillarea}}
The command \cs{fillarea}\margcs{\cmd\fillarea\{\marg{color}\}\{\marg{\cmd\tikz\ path}\}} fills the area given by \marg{\cmd\tikz\ path} with color \marg{color}. The reference for coordinates is the bottom left corner of the cell. You should consider using this command in the \env{puzzlebackground} environment.
\subsection{Presentation}
\subsubsection{\texttt{definecounterstyle}}
The command \cs{definecounterstyle}\margcs{\cmd\definecounterstyle\{\marg{name}\}\\\{\marg{definition}\}} allows you to define your own styles. For example, the style \texttt{left} is defined as follows:

\begin{lstlisting}
\definecounterstyle{left}{
  \begingroup\reversemarginpar\marginnote{
  \tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,
             draw,rounded corners=3pt,thick]
  {\Huge\puzzlecounter};}[\LP@cvoffset]\endgroup}
}
\end{lstlisting}

To typeset the counter into the margin we use the command \cmd\marginnote. We need to use the command \cmd\reversemarginpar\ to set the counter into the left margin. Of course, we must use this command in a group for local scope. Finally we use \cmd\puzzlecounter\ in a \cmd\tikz\ node with a vertical offset set with the option \styleoption{cvoffset}.
\subsubsection{\texttt{puzzlecounter}}
The command \cs{puzzlecounter}\margcs{\cmd\puzzlecounter} provides the counter in textual form to use it for example in \cmd\definecounterstyle.
\subsubsection{\texttt{titleformat}}
With the command \cs{titleformat}\margcs{\cmd\titleformat\{\marg{format}\}}, you can define the format of the title. By default, the definition is as follows:

\begin{lstlisting}
\titleformat{\centering\Large\color{blue}}
\end{lstlisting}
\subsection{Miscellaneous}
\subsubsection{\texttt{hakyuusetup}}
With the command \cs{hakyuusetup}\margcs{\cmd\hakyuusetup\{\marg{options}\}} you can reset the options with global scope.
\subsubsection{\texttt{setpuzzlecounter}}
With the command \cs{setpuzzlecounter}\margcs{\cmd\setpuzzlecounter\{\marg{number}\}}, you can reset the puzzle counter, for example before the solutions.

\section{Examples \& Solutions}
You\marginnote{\href{https://bitbucket.org/kleberj/logicpuzzle/}{\includegraphics[height=2cm]{qrcode.png}}} can download application examples and their solutions from the \href{https://bitbucket.org/kleberj/logicpuzzle/}{project page}. The puzzles are originally licensed under \href{http://creativecommons.org/licenses/by-nc-sa/3.0/}{\ccbyncsa}.
\end{document}