% pdflatex --shell-escape logo.tex
% run twice: 1. download qrcode.png 2. include the pic
% or download http://i.imgur.com/KAunnuS.png and rename it to qrcode.png
%
\documentclass[a4paper]{ltxdoc}%
\usepackage[english]{babel}%
\usepackage[latin1]{inputenc}%
\usepackage[T1]{fontenc}%
\usepackage{textcomp}%
\usepackage{lmodern}%
\usepackage{bera}%
\usepackage{makeidx}
\usepackage{ccicons}
\usepackage{tabularx}
\usepackage{microtype}%
\usepackage{ltxdocext}%
\usepackage{listings}
\usepackage{marginnote}%
\usepackage[svgnames,rgb]{xcolor}%
\usepackage[automark,nouppercase]{scrpage2}
\usepackage[width=5cm,scale=0.84,fontsize=normalsize]{chaossudoku}%
\usepackage{hyperref}
%
\setlength{\headheight}{1.1\baselineskip}%
%
\let\PrintIndex\relax
\makeindex
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
            {-2.5ex\@plus -1ex \@minus -.25ex}%
            {1.25ex \@plus .25ex}%
            {\normalfont\normalsize\bfseries}}
\makeatother
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\makeatother
\AtBeginDocument{\IfFileExists{qrcode.png}{}{\write18{wget -O qrcode.png http://i.imgur.com/KAunnuS.png}}}%
\hypersetup{colorlinks=true,urlcolor=NavyBlue,linkcolor=NavyBlue,citecolor=CornflowerBlue,naturalnames=true,hypertexnames=false}%
\lstset{language=[LaTeX]TeX,numbers=left,numberstyle=\tiny,basicstyle=\ttfamily,aboveskip=\baselineskip,frame=single,backgroundcolor=\color{LightGoldenrodYellow},keywordstyle=\color{Blue},emph={battleship,puzzlebackground,puzzleforeground,center,pgfonlayer,chaossudoku,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,layer,clor,bgcolor,counterstyle,title,titleindent,titlewidth,cvoffset,width},emphstyle={[2]\color{OliveDrab}},morekeywords={LP@definecolor,LP@define@choicekey@fontsize,ExecuteOptionsX,ProcessOptionsX,LP@init@counter,valueH,valueV,sumH,sumV,LP@bottomrow,LP@toprow,LP@rightcolumn,bokkususetup,setkeys,LP@set@package,LP@set@env@prefix,ifthenelse,equal,LP@drawbackground,LP@drawgrid,LP@drawcounter,ProvidesPackage,RequirePackage,LP@BK@init@prefix,LP@BK@init@package,LP@leftcolumn,skylineL,LP@define@key,framearea,fillarea,chaossudokucell,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%
            {\usebox\logo};%
          \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{#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{logicpuzzle.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\layer{\name@idx{PGF layer}}
\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{\hbadness=10000\RaggedLeft\scriptsize #1}}%
\newcommand*\package[1]{\texttt{#1}\index{#1=\string\ttt{#1}}}%
\DeclareRobustCommand{\marg}[1]{%
 \meta{#1}%
 \index{#1=\string\meta{#1} mandatory argument}\index{mandatory argument>#1=\string\meta{#1}}%
}%
\DeclareRobustCommand{\oarg}[1]{%
 \meta{#1}%
 \index{#1=\string\meta{#1} optional argument}\index{optional argument>#1=\string\meta{#1}}%
}%
%
\renewcommand\@biblabel[1]{\makebox[1.5cm][l]{[#1]}}
\renewcommand*\l@paragraph{\@dottedtocline{3}{7em}{4.7em}}
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \columnseprule \z@
                \columnsep 35\p@
\def\see##1##2{\textit{See} ##1}%
\def\seealso##1##2{\textit{See also} ##1}%
\long\def\cmd##1{\cs{\expandafter\cmd@to@cs\string##1}}%
\def\@url##1{\url@break\ttt{##1}\endgroup}%
\def\ttt{\begingroup\@sanitize\ttfamily\@ttt}%
\def\@ttt##1{##1\endgroup}%
\mathchardef\save@secnumdepth\c@secnumdepth
\c@secnumdepth\m@ne
                \phantomsection%
                \twocolumn%[\section{\indexname}]%
                %\addcontentsline{toc}{section}{Index}% 
\c@secnumdepth\save@secnumdepth
                %\thispagestyle{plain}
                \parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \let\item\@idxitem}
               {\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
%
\setlength\parindent{0pt}%
\hypersetup{pdfauthor={Josef Kleber},pdftitle={A style file for typesetting logic puzzles},pdfsubject={Documentation for LaTeX style \filename}}%
%
\begin{document}
\title{\filename}%
\Subtitle{A style file for typesetting logic puzzles}%
\author{Josef Kleber}
\Fileversion{v1.3}
\Refline{\href{mailto:josef.kleber@gmx.de}{\texttt{josef.kleber@gmx.de}}\\\href{https://bitbucket.org/kleberj/logicpuzzle/}{\texttt{https://bitbucket.org/kleberj/logicpuzzle/}}}
\newsavebox\logo
\savebox\logo{%
\begin{chaossudoku}
    \chaossudokucell{1}{1}{3}
    \chaossudokucell{1}{5}{4}
    \chaossudokucell{3}{2}{4}
    \chaossudokucell{4}{2}{5}
    \chaossudokucell{5}{5}{2}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,2)--(2,2)--(2,3)--(4,3)--(4,1)--(1,1)}
      \fillarea{HotPink!30}{(1,2)--(1,6)--(3,6)--(3,5)--(2,5)--(2,2)--(1,2)}
      \fillarea{LightYellow}{(2,3)--(2,5)--(3,5)--(3,4)--(5,4)--(5,2)--(4,2)--(4,3)--(2,3)}
      \fillarea{LightBlue}{(3,4)--(3,6)--(6,6)--(6,5)--(5,5)--(5,4)--(3,4)}
      \fillarea{GreenYellow}{(4,1)--(4,2)--(5,2)--(5,5)--(6,5)--(6,1)--(4,1)}
    \end{puzzlebackground} 
  \end{chaossudoku}
  \hspace{1,5cm}
  \begin{chaossudoku}
    \setrow{5}{4,3,5,1,2}
    \setrow{4}{2,1,3,4,5}
    \setrow{3}{5,4,2,3,1}
    \setrow{2}{1,2,4,5,3}
    \setrow{1}{3,5,1,2,4}
    \begin{puzzlebackground}
      \fillarea{Wheat}{(1,1)--(1,2)--(2,2)--(2,3)--(4,3)--(4,1)--(1,1)}
      \fillarea{HotPink!30}{(1,2)--(1,6)--(3,6)--(3,5)--(2,5)--(2,2)--(1,2)}
      \fillarea{LightYellow}{(2,3)--(2,5)--(3,5)--(3,4)--(5,4)--(5,2)--(4,2)--(4,3)--(2,3)}
      \fillarea{LightBlue}{(3,4)--(3,6)--(6,6)--(6,5)--(5,5)--(5,4)--(3,4)}
      \fillarea{GreenYellow}{(4,1)--(4,2)--(5,2)--(5,5)--(6,5)--(6,1)--(4,1)}
    \end{puzzlebackground} 
  \end{chaossudoku}
}
\maketitle
\stepcounter{page}
\tableofcontents
\clearpage
\setlength\parskip{6pt}%

\section{Roll out your own grid-based logic puzzle}
\label{sec:rollout}
As an example we take a look at the \package{bokkusu.sty} package. First, we ignore the LPPL license stuff.

\lstset{numbers=none,basicstyle=\ttfamily\footnotesize}%
\begin{lstlisting}
\ProvidesPackage{bokkusu}[2013/03/25 bokkusu.sty v1.2 - Josef Kleber (C) 2013]%
\RequirePackage{logicpuzzle}%
\end{lstlisting}

We wrote a package \package{bokkusu.sty} with version number v1.2 and date 2013/03/25 and added a copyright remark. We need to load the code base package \package{logicpuzzle.sty}.

\begin{lstlisting}
\newcommand*\LP@BK@init@prefix{LP@BK}%
\newcommand*\LP@BK@init@package{bokkusu}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{rows}{5}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{columns}{5}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{scale}{1}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{counterstyle}{none}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{color}{black}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{bgcolor}{}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{width}{6.7cm}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{cvoffset}{-38pt}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{title}{}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{titleindent}{0.75cm}%
\LP@define@key{\LP@BK@init@prefix}{\LP@BK@init@package}{titlewidth}{5.85cm}%
\LP@define@choicekey@fontsize{\LP@BK@init@prefix}{\LP@BK@init@package}{Large}%
\ExecuteOptionsX{rows,columns,width,fontsize,scale,color,bgcolor,cvoffset,
                 counterstyle,title,titleindent,titlewidth}%
\ProcessOptionsX\relax%
\LP@init@counter{\LP@BK@init@prefix}%
\end{lstlisting}

We save the package prefix and name in a macro for easy change. Then we define the options for package \package{bokkusu.sty} and the environment \env{bokkusu}, which are executed afterwards to create the macros for the option values. In the end, we need to initialize the package counters.

\begin{lstlisting}
\let\valueH\LP@bottomrow%
\let\valueV\LP@leftcolumn%
\let\sumH\LP@toprow%
\let\sumV\LP@rightcolumn%
\end{lstlisting}

We need numbers around the grid. Therefore, we define some aliases for the existing generic commands.

\begin{lstlisting}
\newcommand*\bokkususetup[1]%
{%
  \setkeys{bokkusu.sty}{#1}%
}%
\end{lstlisting}

We define \cmd\bokkususetup\ for resetting the global package options.

\clearpage
Finally, we define the \env{bokkusu} environment. 

\begin{lstlisting}
\newenvironment{bokkusu}[1][]%
{%
  \setkeys{bokkusu}{#1}%
  \LP@set@package{bokkusu}%
  \LP@set@env@prefix{LP@BK}%
  \setcounter{LP@BK@rows}{\LP@BK@rows}%
  \setcounter{LP@BK@columns}{\LP@BK@columns}%
  \stepcounter{LP@BK@rows}%
  \stepcounter{LP@BK@columns}%
\end{lstlisting}

We locally set the environment options and the prefix and name of the current puzzle environment. We need to reset the counters for \styleoption{rows} and \styleoption{columns}, as they might have been altered. 

\begin{lstlisting}
  \begin{minipage}[t]{\LP@BK@width}%
    \ifthenelse{\equal{\LP@BK@title}{}}%
    {\par\enspace\par}% empty
    {\enspace\par\noindent\hspace{\LP@BK@titleindent}\parbox{\LP@BK@titlewidth}
      {\strut\LP@titleformat\LP@BK@title}\vspace{3mm}\par}%
    \begin{tikzpicture}[scale=\LP@BK@scale]%
      \LP@drawbackground{1}{1}{\LP@BK@columns}{\LP@BK@rows}{\LP@BK@bgcolor}%
      \LP@drawgrid{1}{1}{\LP@BK@columns}{\LP@BK@rows}{1cm}%
}%
\end{lstlisting}

We start a minipage with width \marg{width}. If the user defined a title, we typeset the title and add a vertical space. Then, we draw the puzzle with the help of \package{tikz.sty}. We start drawing the background and the grid.

\begin{lstlisting}
{%
    \end{tikzpicture}%
    \LP@drawcounter{\LP@BK@counterstyle}%
    \stepcounter{LP@puzzlecounter}%
  \end{minipage}%
}%
\end{lstlisting}

Finally, we just end the picture for the puzzle. We draw and step the counter. As last action, we need to close the \env{minipage} environment. That's it. Easy, isn't it? You just need to copy this skelton and change or add some code for your specific puzzle.

\section{The code}
\label{sec:code}
\lstset{basicstyle=\ttfamily\normalsize}%

\subsection{PGF layers}
\label{sec:layer}
The \package{logicpuzzle.sty} package defines the following PGF layers: \layer{LPbgcolor}, \layer{LPbackgroundtwo}, \layer{LPbackground}, \layer{LPforeground} and \layer{LPforegroundtwo}

Without specifying a special layer, the standard \layer{main} layer is used. The \texttt{LPback\-ground} and \layer{LPforeground} layers can be accessed with the \env{puzzlebackground} [see: \ref{sec:puzzlebackground}] and \env{puzzleforeground} [see: \ref{sec:puzzleforeground}] environments.
The \layer{LPbgcolor} is and should only be used for the background color of the grid.

All layers can also be accessed with the generic PGF method:

\begin{lstlisting}
\begin{pgfonlayer}{layer}
  ...
\end{pgfonlayer}{layer}
\end{lstlisting}

\begin{tabularx}{\textwidth}{lX}
Order: & \layer{LPbgcolor} $\rightarrow$ \layer{LPbackgroundtwo} $\rightarrow$ \layer{LPbackground} $\rightarrow$ \layer{main} $\rightarrow$\newline \layer{LPforeground} $\rightarrow$ \layer{LPforegroundtwo} \\
\end{tabularx}

So, if you are in the need to place something behind \layer{LPbackground} or in front of \layer{LPforeground}, you can use the \layer{LPbackgroundtwo} and \layer{LPforegroundtwo} layers.

\subsection{Environments}
\label{sec:env}
\subsubsection{\texttt{puzzlebackground}}
\label{sec:puzzlebackground}
The \env{puzzlebackground} environment\marginnote{\hbadness=10000\RaggedLeft\scriptsize\envb{puzzlebackground}\\\dots\\\enve{puzzlebackground}} allows you to place elements behind the \layer{main} layer on the \layer{LPbackground} layer [see: \ref{sec:layer}]. This is for example usefull for the \cmd\fillarea\ [see: \ref{sec:fillarea}] command.
\subsubsection{\texttt{puzzleforeground}}
\label{sec:puzzleforeground}
The \env{puzzleforeground} environment\marginnote{\hbadness=10000\RaggedLeft\scriptsize\envb{puzzleforeground}\\\dots\\\enve{puzzleforeground}} allows you to place elements in front of the \layer{main} layer on the \layer{LPforeground} layer [see: \ref{sec:layer}]. This is for example usefull for the \cmd\framearea\ [see: \ref{sec:framearea}] command.

\subsection{Commands}
\label{sec:commands}
\subsubsection{Initialization}
\paragraph{\texorpdfstring{\cs{LP@define@key}}{\textbackslash LP@define@key}}
\label{sec:LPdefinekey}
With\margcs{\cmd\LP@define@key\{\marg{prefix}\}\\\{\marg{package}\}\{\marg{option}\}\{\marg{default}\}} the \cmd\LP@define@key\ command, you can define the options of the package \marg{package} \textbf{and} of the environment \marg{package}. A \marg{prefix} is needed for creating different name spaces.
\begin{lstlisting}
\LP@define@key{LP@BS}{battleship}{rows}{5}
\end{lstlisting}
This code snippet defines the option \styleoption{rows} as global option for \package{battleship.sty} and as local option for environment \env{battleship} with the default value 5. This value is stored in \cmd\LP@BS@rows.

\paragraph{\texorpdfstring{\cs{LP@define@choicekey@fontsize}}{\textbackslash LP@define@choicekey@fontsize}}
\label{sec:LPdefinechoicekeyfontsize}
With\margcs{\cmd\LP@define@choicekey@fontsize\\\{\marg{prefix}\}\{\marg{package}\}\{\marg{default}\}} the \cmd\LP@define@choicekey@fontsize\ command, you can define the choice key option \styleoption{fontsize} of the package \marg{package} \textbf{and} of the environment \marg{package}. Possible keys are: tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge

\paragraph{\texorpdfstring{\cs{LP@init@counter}}{\textbackslash LP@init@counter}}
\label{sec:LPinitcounter}
The command\margcs{\cmd\LP@init@counter\{\marg{prefix}\}} \cmd\LP@init@counter\ defines the counters \marg{prefix}@rows and \marg{prefix}@columns, initialize them with \textbackslash\marg{prefix}@rows\ and \textbackslash\marg{prefix}@columns\ and steps the counters. 

\subsubsection{Drawing grids}
\paragraph{\texorpdfstring{\cs{LP@drawgrid}}{\textbackslash LP@drawgrid}}
\label{sec:LPdrawgrid}
With\margcs{\cmd\LP@drawgrid\{\marg{xmin}\}\{\marg{ymin}\}\\\{\marg{xmax}\}\{\marg{ymax}\}\{\marg{step}\}} the \cmd\LP@drawgrid\ command, you can draw the grid (\marg{xmin},\marg{ymin}) to (\marg{xmax},\marg{ymax}) with step \marg{step}. For drawing the standard puzzle grid the step must be 1cm.

\paragraph{\texorpdfstring{\cs{LP@drawsudokugrid}}{\textbackslash LP@drawsudokugrid}}
\label{sec:LPdrawsudokugrid}
The\margcs{\cmd\LP@drawsudokugrid} command \cmd\LP@drawsudokugrid\ draws the stnadard Sudoku grid, but just the thicker lines. You will have to overlay the standard grid to get a full Sudoku grid. 

\paragraph{\texorpdfstring{\cs{LP@drawbackground}}{\textbackslash LP@drawbackground}}
\label{sec:LPdrawbackground}
With\margcs{\cmd\LP@drawbackground\{\marg{xmin}\}\\\{\marg{ymin}\}\{\marg{xmax}\}\{\marg{ymax}\}\{\marg{color}\}} the \cmd\LP@drawbackground\ command, you can draw the background color of the grid.

\subsubsection{In the grid}
\paragraph{\texorpdfstring{\cs{setcell}}{\textbackslash setcell}}
\label{sec:setcell}
With\margcs{\cmd\setcell\{\{\marg{column}\}\{\marg{row}\}\\\{\marg{element}\}} the \cmd\setcell\ command, you can set \marg{element} into cell \marg{column}\marg{row} as central node. It is aware of the current values of the surrounding environment options \styleoption{rows}, \styleoption{columns}, \styleoption{scale} and \styleoption{fontsize}. Furthermore, a check if \marg{element} is within the grid is applied.

\paragraph{\texorpdfstring{\cs{LP@setcellcontent}}{\textbackslash LP@setcellcontent}}
\label{sec:LPsetcellcontent}
The\margcs{\cmd\LP@LP@setcellcontent\{\marg{column}\}\\\{\marg{row}\}\{\marg{element}\}} command \cmd\LP@setcellcontent\ is the generic command to set an arbitrary \marg{element}.

\paragraph{\texorpdfstring{\cs{setrow}}{\textbackslash setrow}}
\label{sec:setrow}
With\margcs{\cmd\setrow\{\marg{row}\}\{\marg{csv list}\}} the \cmd\setrow\ command, you can set the contents of a \marg{row}. These may be numbers or letters. 

\paragraph{\texorpdfstring{\cs{LP@setrowcontents}}{\textbackslash LP@setrowcontents}}
\label{sec:LPsetrowcontents}
The\margcs{\cmd\LP@setrowcontents\{\marg{csv list}\}\\\{\marg{column}\}\{\marg{row}\}} command \cmd\LP@setrowcontents\ is the generic command to set row contents. It does not necessarily start with \marg{column} 1!

\paragraph{\texorpdfstring{\cs{setcolorrow}}{\textbackslash setcolorrow}}
\label{sec:setcolorrow}
With\margcs{\cmd\setcolorrow\{\marg{row}\}\{\marg{csv list}\}} the \cmd\setcolorrow\ command, you can set the contents of a \marg{row}. Furthermore, the background of the cell is filled with color \texttt{LP@c@romannumber} [see: \ref{sec:LPdefinecolor}]. With the number 0, you can black out the grid cell.

\paragraph{\texorpdfstring{\cs{setcolumn}}{\textbackslash setcolumn}}
\label{sec:setcolumn}
With\margcs{\cmd\setcolumn\{\marg{column}\}\{\marg{csv list}\}} the \cmd\setcolumn\ command, you can set the contents of a \marg{column}. These may be numbers or letters. 

\paragraph{\texorpdfstring{\cs{LP@setcolumncontents}}{\textbackslash LP@setcolumncontents}}
\label{sec:LPsetcolumncontents}
The\margcs{\cmd\LP@setcolumncontents\{\marg{csv list}\}\\\{\marg{column}\}\{\marg{row}\}} command \cmd\LP@setcolumncontents\ is the generic command to set column contents. It does not necessarily start with \marg{row} 1!

\paragraph{\texorpdfstring{\cs{setcolorcolumn}}{\textbackslash setcolorcolumn}}
\label{sec:setcolorcolumn}
With\margcs{\cmd\setcolorcolumn\\\{\marg{column}\}\{\marg{csv list}\}} the \cmd\setcolorcolumn\ command, you can set the contents of a \marg{column}. Furthermore, the background of the cell is filled with color \texttt{LP@c@romannumber} [see: \ref{sec:LPdefinecolor}].

\paragraph{\texorpdfstring{\cs{fillcell}}{\textbackslash fillcell}}
\label{sec:fillcell}
With\margcs{\cmd\fillcell\{\{\marg{column}\}\{\marg{row}\}} the \cmd\fillcell\ command, you can fill cell \marg{column}\marg{row} with the color defined with environment option \styleoption{color}\footnote{Therefore, you must define an option \styleoption{color} in the style file you want to use fill commands}. It is aware of the current values of the surrounding envionment options \styleoption{rows}, \styleoption{columns}, \styleoption{scale} and \styleoption{color}. Furthermore, a check if the cell is within the grid is applied.

\paragraph{\texorpdfstring{\cs{fillrow}}{\textbackslash fillrow}}
\label{sec:fillrow}
With\margcs{\cmd\fillrow\{\marg{row}\}\{\marg{csv list}\}} the \cmd\fillrow\ command, you can fill a \marg{row}. In \marg{csv list} '1' means 'fill' and '0' means 'don't fill'. Internally, \cmd\fillrow\ uses \cmd\fillcell\ [see: \ref{sec:fillcell}].

\paragraph{\texorpdfstring{\cs{fillcolumn}}{\textbackslash fillcolumn}}
\label{sec:fillcolumn}
With\margcs{\cmd\fillcolumn\{\marg{column}\}\{\marg{csv list}\}} the \cmd\fillcolumn\ command, you can fill a \marg{column}. In \marg{csv list} '1' means 'fill' and '0' means 'don't fill'. Internally, \cmd\fillcolumn\ uses \cmd\fillcell\ [see: \ref{sec:fillcell}].

\paragraph{\texorpdfstring{\cs{filldiagonals}}{\textbackslash filldiagonals}}
\label{sec:filldiagonals}
With\margcs{\cmd\filldiagonals[\oarg{color}]} the \cmd\filldiagonals\ command, you can fill the diagonals with the color specified with the optional argument \oarg{color} (default: yellow!20). Furthermore, it checks for a quadratic grid, otherwise an error message is issued.

\paragraph{\texorpdfstring{\cs{framearea}}{\textbackslash framearea}}
\label{sec:framearea}
The command \cmd\framearea\margcs{\cmd\framearea\{\marg{color}\}\{\marg{tikz path}\}} frames the area given by \marg{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} [see: \ref{sec:puzzleforeground}] environment.

\paragraph{\texorpdfstring{\cs{fillarea}}{\textbackslash fillarea}}
\label{sec:fillarea}
The command \cmd\fillarea\margcs{\cmd\fillarea\{\marg{color}\}\{\marg{tikz path}\}} fills the area given by \marg{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} [see: \ref{sec:puzzlebackground}] environment.

\paragraph{\texorpdfstring{\cs{framepuzzle}}{\textbackslash framepuzzle}}
\label{sec:framepuzzle}
With\margcs{\cmd\framepuzzle[\oarg{color}]} the \cmd\framepuzzle\ command, you can frame the grid (thicker line) with the color specified with the optional argument \oarg{color} (default: black).

\paragraph{\texorpdfstring{\cs{LP@ingrid}}{\textbackslash LP@ingrid}}
\label{sec:LPingrid}
With\margcs{\cmd\LP@ingrid\\\{\marg{column}\}\{\marg{row}\}\{\marg{max column}\}\\\{\marg{max row}\}\{\marg{package}\}} the \cmd\LP@ingrid\ command, you can check if an element -- that should be placed -- is within the grid. Otherwise an error message is issued.

\paragraph{\texorpdfstring{\cs{LP@definecolor}}{\textbackslash LP@definecolor}}
\label{sec:LPdefinecolor}
With\margcs{\cmd\LP@definecolor\\\{\marg{name}\}\{\marg{rgb color}\}} the \cmd\LP@definecolor\ command, you can define named rgb colors, especially for defining background colors of numbers used in \cmd\setcolorrow\ [see: \ref{sec:setcolorrow}] and \cmd\setcolorcolumn\ [see: \ref{sec:setcolorcolumn}].

The background color names follow the pattern: \texttt{LP@c@romannumber}

\begin{lstlisting}
\LP@definecolor{LP@c@iv}{.55,1,.88}
\end{lstlisting}

This command will define the new background color of number \colorbox[rgb]{.55,1,.88}{4}!

\subsubsection{Around the grid}
\paragraph{\texorpdfstring{\cs{LP@leftcolumn}}{\textbackslash LP@leftcolumn}}
\label{sec:LPleftcolumn}
With\margcs{\cmd\LP@leftcolumn\{\{\marg{csv list}\}} the \cmd\LP@leftcolumn\ command, you can set the contents of the column left to the grid. The \package{skyline.sty} package uses for example:

\begin{lstlisting}
\let\skylineL\LP@leftcolumn
\end{lstlisting}

\paragraph{\texorpdfstring{\cs{LP@rightcolumn}}{\textbackslash LP@rightcolumn}}
\label{sec:LPrightcolumn}
With\margcs{\cmd\LP@rightcolumn\{\{\marg{csv list}\}} the \cmd\LP@rightcolumn\ command, you can set the contents of the column right to the grid.

\paragraph{\texorpdfstring{\cs{LP@toprow}}{\textbackslash LP@toprow}}
\label{sec:LPtoprow}
With\margcs{\cmd\LP@toprow\{\{\marg{csv list}\}} the \cmd\LP@toprow\ command, you can set the contents of the row above the grid.

\paragraph{\texorpdfstring{\cs{LP@bottomrow}}{\textbackslash LP@bottomrow}}
\label{sec:LPbottomrow}
With\margcs{\cmd\LP@bottomrow\{\{\marg{csv list}\}} the \cmd\LP@bottomrow\ command, you can set the contents of the row below the grid. 

\subsubsection{Presentation}
\paragraph{\texorpdfstring{\cs{titleformat}}{\textbackslash titleformat}}
\label{sec:titleformat}
With\margcs{\cmd\titleformat\{\{\marg{format}\}} the \cmd\titleformat\ command, you can define the \marg{format} of the title. By default, the definition is as follows:

\begin{lstlisting}
\titleformat{\centering\Large\color{blue}}
\end{lstlisting}

\paragraph{\texorpdfstring{\cs{puzzlecounter}}{\textbackslash puzzlecounter}}
\label{sec:puzzlecounter}
The command \cs{puzzlecounter}\margcs{\cmd\puzzlecounter} provides the counter in textual form to use it for example in \cmd\definecounterstyle.

\paragraph{\texorpdfstring{\cs{setpuzzlecounter}}{\textbackslash setpuzzlecounter}}
\label{sec:setpuzzlecounter}
With the command \cs{setpuzzlecounter}\margcs{\cmd\setpuzzlecounter\{\marg{number}\}}, you can reset the puzzle counter, for example before the solutions.

\paragraph{\texorpdfstring{\cs{definecounterstyle}}{\textbackslash definecounterstyle}}
\label{sec: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}.

\paragraph{\texorpdfstring{\cs{LP@drawcounter}}{\textbackslash LP@drawcounter}}
\label{sec:LPdrawcounter}
The command \cs{LP@drawcounter}\margcs{\cmd\LP@drawcounter\{\marg{name}\}} draws the counter with counter style \marg{name}.

\section{Examples}
You\IfFileExists{qrcode.png}{\marginnote{\href{https://bitbucket.org/kleberj/logicpuzzle/}{\includegraphics[height=2cm]{qrcode.png}}}[-37pt]}{} 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}.
\clearpage
\Headline{Index}
\printindex
\end{document}
