summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/labyrinth
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/labyrinth
Initial commit
Diffstat (limited to 'macros/latex/contrib/labyrinth')
-rw-r--r--macros/latex/contrib/labyrinth/README27
-rw-r--r--macros/latex/contrib/labyrinth/classic-en.ist3
-rw-r--r--macros/latex/contrib/labyrinth/labyrinth.pdfbin0 -> 222062 bytes
-rw-r--r--macros/latex/contrib/labyrinth/labyrinth.sty258
-rw-r--r--macros/latex/contrib/labyrinth/labyrinth.tex395
-rw-r--r--macros/latex/contrib/labyrinth/lstlocal.cfg99
6 files changed, 782 insertions, 0 deletions
diff --git a/macros/latex/contrib/labyrinth/README b/macros/latex/contrib/labyrinth/README
new file mode 100644
index 0000000000..34686620e8
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/README
@@ -0,0 +1,27 @@
+
+**********************************************************
+The Labyrinth Package
+**********************************************************
+
+Francesco Zigliotto
+francesco.zigliotto@gmail.com
+
+License
+
+ This software is provided under the terms of the
+ LaTeX Project Public License distributed from CTAN
+ archives in directory macros/latex/base/lppl.txt.
+
+Abstract
+
+ The labyrinth package provides a code and an environment for
+ typesetting simple labyrinths with LaTeX and generating an
+ automatic or manual solution path.
+
+Installation
+
+ Move labyrinth.sty into a directory searched
+ by LaTeX. If necessary, refresh the database
+ to finish installation.
+ To produce the documentation, run labyrinth.tex
+ through pdfLaTeX. \ No newline at end of file
diff --git a/macros/latex/contrib/labyrinth/classic-en.ist b/macros/latex/contrib/labyrinth/classic-en.ist
new file mode 100644
index 0000000000..648e5f1f70
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/classic-en.ist
@@ -0,0 +1,3 @@
+headings_flag 1
+heading_prefix "\\goodbreak\\textssc{"
+heading_suffix "}\\par\\nobreak\\vskip\\smallskipamount\\nobreak" \ No newline at end of file
diff --git a/macros/latex/contrib/labyrinth/labyrinth.pdf b/macros/latex/contrib/labyrinth/labyrinth.pdf
new file mode 100644
index 0000000000..b6d8499363
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/labyrinth.pdf
Binary files differ
diff --git a/macros/latex/contrib/labyrinth/labyrinth.sty b/macros/latex/contrib/labyrinth/labyrinth.sty
new file mode 100644
index 0000000000..1e356cd194
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/labyrinth.sty
@@ -0,0 +1,258 @@
+
+% Francesco Zigliotto
+% The Labyrinth Package
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{labyrinth}[2014/04/12 v1.0
+ Labyrinths typeset with LaTeX]
+
+\RequirePackage{calc}
+\RequirePackage{xkeyval}
+\RequirePackage{picture}
+
+\newcommand\lab@addtomacro[2]{%
+ \let\lab@oldmacro#1
+ \global\edef#1{\lab@oldmacro#2}}
+
+\providecommand\@nameedef[1]{%
+ \expandafter\edef\csname #1\endcsname}
+
+\providecommand\truncdiv[2]{((#1-(#2-1)/2)/#2)}
+
+%******************************************************************
+% Cat-codes of + - *
+%******************************************************************
+
+\begingroup
+\catcode`\+=\active
+\catcode`\-=\active
+\catcode`\*=\active
+\gdef\lab@catcodes{%
+ \catcode`\+=\active\def+{\lab@line}%
+ \catcode`\-=\active\def-{\lab@noline}%
+ \catcode`\*=\active\def*{\lab@repeat}}
+\endgroup
+\newcounter{lab@h}
+\newcounter{lab@v}
+
+%******************************************************************
+% Labyrinth Options
+%******************************************************************
+
+\newcommand*\labyrinthset{\setkeys{labyrinth}}
+
+\define@key{labyrinth}{unit}{\setlength\unitlength{#1}}
+\define@key{labyrinth}{thickness}{\linethickness{#1}}
+\define@boolkey{labyrinth}[lab@]{centered}{}
+
+\setkeys{labyrinth}{%
+ unit=11pt,%
+ centered=true}
+
+\newcommand*\solutionset{\setkeys{solution}}
+
+\define@boolkey{solution}[lab@]{hidden}{}
+\define@boolkey{solution}[lab@]{thicklines}{}
+\define@key{solution}{up}{\def\lab@key@u{#1}}
+\define@key{solution}{left}{\def\lab@key@l{#1}}
+\define@key{solution}{down}{\def\lab@key@d{#1}}
+\define@key{solution}{right}{\def\lab@key@r{#1}}
+\define@key{solution}{hcorr}{\def\lab@key@hcorr{#1}}
+\define@key{solution}{vcorr}{\def\lab@key@vcorr{#1}}
+\define@key{solution}{font}{\def\lab@key@font{#1}}
+
+\setkeys{solution}{%
+ thicklines=true,%
+ hidden=false,%
+ up={\line(0,1){1}},%
+ left={\line(-1,0){1}},%
+ down={\line(0,-1){1}},%
+ right={\line(1,0){1}},%
+ hcorr=0.5\unitlength,%
+ vcorr=0.5\unitlength}
+
+\@ifundefined{color}
+ {\setkeys{solution}{font=}}
+ {\setkeys{solution}{font=\color{red}}}
+
+%******************************************************************
+% Lines Definitions
+%******************************************************************
+
+\def\lab@hline{%
+ \put(\thelab@h,\thelab@v){\line(1,0){1}}%
+ \@namedef{(\number\numexpr\thelab@h*2+1,%
+ \number\numexpr\thelab@v*2)}{}%
+ \stepcounter{lab@h}}%
+\def\lab@vline{%
+ \put(\thelab@h,\thelab@v){\line(0,1){1}}%
+ \@namedef{(\number\numexpr\thelab@h*2,%
+ \number\numexpr\thelab@v*2+1)}{}%
+ \stepcounter{lab@h}}%
+\def\lab@noline{\stepcounter{lab@h}}
+\def\lab@repeat#1#2{%
+ \count@=#1\relax\@whilenum\count@>\z@
+ \do{#2\advance\count@\m@ne}}
+
+%******************************************************************
+% Labyrinth Environment
+%******************************************************************
+
+\newenvironment{labyrinth}[3][]{%
+ \iflab@centered\begin{center}\fi
+ \setkeys{labyrinth}{#1}
+ \def\lab@width{#2}
+ \def\lab@height{#3}
+ \def\h{%
+ \setcounter{lab@h}{0}%
+ \let\lab@line\lab@hline}%
+ \def\v{%
+ \addtocounter{lab@v}{-1}%
+ \setcounter{lab@h}{0}%
+ \let\lab@line\lab@vline}%
+ \def\putsymbol(##1)##2{\put(##1){\makebox[\unitlength]{##2}}}
+ \def\plus{+}\def\minus{-}\def\ast{*}
+ \begin{picture}(#2,#3)(0,0)
+ \setcounter{lab@v}{#3}%
+ \lab@catcodes
+ }{%
+ \end{picture}
+ \iflab@centered\end{center}\fi}
+
+%******************************************************************
+% Labyrinth Solution
+%******************************************************************
+
+\newcounter{lab@key@h}
+\newcounter{lab@key@v}
+
+\newcommand*\labyrinthsolution[1][]{%
+ \setkeys{solution}{#1}%
+ \lab@solution}
+
+\def\lab@solution(#1,#2)#3{%
+ \unless\iflab@hidden
+ \begingroup
+ \iflab@thicklines\thicklines\fi
+ \setcounter{lab@key@h}{#1}%
+ \setcounter{lab@key@v}{#2}%
+ \edef\lab@keycode{#3}%
+ \expandafter\lab@forany\lab@keycode.%
+ \endgroup
+ \fi}
+
+\def\lab@forany#1{\if#1.\else\lab@key{#1}%
+ \expandafter\lab@forany\fi}
+
+\def\lab@key#1{\@nameuse{lab@#1}}
+\@namedef{lab@u}{ \lab@key@put{u}\stepcounter{lab@key@v}}
+\@namedef{lab@l}{\lab@key@put{l}\addtocounter{lab@key@h}{-1}}
+\@namedef{lab@d}{\lab@key@put{d}\addtocounter{lab@key@v}{-1}}
+\@namedef{lab@r}{\lab@key@put{r}\stepcounter{lab@key@h}}
+
+\def\lab@key@put#1{%
+ \put(\lab@key@h,\lab@key@v){\lab@key@font\@nameuse{lab@key@#1}}}
+
+\def\lab@key@h{\thelab@key@h\unitlength+\lab@key@hcorr}
+\def\lab@key@v{\thelab@key@v\unitlength+\lab@key@vcorr}
+
+%******************************************************************
+% Automatic Solution
+%******************************************************************
+
+\newif\iflab@isin
+\newcommand\lab@ifisin[2]
+ {\def\lab@@isin##1#1##2|end@isin|%
+ {\if|##2|\lab@isinfalse
+ \else\lab@isintrue
+ \fi}%
+ \lab@@isin#2#1|end@isin|%
+ \iflab@isin}
+
+\newcounter{lab@x}
+\newcounter{lab@y}
+\newcounter{lab@xtry}
+\newcounter{lab@ytry}
+
+\def\lab@f#1{%
+ \setcounter{lab@xtry}{\thelab@x}%
+ \setcounter{lab@ytry}{\thelab@y}%
+ \edef\lab@f@try{\number\numexpr#1+4-\truncdiv{#1+4}{4}*4}%
+ \@nameuse{lab:\lab@f@try}%
+ \lab@check}
+
+\@namedef{lab:0}{\addtocounter{lab@ytry}{2}}
+\@namedef{lab:1}{\addtocounter{lab@xtry}{2}}
+\@namedef{lab:2}{\addtocounter{lab@ytry}{-2}}
+\@namedef{lab:3}{\addtocounter{lab@xtry}{-2}}
+
+\def\lab@step{%
+ \lab@f{\lab@f@last+1}\iflab@ok\lab@ok\else
+ \lab@f{\lab@f@last}\iflab@ok\lab@ok\else
+ \lab@f{\lab@f@last-1}\iflab@ok\lab@ok\else
+ \lab@f{\lab@f@last-2}\lab@ok\fi\fi\fi}
+
+\newif\iflab@ok
+\def\lab@check{%
+ \@ifundefined{(\number\numexpr(\thelab@x+\thelab@xtry)/2,%
+ \number\numexpr(\thelab@y+\thelab@ytry)/2)}%
+ {\lab@oktrue}{\lab@okfalse}}
+
+\def\lab@ok{%
+ \edef\lab@f@last{\lab@f@try}%
+ \setcounter{lab@x}{\thelab@xtry}%
+ \setcounter{lab@y}{\thelab@ytry}%
+ \edef\lab@f@char{\ifcase\lab@f@last u\or r\or d\or l\fi}%
+ \lab@addtomacro\lab@pos@list{%
+ (\lab@f@char:\thelab@x,\thelab@y)}}
+
+\def\lab@deleted@cyc{}
+\def\lab@f@list{}
+
+\def\lab@del@cyc(#1:#2)#3.{%
+ \lab@addtomacro\lab@deleted@cyc{(#1:#2)}%
+ \lab@addtomacro\lab@f@list{#1}%
+ \def\lab@del@@cyc##1(##2:#2){}%
+ \lab@ifisin{:#2)}{#3}%
+ \edef\lab@next@del@cyc{\lab@del@@cyc#3.}\else
+ \edef\lab@next@del@cyc{#3.}\fi
+ \if.\lab@next@del@cyc
+ \else\expandafter\lab@del@cyc\lab@next@del@cyc\fi}
+
+\def\lab@deletecyc#1;{%
+ \def\lab@deleted@cyc{}%
+ \def\lab@f@list{}%
+ \lab@del@cyc#1.%
+ \loop\unless\ifx\lab@deleted@cyc\lab@last@deleted@cyc
+ \let\lab@last@deleted@cyc\lab@deleted@cyc
+ \def\lab@deleted@cyc{}%
+ \def\lab@f@list{}%
+ \expandafter\lab@del@cyc\lab@last@deleted@cyc.%
+ \repeat}
+
+\@namedef{lab:u}{0}
+\@namedef{lab:r}{1}
+\@namedef{lab:d}{2}
+\@namedef{lab:l}{3}
+
+\newcommand*\autosolution[1][]{\lab@autokey[#1]}
+
+\def\lab@autokey[#1](#2,#3)(#4,#5)#6{%
+ \setcounter{lab@x}{#2*2+1}%
+ \setcounter{lab@y}{#3*2+1}%
+ \edef\lab@f@last{\@nameuse{lab:#6}}%
+ \lab@f\lab@f@last
+ \setcounter{lab@x}{\thelab@xtry}%
+ \setcounter{lab@y}{\thelab@ytry}%
+ \edef\lab@pos@list{(#6:\thelab@x,\thelab@y)}%
+ \edef\lab@pos@final{%
+ (\number\numexpr#4*2+1,\number\numexpr#5*2+1)}%
+ \loop\unless\ifx\lab@pos@final\lab@pos@current
+ \lab@step
+ \edef\lab@pos@current{(\thelab@x,\thelab@y)}%
+ \repeat
+ \expandafter\lab@deletecyc\lab@pos@list;%
+ \labyrinthsolution[#1](#2,#3)\lab@f@list
+ \edef\solutionpath{\lab@f@list}}
+
+\endinput \ No newline at end of file
diff --git a/macros/latex/contrib/labyrinth/labyrinth.tex b/macros/latex/contrib/labyrinth/labyrinth.tex
new file mode 100644
index 0000000000..cb7a3a5942
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/labyrinth.tex
@@ -0,0 +1,395 @@
+
+% !TeX encoding = utf8
+% !TeX program = pdflatex
+% !TeX spellcheck = en_GB
+
+\documentclass[a4paper,11pt,headinclude,footinclude]{scrartcl}
+
+\usepackage[T1]{fontenc}
+\usepackage[utf8]{inputenc}
+\usepackage[english]{babel}
+
+\usepackage{imakeidx}
+\IfFileExists{classic-en.ist}{%
+ \makeindex[columns=2,options=-s classic-en,intoc]}{%
+ \makeindex[columns=2,options=-s classic,intoc]}
+
+\indexsetup{noclearpage,firstpagestyle=scrheadings}
+
+\PassOptionsToPackage{%
+ bookmarks=false,colorlinks,%
+ linkcolor=RoyalBlue,linktocpage}{hyperref}
+\PassOptionsToPackage{noopticals,loosequotes}{MinionPro}
+\PassOptionsToPackage{dvipsnames}{xcolor}
+\usepackage[nochapters,minionprospacing]{classicthesis}
+\areaset{312pt}{699pt}
+\setlength\marginparwidth{8em}
+
+\usepackage[writefile]{listings}
+\lstset{%
+ morekeywords={v,h,minus,plus,ast,putsymbol,labyrinthsolution,
+ autosolution,labyrinthset,solutionset,color}}
+
+\usepackage[scaled=0.80]{beramono}
+\renewcommand\sfdefault{iwona}
+
+\usepackage{lettrine}
+\usepackage{labyrinth}
+
+\def\ins{~}
+
+\def\stmtitle{The \pkgname{labyrinth} package}
+\def\stmauthor{Francesco Zigliotto}
+\def\stmdate{April 12, 2014}
+
+\clearscrheadings
+\chead{\stmtitle\ $\cdot$ \parbox[b]{\widthof{\stmtitle}}{\textcolor{Orange}{\itshape\stmauthor}}}
+\cfoot{\pagemark}
+\pagestyle{scrheadings}
+
+\begin{document}
+
+\colorlet{RoyalBlue}{MidnightBlue}
+
+\begin{center}
+{\LARGE\stmtitle\par\bigskip}
+{\Large\color{Orange}\itshape\stmauthor\par\medskip}
+{\itshape\stmdate}
+\end{center}
+\par\smallskip
+
+\thispagestyle{plain}
+
+\lettrine[findent=2pt,nindent=-2pt,loversize=.2,lraise=0]{\textcolor{Orange}{T}}{\lsstyle he} \pkgname{labyrinth} package provides a code and an environment for typesetting simple labyrinths with \LaTeX\ and generating an automatic or manual solution path.
+
+\tableofcontents
+
+\enlargethispage{2\baselineskip}
+
+\begin{figure}[bh]
+\par\bigskip
+\begin{labyrinth}[unit=9pt]{19}{20}
+\putsymbol(8,\minus1){\Large$\Uparrow$}
+\putsymbol(10,20){\Large$\Uparrow$}
+ \h *9+---*7+
+\v +*5-+--+--+---+--+ \h -*4+--+-+-*4+--+
+\v +*4-++-++---+--++-+ \h *4+--+--+++--++--+
+\v +---++-++---+++--+-+ \h -++--+---++*4-+++
+\v +--++-+-++-+-+++---+ \h ++--+-+++--++---+++
+\v +--+-+*4-++-*4+--+ \h -+++-*4+-+*6-+
+\v +---++---++-++-+-+-+ \h +++---++--++-++---+
+\v +--++---++--+--+++-+ \h -+--+++--++-++---+
+\v +-++---++--+--+-++-+ \h +---++--++-++-++--+
+\v +-+++-+++--+-++--+-+ \h -+*7-++*4-+++
+\v ++-*6+-+-+-+-+--+ \h --+*8-*4+--++
+\v ++--*8+-+-++--+ \h -+++*{12}-++
+\v +-+--+-+-++-+-++--++ \h +--*7+-+++-++
+\v +-+---+---+---+-+-++ \h -++-+--++-+++-++-+
+\v ++-+-+---++-+-+--+-+ \h ---+-+++*5-+-++-+
+\v +++-++--++-++-++-+-+ \h --+---+--++-+*4-+
+\v ++-+-+-++--++-+-+-++ \h -+-+++--++*4-+++
+\v +---+-++--*5+-*4+ \h -++*4-++
+\v ++-*4+--+-+--*6+ \h *6-++-*5+
+\v *4+-++*8-+-+++ \h ---+++-+-+-*6+
+\v +-+*4-+--+*8-+ \h *7+---*9+
+
+\autosolution[font=\color{Orange}](8,0)(10,19){u}
+
+\labyrinthsolution[
+ font=\color{MidnightBlue}\footnotesize,
+ up=\kern2pt$\uparrow$,
+ left=$\leftarrow$,
+ down=\kern2pt$\downarrow$,
+ right=$\rightarrow$,
+ hcorr=0.1\unitlength,
+ vcorr=0.3\unitlength](7,1){%
+ ldlllluulddluuuuuuuruluuurulurrdd%
+ dldrruuurrrddddluuuldddlldrrrdr}
+\end{labyrinth}
+\caption{A labyrinth example (the code is shown at page\ins\pageref{sec:Example}).}
+\label{fig:Example}
+\end{figure}
+
+\section{A code for writing labyrinths}
+\label{sec:GeneralCode}
+
+The key-point in typesetting a labyrinth with \LaTeX\ is finding a way to describe it by a set of characters. The problem can be solved by including the labyrinth in an ideal $m$ by $n$ frame, divided into $m \cdot n$ unit squares. The grid is then split into $m$ horizontal sections, of $n$ unit squares each, as reported in Figure\ins\ref{fig:LabyrinthDivided}.
+
+\begin{figure}
+\centering
+\begin{minipage}{.2\textwidth}
+\centering
+ \begin{labyrinth}[unit=10pt]{5}{5}
+ \h*5+\v*5-+\h*4+\v++-+++\h\v+-++++\h-+\v+-++-+\h---+
+ \v+++--+\h+-+++
+ \end{labyrinth}
+\end{minipage}
+{\Large$\Rightarrow$}
+\quad
+\begin{minipage}{.2\textwidth}
+\centering
+ \begin{labyrinth}[unit=10pt]{5}{5}
+ \putsymbol(\minus1,5){1}
+ \putsymbol(\minus1,4){2}
+ \putsymbol(\minus1,3){3}
+ \putsymbol(\minus1,2){4}
+ \putsymbol(\minus1,1){5}
+ \putsymbol(\minus1,0){6}
+ \linethickness{0.1pt}
+ \multiput(0,0)(1,0){6}{\line(0,1){6}}
+ \multiput(0,0)(0,1){7}{\line(1,0){5}}
+ \linethickness{1pt}
+ \h*5+\v*5-+\h*4+\v++-+++\h\v+-++++\h-+\v+-++-+\h---+
+ \v+++--+\h+-+++
+ \end{labyrinth}
+\end{minipage}
+{\Large$\Rightarrow$}
+\quad
+\begin{minipage}{.2\textwidth}
+\centering
+ \begin{labyrinth}[unit=10pt]{5}{10}
+ \putsymbol(\minus1,10){1}
+ \putsymbol(\minus1,8){2}
+ \putsymbol(\minus1,6){3}
+ \putsymbol(\minus1,4){4}
+ \putsymbol(\minus1,2){5}
+ \putsymbol(\minus1,0){6}
+ \linethickness{0.1pt}
+ \multiput(0,0)(0,2){6}{%
+ \multiput(0,0)(1,0){6}{\line(0,1){1}}
+ \multiput(0,0)(0,1){2}{\line(1,0){5}}}
+ \linethickness{1pt}
+ \h*5+
+ \v\v*5-+\h*4+
+ \v\v++-+++\h
+ \v\v+-++++\h-+
+ \v\v+-++-+\h---+
+ \v\v+++--+\h+-+++
+ \end{labyrinth}
+\end{minipage}
+\caption{The labyrinth grid split into horizontal sections. (The line thickness has been incremented to differentiate the labyrinth lines from the grid).}
+\label{fig:LabyrinthDivided}
+\end{figure}
+
+\subsection{Marking horizontal lines}
+\label{hlines}
+
+First, we have to differentiate between the horizontal and vertical lines of the labyrinth. Let's focus on horizontal lines. For each unit square, you have to indicate either its bottom line belongs to the labyrinth or not. Accordingly, you will type either “\othname{+}” or “\othname{-}”. For example, with reference to Figure\ins\ref{fig:LabyrinthDivided}, the first four unit squares of the second section have their bottom lines included in the labyrinth, while the last one has not. The corresponding description is “\texttt{++++-}”.
+
+\subsection{Marking vertical lines}
+\label{vlines}
+
+Each horizontal section contains $n$ unit squares and thus $(n+1)$ vertical sides. Similarly to horizontal lines, each vertical side is marked by a “\othname{+}” if it is a part of the labyrinth and by a “\othname{-}” if it is not the case. For example, in Figure\ins\ref{fig:LabyrinthDivided}, the vertical lines in the fourth section are marked as “\texttt{+-++++}”.
+
+\subsection{Merging horizontal and vertical marks}
+\label{sec:MarkWhole}
+
+Now we have to arrange the horizontal and vertical descriptions into a unique code. For each section, \emph{first} we write \cmdname{v}, followed by the description of the vertical lines and \emph{then} \cmdname{h}, followed by the description of horizontal lines.
+
+Be careful to keep the correct sequence (\cmdname{v} leading \cmdname{h}), because every \cmdname{v} command also increases the labyrinth section number which we are referring to.
+
+Very often, the first section has no vertical lines (while horizontal lines are quite common). If this is the case, we may start the code with \cmdname{h}, skipping the \cmdname{v} command . Out of the first section, any other one without vertical sides belonging to the labyrinth calls for the \cmdname{v} command.
+
+With the above rules, the code of the labyrinth of Figure\ins\ref{fig:LabyrinthDivided} is written as follows:
+\begin{code}
+ \h +++++ % 1st section
+\v -----+ \h ++++- % 2nd section
+\v ++-+++ \h ----- % 3rd section
+\v +-++++ \h -+--- % 4th section
+\v +-++-+ \h ---+ % 5th section
+\v +++--+ \h +-+++ % 6th section
+\end{code}
+
+\subsection{Simplifying the code}
+
+The labyrinth code can be simplified, by using the rules listed below:
+\begin{itemize}
+ \item all “\othname{-}” characters at the end of each section can be omitted, for both horizontal and vertical marks;
+ \item the \cmdname{h} command can be omitted for any section void of horizontal lines;
+ \item if there are more than three consecutive “\othname{+}” or “\othname{-}” characters, you can use the following syntax:\othindex{*}
+\begin{code}
+*{£*\meta{n}*£}+ £*\normalfont or*£ *{£*\meta{n}*£}-
+\end{code}
+where \meta{n} is the number of “\othname{+}” or “\othname{-}”.
+\end{itemize}
+
+For example, the code of Section\ins\ref{sec:MarkWhole} can be simplified like this:
+\begin{code}
+ \h *5+ % 1st section
+\v *5-+ \h *4+ % 2nd section
+\v ++-+++ % 3rd section
+\v +-*4+ \h -+ % 4th section
+\v +-++-+ \h ---+ % 5th section
+\v +++--+ \h +-+++ % 6th section
+\end{code}
+
+\section{The \envname{labyrinth} environment}
+
+To typeset a labyrinth with the \pkgname{labyrinth} package, you can use the \envname{laby\-rinth} environment:
+
+\begin{code}
+\begin{labyrinth}[£*\meta{options}*£]{£*\meta{width}*£}{£*\meta{height}*£}
+£*\meta{labyrinth code}*£
+\end{labyrinth}
+\end{code}
+
+where:
+\begin{itemize}
+ \item \meta{width} is the number of columns ($n$) of the ideal grid described in Section\ins\ref{sec:GeneralCode} (see Figure\ins\ref{fig:LabyrinthDivided});
+ \item \meta{heigth} has to be set to ($m-1$), where $m$ is the number of horizontal sections, since only the bottom lines of the first horizontal section belong to the labyrinth (see Figure\ins\ref{fig:LabyrinthDivided});
+ \item \meta{options} are optional parameters in the form \texttt{key=value} of the \pkgname{xkeyval} package (see Subsection\ins\ref{sec:Options});
+ \item \meta{labyrinth code} is the code using the \cmdname{v} and \cmdname{h} commands, as described in Section\ins\ref{sec:GeneralCode}.
+\end{itemize}
+
+\subsection{Options of the \envname{labyrinth} environment}
+\label{sec:Options}
+
+There are some options for the labyrinths, which you can put either in the optional argument of the \envname{labyrinth} environment or in the argument of the \cmdname{labyrinthset} command, which should be placed outside the labyrinth environment. It that case, the options work for all the labyrinths from then on.
+\begin{code}
+\labyrinthset{£*\meta{options}*£}
+\end{code}
+
+The possible \meta{options}, in the form \othname*{key=value}, are:
+\begin{description}
+ \item[\optname{unit}] (default: \othname*{11pt}) sets the width of the side of every unit square of the ideal grid (see).
+ \item[\optname{thickness}] sets the thickness of the lines of the labyrinth.
+ \item[\optname{centered}] (values: \othname*{true}/\othname*{false}) centres horizontally the labyrinth. It also leaves extra space before and after.
+\end{description}
+
+\subsection{Adding elements to the labyrinth}
+
+The content of the \envname{labyrinth} environment is internally put inside a \envname{picture} environment, so that if we need to add to the labyrinth oblique lines, symbols or so we can do it with the usual \LaTeX\ command \cmdname{put}, \cmdname{line}\dots
+
+To put symbols inside the labyrinth, we can use the \cmdname{putsymbol} command, similar to \cmdname{put}, except for it centres its argument horizontally inside the ideal square:
+\begin{code}
+\putsymbol(£*\meta{h-pos}*£,£*\meta{v-pos}*£){£*\meta{symbol}*£}
+\end{code}
+%
+%The \pkgname{labyrinth} package is compatible with the \pkgname{picture} package.
+
+\subsection{Replacing “\othname{+}”, “\othname{-}” and “\othname{*}” characters}
+
+Of course, inside the \envname{labyrinth} environment, we can't use the characters “\othname{+}”, “\othname{-}” and “\othname{*}” outside the foreseen position, which are substituted by the \cmdname{plus}, \cmdname{minus} and \cmdname{ast} commands, respectively.
+
+\section{Typesetting the solution of the labyrinth}
+
+\subsection{The \cmdname{labyrinthsolution} macro}
+
+If we need to typeset the solution of a labyrinth, we can use the \cmdname{laby\-rinthsolution} command with the following syntax:
+\begin{code}
+\labyrinthsolution[£*\meta{options}*£](£*\meta{x,y}*£){£*\meta{solution code}*£}
+\end{code}
+where:
+\begin{itemize}
+\item \meta{options} are the optional parameters of the command in the form \texttt{key=value} of the \pkgname{xkeyval} package (see the next Subsection\ins\ref{sec:KeyOptions}).
+
+\item \meta{x,y} are the horizontal and vertical coordinates of the starting point of the solution. Please note that these coordinates are automatically increased by half a \cmdname{unitlength} (for more details, see the options \optname{hcorr} and \optname{vcorr} in the Subsection\ins\ref{sec:KeyOptions}).
+
+\item \meta{solution code} is a sequence of characters of the set $\{$\othname{u},\othname{l},\othname{d},\othname{r}$\}$. From the starting point (\meta{x,y}) we describe each segment of the solution path by indicating the direction: up (\othname{u}), left (\othname{l}), down (\othname{d}) or right (\othname{r}). Each step is one \cmdname{unitlength} long.
+
+\end{itemize}
+Please note that:
+\begin{itemize}
+\item the \cmdname{labyrinthsolution} command should be put \emph{inside} the \envname{laby\-rinth} environment;
+\item there can be more than one \cmdname{labyrinthsolution} command inside the same labyrinth (e.g. for multiple solutions).
+\end{itemize}
+
+\subsection{Options of the \cmdname{labyrinthsolution} command}
+\label{sec:KeyOptions}
+
+As the labyrinth options and the \cmdname{labyrinthset} macro (Subsection\ins\ref{sec:Options}), you can put the solution options either in the optional argument of the \cmdname{labyrinthsolution} command or in the argument of the \cmdname{solutionset} command, that should be placed outside the labyrinth environment and that works for all the labyrinth solutions from then on.
+\begin{code}
+\solutionset{£*\meta{options}*£}
+\end{code}
+
+\goodbreak
+The possible \meta{options} are:\nobreak
+\begin{description}
+ \item[\optname{hidden}] (values: \optname*{true}/\optname*{false}, default: \optname*{false}) hides (\optname*{true}) or shows (\optname*{fal\-se}) the solution the labyrinth.
+ \item[\othname{thicklines}] (values: \optname*{true}/\optname*{false}, default: \optname*{true}) sets the lines of the solution thick (\optname*{true}) or thin (\optname*{false});
+ \item[\othname{up}] (default: \lstinline!\line(0,1){1}!) defines the symbol that indicates a step up in the solution path (letter \othname{u});
+ \item[\othname{left}] (default: \lstinline!\line(-1,0){1}!) as above, for the left step (letter \othname{l});
+ \item[\othname{down}] (default: \lstinline!\line(0,-1){1}!) as above, for the down step (letter \othname{d});
+ \item[\othname{right}] (default: \lstinline!\line(1,0){1}!) as above, for the right step (letter \othname{r});
+ \item[\othname{hcorr}] (default: \lstinline!0.5\unitlength!) sets the increment of the horizontal coordinate (it moves horizontally all the solution route);
+ \item[\othname{vcorr}] (default: \lstinline!0.5\unitlength!) sets the increment of the vertical coordinate (it moves vertically all the solution route);
+ \item[\othname{font}] (default: \lstinline!\color{red}! if \cmdname{color} is defined) select the font (mainly the colour) of the labyrinth solution.
+\end{description}
+
+\subsection{Automatic solution of the labyrinth}
+
+The package also provides the macro \cmdname{autosolution} that finds and draws automatically one of the labyrinth solutions (if any, of course):
+\begin{code}
+\autosolution[£*\meta{options}*£](£*\meta{$x_A$,$y_A$}*£)(£*\meta{$x_B$,$y_B$}*£){£*\meta{first direction}*£}
+\end{code}
+where:
+\begin{itemize}
+\item \meta{options} are the same optional parameters of the \cmdname{labyrinth\-solution} command described in Section\ins\ref{sec:KeyOptions};
+
+\item \meta{$x_A$,$y_A$} and \meta{$x_B$,$y_B$} are the horizontal and vertical coordinates of the starting point (A) and of the arrival point (B) of the solution path. Please note that the coordinates of both points are automatically increased by half a \cmdname{unitlength} (for more details, see options \optname{hcorr} and \optname{vcorr} in the Subsection\ins\ref{sec:KeyOptions}).
+
+\item \meta{first direction} is one character of the set $\{$\othname{u},\othname{d},\othname{l},\othname{r}$\}$ (up, down, left, right - respectively) that indicates the direction of the first step of the solution path.
+
+\end{itemize}
+
+The \cmdname{autosolution} command also defines \cmdname{solutionpath}, which generates the string of direction-characters that defines the solution path.
+
+\clearpage
+\section{Example}
+
+Here you can see the code used for the labyrinth of Figure\ins\ref{fig:Example}:
+\label{sec:Example}
+\begin{code}
+\begin{labyrinth}[unit=9pt]{19}{20}
+\putsymbol(8,\minus1){\Large$\Uparrow$}
+\putsymbol(10,20){\Large$\Uparrow$}
+ \h *9+---*7+
+\v +*5-+--+--+---+--+ \h -*4+--+-+-*4+--+
+\v +*4-++-++---+--++-+ \h *4+--+--+++--++--+
+\v +---++-++---+++--+-+ \h -++--+---++*4-+++
+\v +--++-+-++-+-+++---+ \h ++--+-+++--++---+++
+\v +--+-+*4-++-*4+--+ \h -+++-*4+-+*6-+
+\v +---++---++-++-+-+-+ \h +++---++--++-++---+
+\v +--++---++--+--+++-+ \h -+--+++--++-++---+
+\v +-++---++--+--+-++-+ \h +---++--++-++-++--+
+\v +-+++-+++--+-++--+-+ \h -+*7-++*4-+++
+\v ++-*6+-+-+-+-+--+ \h --+*8-*4+--++
+\v ++--*8+-+-++--+ \h -+++*{12}-++
+\v +-+--+-+-++-+-++--++ \h +--*7+-+++-++
+\v +-+---+---+---+-+-++ \h -++-+--++-+++-++-+
+\v ++-+-+---++-+-+--+-+ \h ---+-+++*5-+-++-+
+\v +++-++--++-++-++-+-+ \h --+---+--++-+*4-+
+\v ++-+-+-++--++-+-+-++ \h -+-+++--++*4-+++
+\v +---+-++--*5+-*4+ \h -++*4-++
+\v ++-*4+--+-+--*6+ \h *6-++-*5+
+\v *4+-++*8-+-+++ \h ---+++-+-+-*6+
+\v +-+*4-+--+*8-+ \h *7+---*9+
+
+\autosolution[font=\color{Orange}](8,0)(10,19){u}
+
+\labyrinthsolution[
+ font=\color{MidnightBlue}\footnotesize,
+ up=\kern2pt$\uparrow$,
+ left=$\leftarrow$,
+ down=\kern2pt$\downarrow$,
+ right=$\rightarrow$,
+ hcorr=0.1\unitlength,
+ vcorr=0.3\unitlength](7,1){%
+ ldlllluulddluuuuuuuruluuurulurrdd%
+ dldrruuurrrddddluuuldddlldrrrdr}
+\end{labyrinth}
+\end{code}
+
+%\begin{center}
+%\begin{labyrinth}{5}{5}
+%\v*2{-+}\h*2{-+}
+%\v*2{+-}+\h*2{+-}+
+%\v*2{-+}\h*2{-+}
+%\v*2{+-}+\h*2{+-}+
+%\v*2{-+}
+%\end{labyrinth}
+%\end{center}
+
+\printindex
+
+\end{document} \ No newline at end of file
diff --git a/macros/latex/contrib/labyrinth/lstlocal.cfg b/macros/latex/contrib/labyrinth/lstlocal.cfg
new file mode 100644
index 0000000000..1933c0f01a
--- /dev/null
+++ b/macros/latex/contrib/labyrinth/lstlocal.cfg
@@ -0,0 +1,99 @@
+% Listing configuration file
+
+% !TeX encoding = utf8
+
+\makeatletter
+
+\let\scr@float@addtolists@warning\relax
+\definecolor{lightergray}{gray}{0.99}
+
+\lstset{%
+ language=[LaTeX]TeX,
+ basicstyle=\ttfamily,
+ keywordstyle=\color{RoyalBlue},
+ commentstyle=\color{darkgray},
+ backgroundcolor=\color{lightergray},
+ stringstyle=\rmfamily,
+ numbers=none,
+ showstringspaces=false,
+ breaklines=true,
+ %frameround=ftff,
+ frame=lines,
+ escapeinside={£*}{*£},
+ tabsize=2,
+ morekeywords={unless}}
+
+\lstnewenvironment{code}
+ {\lstset{columns=fullflexible,keepspaces=true,%
+ basicstyle=\ttfamily\small}}{}
+
+\lstnewenvironment{sidebyside}
+ {\global\let\lst@intname\@empty
+ \setbox\z@=\hbox\bgroup
+ \lstset{columns=fullflexible,%
+ linewidth=0.45\linewidth,keepspaces=true,%
+ breaklines=true,%
+ breakindent=0pt,%
+ boxpos=t,%
+ basicstyle=\ttfamily\small}%
+ \lst@BeginAlsoWriteFile{\jobname.tmp}}
+ {\lst@EndWriteFile\egroup
+ \begin{center}%
+ \begin{minipage}{0.45\linewidth}%
+ \hbox to\linewidth{\box\z@\hss}
+ \end{minipage}%
+ \qquad
+ \begin{minipage}{0.45\linewidth}%
+ \lstset{frame=none}%
+ \leavevmode \catcode`\^^M=5\relax
+ \small\input{\jobname.tmp}%
+ \end{minipage}%
+ \end{center}}
+
+\DeclareRobustCommand*{\clsname}{%
+ \texorpdfstring{\@ifstar\@clsname\@@clsname}{}}
+ \def\@clsname#1{{\normalfont\textsf{#1}}}
+ \def\@@clsname#1{{\normalfont\textsf{#1}\clsindex{#1}}}
+\DeclareRobustCommand*{\pkgname}{%
+ \texorpdfstring{\@ifstar\@pkgname\@@pkgname}{}}
+ \def\@pkgname#1{{\normalfont\textsf{#1}}}
+ \def\@@pkgname#1{{\normalfont\textsf{#1}\pkgindex{#1}}}
+\DeclareRobustCommand*{\optname}{%
+ \texorpdfstring{\@ifstar\@optname\@@optname}{}}
+ \def\@optname#1{{\normalfont\texttt{#1}}}
+ \def\@@optname#1{{\normalfont\texttt{#1}\optindex{#1}}}
+\DeclareRobustCommand*{\othname}{%
+ \texorpdfstring{\@ifstar\@othname\@@othname}{}}
+ \def\@othname#1{{\normalfont\texttt{#1}}}
+ \def\@@othname#1{{\normalfont\texttt{#1}\othindex{#1}}}
+\DeclareRobustCommand*{\envname}{%
+ \texorpdfstring{\@ifstar\@envname\@@envname}{}}
+ \def\@envname#1{{\normalfont\texttt{#1}}}
+ \def\@@envname#1{{\normalfont\texttt{#1}\envindex{#1}}}
+\DeclareRobustCommand*{\cmdname}{%
+ \texorpdfstring{\@ifstar\@cmdname\@@cmdname}{\textbackslash}}
+ \def\@cmdname#1{{\ttfamily\textbackslash\textcolor{RoyalBlue}{#1}}}
+ \def\@@cmdname#1{{\ttfamily\textbackslash\textcolor{RoyalBlue}{#1}}\cmdindex{#1}}
+
+\def\clsindex#1{\index{#1@\textsf{#1}}%
+ \index{#1@\textsf{#1} \textit{\textit{(class)}}}}
+\def\pkgindex#1{\index{Package!#1@\textsf{#1}}%
+ \index{#1@\textsf{#1} \textit{(pack.)}}}
+\def\optindex#1{\index{Option!#1@\texttt{#1}}%
+ \index{#1@\texttt{#1} \textit{(opt.)}}}
+\def\othindex#1{\index{#1@\texttt{#1}}}
+\def\envindex#1{\index{Environment!#1@\texttt{#1}}%
+ \index{#1@\texttt{#1} \textit{(env.)}}}
+\def\cmdindex#1{\index{#1@\texttt{\hspace*{-1.2ex}%
+ \textbackslash#1}}}
+
+\DeclareRobustCommand\meta[1]{%
+ $\langle${\normalfont\itshape#1}$\rangle$}
+\DeclareRobustCommand\mail[1]{\href{mailto:#1}{\texttt{#1}}}
+
+%\def\dotfill{\leaders\hbox to.6em{\hss .\hss}\hskip\z@ plus 1fill}%
+%\def\dotfil{\leaders\hbox to.6em{\hss .\hss}\hfil}%
+%\def\pfill{\unskip~\dotfill\penalty500\strut\nobreak
+% \dotfil~\ignorespaces}
+
+\makeatother \ No newline at end of file