logicpuzzle

A LaTeX style file for typesetting logic puzzles

bokkusu

Bokkusu

The puzzle

Black out some of the grid cells. The numbers on the left and the bottom edge of the grid indicate the values of the cells for adding up. The numbers on the right and the top edge of the grid specify the sums of the values of the colored cells. Here’s a little self-explanatory example:

bokkusu.tex
\begin{center}
\begin{bokkusu}
\valueH{1,2,3,4,5}
\valueV{1,2,3,4,5}
\sumH{7,1,11,9,6}
\sumV{2,12,5,13,?}
\end{bokkusu}
\hspace{1cm}
\begin{bokkusu}
\valueH{1,2,3,4,5}
\valueV{1,2,3,4,5}
\sumH{7,1,11,9,6}
\sumV{2,12,5,13,?}
\fillrow{5}{0,0,1,0,0}
\fillrow{4}{1,0,1,1,1}
\fillrow{3}{1,0,0,1,0}
\fillrow{2}{0,0,1,1,1}
\fillrow{1}{0,1,0,0,0}
\end{bokkusu}
\end{center}

Options

• rows (5) defines the number of rows in the grid

• columns (5) specifies the number of columns in the grid

• width (6.7cm) sets the width of the minipage, in which the grid is typeset

• scale (1) scales the size of the grid in the minipage

• fontsize (Large) specifies the size of the numbers next to the grid. Here, the usual LaTeX sizes are used. Possible values: tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge

• title () sets the title of a puzzle

• titleindent (0.75cm) defines the indent of the title

• titlewidth (5.85cm) specifies the width of the box the title is set in

• color (black) specifies the color for coloring the cells

• bgcolor () sets the background color of the grid

• counterstyle (none) defines the counter style. Predefined styles: none, left, right

• cvoffset (-38pt) sets the vertical offset of the counters in the margin

Environments

bokkusu

\begin{bokkusu}

\end{bokkusu}


The environment 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.

Commands

In the grid and around

valueH

\valueH{csv list}

The command typesets the numbers left to the grid indicating the values of the cells. It expects a comma-separated list as an argument.

valueV

\valueV{csv list}

The command typesets the numbers below the grid specifying the values of the cells. It also expects a comma separated list.

sumH

\sumH{csv list}

The command typesets the numbers right to the grid indicating the sums of the values of the colored cells. It expects a comma-separated list.

sumV

\sumV{csv list}

The command typesets the numbers above the grid specifying the sums of the values of the colored cells. It expects a comma separated list.

fillcell

\fillcell{column}{row}

The command fills the grid cell {column}{row} with the color specified with the option color.

fillrow

\fillrow{row}{csv list}

The command fills the grid row {row}. In {csv list} 1 means ’fill’ and 0 means ’don’t fill’.

fillcolumn

\fillcolumn{column}{csv list}

The command fills a grid column.

Presentation

definecounterstyle

The command allows you to define your own styles. For example, the style left is defined as follows:

\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}
}


To typeset the counter into the margin we use the command \marginnote. We need to use the command \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 \puzzlecounter in a \tikz node with a vertical offset set with the option cvoffset.

puzzlecounter

\puzzlecounter

The command provides the counter in textual form to use it for example in \definecounterstyle.

titleformat

\titleformat{format}

With the command \titleformat, you can define the format of the title. By default, the definition is as follows:

\titleformat{\centering\Large\color{blue}}

Miscellaneous

bokkususetup

\bokkususetup{options}

With the command you can reset the options with global scope.

setpuzzlecounter

\setpuzzlecounter{number}

With the command , you can reset the puzzle counter, for example before the solutions.

Examples & Solutions

You can download application examples and their solutions from the project page. The puzzles are originally licensed under CC-BY-NC-SA.