logicpuzzle

A LaTeX style file for typesetting logic puzzles

Sidebar

CTAN

Bitbucket

jkLaTeX

TeXdoku

——

The TeX community aggregator

Impressum / Datenschutzerklärung

lpsudoku

lpsudoku.sty

The puzzle

Well, it’s Sudoku – nothing to explain! Fill each row and column with numbers from 1 to 9. Here’s a little self-explanatory example:

\begin{center}
\begin{lpsudoku}
\setrow{9}{{},2,6,{},{},{},{},{},{}}
\setrow{8}{{},{},{},{},{},{},1,7,{}}
\setrow{7}{{},{},3,1,{},6,{},{},{}}
\setrow{6}{{},6,{},{},5,{},8,{},3}
\setrow{5}{{},{},9,2,6,1,7,{},{}}
\setrow{4}{5,{},4,{},8,{},{},6,{}}
\setrow{3}{{},{},{},8,{},4,3,{},{}}
\setrow{2}{{},4,8,{},{},{},{},{},{}}
\setrow{1}{{},{},{},{},{},{},9,4,{}}
\end{lpsudoku}
\hspace{1,5cm}
\begin{lpsudoku}
\setrow{9}{1,2,6,5,7,8,4,3,9}
\setrow{8}{4,8,5,9,3,2,1,7,6}
\setrow{7}{7,9,3,1,4,6,5,8,2}
\setrow{6}{2,6,1,4,5,7,8,9,3}
\setrow{5}{8,3,9,2,6,1,7,5,4}
\setrow{4}{5,7,4,3,8,9,2,6,1}
\setrow{3}{6,5,2,8,9,4,3,1,7}
\setrow{2}{9,4,8,7,1,3,6,2,5}
\setrow{1}{3,1,7,6,2,5,9,4,8}
\end{lpsudoku}
\end{center}


Options

• width (9.1cm) 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 (0cm) defines the indent of the title

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

• bgcolor () sets the background color of the grid

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

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

Environments

lpsudoku

\begin{lpsudoku}

\end{lpsudoku}


The lpsudoku 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

lpsudokucell

lpsudokucell{column}{row}{number}

The command sets the {number} of the grid cell {column}{row}.

setrow

\setrow{row}{csv list}

The command sets the contents of {row}. It expects a comma-separated list.

setcolumn

\setcolumn{column}{csv list}

The command sets the contents of {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

lpsudokusetup

\lpsudokusetup{options}

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

setpuzzlecounter

\setpuzzlecounter{number}

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

Supporting bash scripts

createlpsudoku

The createlpsudoku bash script can transform Sudoku format files into lpsudoku environments. It can process files in the so called one line 81 format (option -e (default)) and in simple sudoku format (option -s)

Usage: createlpsudoku [options] [-o output] -i input

It expects an input file with the option -i. You can specify an output file with the option -o. Otherwise it writes to stdout. Furthermore, the following options are possible:

• -w write Windows line endings (CR/LF) to file
• -v prints version number
• -h prints help

lpsmag

With the lpsmag bash script you can half automatically produce a Sudoku magazine using the LaTeX package lpsudoku.sty and the createlpsudoku bash script.

Usage: lpsmag configfile

The script needs an installed QQwing and a config file for defining the magazine’s contents:

page p1 easy
page p2 easy
startpuzzles
typesetpage p1
typesetpage p2
startsolutions
typesetsolpage p1 p2 last


This config file will be sourced into the lpsmag bash script and contains calls of lpsmag functions. Make sure, that the config file has UNIX line endings (LF). For a detailed documentation I refer to the following wiki entry.

After running lpsmag you will find a lpsmag.tex in your working directory. Just run pdflatex lpsmag.tex twice and you finally get for example this lpsmag.pdf.

Examples & Solutions

You can download application examples and their solutions from the project page