%%
%% This is file `diagram.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% diagram.dtx  (with options: `style')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from diagram.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file diagram.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%  File 'diagram.dtx'
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version
%% 1.2 of this license or (at your option) any later version.
%% The latest version of this license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%
%%
%%

\ProvidesPackage{diagram}[2025/02/21-tikz]
\newcommand*{\DefaultDiagramSize}{}
\DeclareOption{10pt}{\renewcommand*{\DefaultDiagramSize}{\diagramx}}
\DeclareOption{11pt}{\renewcommand*{\DefaultDiagramSize}{\diagramxi}}
\DeclareOption{12pt}{\renewcommand*{\DefaultDiagramSize}{\diagramxii}}
\ExecuteOptions{10pt}

\ProcessOptions
\AtBeginDocument{\DefaultDiagramSize}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{tikz}
\RequirePackage{xstring}
%%
%%
%%
\chardef\f@ur=4
\chardef\@ight=8
\newcount\elchfont

\chardef\@pkelch=0
\chardef\@fselch=1

\newcount\dia@type

\newboolean{@textproblem}
\setboolean{@textproblem}{false}
\def\textproblem{\setboolean{@textproblem}{true}\let\@dia@stipulation=\relax}

\newboolean{@solafterdiagram}
\setboolean{@solafterdiagram}{false}
\def\solafterdiagram{\setboolean{@solafterdiagram}{true}\ignorespaces}

\newif\if@vframe\@vframetrue
\newif\if@hframe\@hframetrue
\newif\if@leaveOuter\@leaveOutertrue

\newif\if@shortform

\newif\ifspace@vertical
\def\spacehorizontal{\space@verticalfalse}

\newboolean{@cpd@numbering@global}
\newboolean{@cpd@numbering@local}
\newcounter{board@nr}
\renewcommand{\theboard@nr}{\thediag}
\newboolean{piececounter}

\newcounter{cpd@piece@index}

\newboolean{showcity}
\setboolean{showcity}{false}
\newboolean{showacademictitle}
\setboolean{showacademictitle}{true}
\newboolean{legend}
\setboolean{legend}{false}

\newcount\@blackfield
\newboolean{allwhite}
\setboolean{allwhite}{false}
\newcommand{\allwhite}{\setboolean{allwhite}{true}}
\newcounter{field@border}
\newcount\@whitefield
\newboolean{switchcolors}
\setboolean{switchcolors}{false}
\newcommand{\switchcolors}{\setboolean{switchcolors}{true}}
\newboolean{cpd@checkPieceCounts}
\newcounter{cpd@defWhitePieces}
\newcounter{cpd@defBlackPieces}
\newcounter{cpd@defNeutralPieces}

\newcounter{cpd@whitePieces}
\newcounter{cpd@blackPieces}
\newcounter{cpd@neutralPieces}

\newcommand{\cpd@stepcounterWhite}{\stepcounter{cpd@whitePieces}}
\newcommand{\cpd@stepcounterBlack}{\stepcounter{cpd@blackPieces}}
\newcommand{\cpd@stepcounterNeutral}{\stepcounter{cpd@neutralPieces}}
\global\let\cpd@stepcounterPieces\relax

\newcount\help@a

\newbox\dia@box
\newbox\@cnt@box
\newdimen\@cnt@wd
\newbox\@stip@box

\newdimen\topdist\topdist\z@
\newbox\@test@box
\newdimen\@test@dimen
\newif\if@left

\newdimen\dia@lineskip

\newdimen\board@width
\newdimen\bd@width
\newdimen\head@width
\newdimen\sq@width

\newdimen\grid@width
\newdimen\inner@frame
\newdimen\outer@frame
\newdimen\space@frame
\newdimen\v@frame@dist
\newdimen\h@frame@dist
\newdimen\space@frame@dist
\newdimen\v@space@dist
\newdimen\h@space@dist

\newbox\sq@box
\newbox\plane@box
\newtoks\typis@tk\typis@tk={\relax}
\newtoks\label@tk\label@tk={\relax}
\newtoks\sol@tk\sol@tk={\relax}
\newtoks\number@tk\number@tk={\relax}
\newtoks\aut@tk\aut@tk={\relax}
\newtoks\city@tk\city@tk={\relax}
\newtoks\sourcenr@tk\sourcenr@tk={\relax}
\newtoks\source@tk\source@tk={\relax}
\newtoks\day@tk\day@tk={\relax}
\newcount\from@month\from@month=\z@
\newcount\to@month\to@month=\z@
\newtoks\year@tk\year@tk={\relax}
\newtoks\issue@tk\issue@tk={\relax}
\newtoks\pages@tk\pages@tk={\relax}
\newtoks\tournament@tk\tournament@tk={\relax}
\newtoks\award@tk\award@tk={\relax}
\newtoks\after@tk\after@tk={\relax}
\newtoks\version@tk\version@tk={\relax}
\newtoks\correction@tk\correction@tk={\relax}
\newtoks\dedic@tk\dedic@tk={\relax}
\newtoks\fidealbum@tk\fidealbum@tk={\relax}
\newtoks\theme@tk\theme@tk={\relax}
\newtoks\twins@tk\twins@tk={\relax}
\newtoks\judgement@tk\judgement@tk={\relax}
\newtoks\comment@tk\comment@tk={\relax}
\newtoks\computer@tk\computer@tk={-}
\newtoks\nofields@tk\nofields@tk={\relax}
\newtoks\fieldframe@tk\fieldframe@tk={\relax}
\newtoks\gridlines@tk\gridlines@tk={\relax}
\newtoks\pieces@tk\pieces@tk={\relax}
\newtoks\fen@tk\fen@tk={\relax}
\newtoks\fieldtext@tk\fieldtext@tk={\relax}
\newtoks\text@tk\text@tk={\relax}
\newtoks\stipulation@tk\stipulation@tk={\relax}
\newtoks\condition@tk\condition@tk={\relax}
\newtoks\remark@tk\remark@tk={\relax}
\newtoks\piecedefs@tk\piecedefs@tk={\relax}
\newtoks\@cpd@emptytest
\newif\if@label\@labelfalse
\newif\if@number\@numberfalse
\newif\if@special\@specialfalse
\newif\ifauth@r\auth@rfalse
\newif\if@city\@cityfalse
\newif\if@sourcenr\@sourcenrfalse
\newif\if@source\@sourcefalse
\newif\if@date\@datefalse
\newif\if@day\@dayfalse
\newif\if@year\@yearfalse
\newif\if@issue\@issuefalse
\newif\if@pages\@pagesfalse
\newif\if@tournament\@tournamentfalse
\newif\if@award\@awardfalse
\newif\if@after\@afterfalse
\newif\if@version\@versionfalse
\newif\if@correction\@correctionfalse
\newif\if@dedication\@dedicationfalse
\newif\if@fidealbum\@fidealbumfalse
\newif\if@twins\@twinsfalse
\newif\if@theme\@themefalse
\newif\if@computer\@computerfalse
\newif\if@judgement\@judgementfalse
\newif\if@comment\@commentfalse
\newif\if@pieces\@piecesfalse
\newboolean{@cpd@fen}\setboolean{@cpd@fen}{false}%
\newif\if@fieldtext\@fieldtextfalse
\newif\if@nofields\@nofieldsfalse
\newif\if@gridlines\@gridlinesfalse
\newif\if@fieldframe\@fieldframefalse
\newif\if@stdgrid\@stdgridfalse
\newboolean{showcomputer}\setboolean{showcomputer}{true}%
\newcommand*{\computerproofedsymbol}{C+}
\newcommand*{\notcomputerproofedsymbol}{C-}
\newif\if@stipulation\@stipulationfalse
\newif\if@condition\@conditionfalse
\newif\if@remark\@remarkfalse
\newif\if@piecedefs\@piecedefsfalse
\newif\if@typis\@typisfalse
\newif\if@widedias\@widediasfalse
\newif\ifx@twins\x@twinsfalse
\newif\ifx@cond\x@condfalse
\newif\ifimitator\imitatorfalse
\newif\ifnormal@names\normal@namesfalse
\newif\ifs@lu
\newif\if@develop\@developfalse
\newif\if@notfirst
\newif\if@first
\newwrite\s@lfd
\let\below@newline=\relax
\newcounter{cpd@planes}
\newcounter{cpd@rows}
\newcounter{cpd@lines}
\newcounter{cpd@plane}
\newcounter{cpd@current@plane}
\newcounter{cpd@current@plane@display}
\newcounter{cpd@row}
\newcounter{cpd@line}
\newcounter{cpd@row@display}
\newcounter{cpd@line@display}
\newcounter{cpd@maxsquare}
\newcounter{cpd@helper}
\newcounter{cpd@current@square@index}
\newcounter{cpd@current@square@value}
\newif\if@stereo\@stereofalse
\newif\if@space\@spacefalse
\newif\if@aindex\@aindexfalse
\newif\if@sindex\@sindexfalse
\newif\if@tindex\@tindexfalse
\newif\ifds@label
\newcommand{\cpd@begindiagram@hook}{}
\newcommand{\cpd@enddiagram@hook}{}
\def\diagram{%
   \begingroup%
   \@ifnextchar [{\@diagram}{\@diagram[\@ight x\@ight]}%
}

\def\@cpd@initsize#1#2{%
   \setcounter{cpd@lines}{#1}%
   \setcounter{cpd@rows}{#2}%
   \setcounter{cpd@maxsquare}{\value{cpd@rows}*\value{cpd@lines}}%
}

\def\@diagram[#1x#2]{%
   \@cpd@initsize{#1}{#2}%
   \setcounter{cpd@plane}{0}%
   \setcounter{cpd@current@plane}{0}%
   \let\put@sqs=\put@sqs@normal%
   \let\read@plane=\read@plane@normal%
   \@start@diagram%
}
\def\stereodiagram{%
   \begingroup%
   \inner@frame=0.6pt%
   \@stereotrue%
   \@cpd@initsize{8}{8}%
   \let\put@sqs=\put@sqs@stereo%
   \let\read@plane=\read@plane@stereo%
   \@start@diagram%
}
\def\spacediagram{%
   \begingroup%
   \inner@frame=0.6pt%
   \@spacetrue%
   \@ifnextchar [{\@spacediagram}{\@spacediagram[5x5x5]}%
}

\def\@spacediagram[#1x#2x#3]{%
   \setcounter{cpd@planes}{#3}%
   \@cpd@initsize{#1}{#2}%
   \let\put@sqs=\put@sqs@space%
   \let\read@plane=\read@plane@space%
   \@start@diagram%
}
\def\@start@diagram{%
   \init@vars%
   \let\author=\ds@author%
   \let\day=\ds@day%
   \let\month=\ds@month%
   \let\year=\ds@year%
   \let\label=\ds@label%
   \cpd@begindiagram@hook%
   \ignorespaces%
}

\def\showtypis#1{%
   \@typistrue%
   \typis@tk={#1}%
   \ignorespaces%
}

\newboolean{@cpd@inside@diagram}
\setboolean{@cpd@inside@diagram}{false}
\newcommand{\insidediagram}[1]{%
    \ifthenelse{\boolean{@cpd@inside@diagram}}{#1}{}%
}
\def\enddiagram{%
   \let\author=\orig@author%
   \let\day=\orig@day%
   \let\month=\orig@month%
   \let\year=\orig@year%
   \let\label=\orig@label%
   \if@number%
   \else%
      \refstepcounter{board@nr}% so \label and \ref work properly
   \fi%
   %
   % Now \label@tk should be set, if wanted, so
   % we can generate the index entries
   %
   \@aindex%
   \@sindex%
   \@tindex%
   %
   % Now \@currentlabel will be set right, so we can use
   % the original label
   \if@label%
      \expandafter\@set@label\the\label@tk;%
   \fi%
   %
   % Now we know, if we have frames so we can setup our dimensions
   %
   \global\sq@width=\fontdimen\tw@\chessfont%
   \if@stereo%
      \bd@width=\@ight\sq@width%
      \board@width=\@ight\sq@width%
      \ifdim\h@frame@dist<\sq@width%
         \h@frame@dist=\sq@width%
      \fi%
      % We do already skip with \v@space@dist
      % So we use the additional skip \space@frame@dist here
      \v@frame@dist=\space@frame@dist%
      \ifdim\space@frame>\outer@frame%
         \outer@frame=\space@frame%
      \fi%
      \advance\bd@width\tw@\inner@frame%
      \advance\board@width\tw@\inner@frame%
      \advance\board@width\tw@\h@frame@dist%
      \advance\board@width\tw@\outer@frame%
   \else\if@space%
      \ifdim\h@frame@dist<1.5\sq@width%
         \h@frame@dist=1.5\sq@width%
      \fi%
      % We do already skip with \v@space@dist
      % So we use the additional skip \space@frame@dist here
      \v@frame@dist=\space@frame@dist%
      \ifdim\space@frame>\outer@frame%
         \outer@frame=\space@frame%
      \fi%
      \ifspace@vertical%
         \bd@width=\value{cpd@lines}\sq@width%
         \board@width\bd@width%
         \advance\bd@width\tw@\inner@frame%
         \advance\board@width\tw@\inner@frame%
         \advance\board@width\tw@\h@frame@dist%
         \advance\board@width\tw@\outer@frame%
      \else%
         \bd@width=\value{cpd@lines}\sq@width%
         \advance\bd@width\tw@\inner@frame%
         \ifdim\h@space@dist<1.5\sq@width%
            \h@space@dist=1.5\sq@width%
         \fi%
         %\h@space@dist=0.7\sq@width%
         % Now we can compute the width of the complete board
         \board@width\bd@width%
         \advance\board@width\h@space@dist%
         \multiply\board@width\value{cpd@planes}%
         \advance\board@width\h@space@dist%
         \advance\board@width\tw@\outer@frame%
      \fi%
   \else%
      \ifthenelse{\boolean{legend}}{\v@frame@dist=1.5em\h@frame@dist=1.5em}{}%
      \bd@width=\value{cpd@lines}\sq@width%
      \ifthenelse{\value{cpd@lines} > 8}{%
         % Make the board wider
         \board@width=\value{cpd@lines}\sq@width%
      }{%
         % Make a normal width
         \board@width=\@ight\sq@width%
      }%
      \advance\bd@width\tw@\inner@frame%
      \advance\board@width\tw@\inner@frame%
      \advance\board@width\tw@\h@frame@dist%
      \advance\board@width\tw@\outer@frame%
   \fi\fi%
   \if@widedias%
      \head@width=\textwidth%
   \else%
      \head@width=\board@width%
   \fi%
   %
   % Now we should build the diagram itself
   %
   \ifthenelse{\boolean{@textproblem}}{%
      % Put the stipulation into the \sq@box
      \setbox\sq@box=\hbox{\vbox to \board@width{\hsize\board@width%
         \stipfont%
         \raggedright%
         \sloppy%
         \the\stipulation@tk%
         \vfil%
      }}%
   }{%
      \put@sqs% This builds up the \sq@box
      % Check, if the given number of pieces is reached
      \ifthenelse{\boolean{cpd@checkPieceCounts}}{%
        \ifthenelse{\value{cpd@defWhitePieces}=\value{cpd@whitePieces}}{}%
            {\errmessage{Wrong number of white pieces}}%
        \ifthenelse{\value{cpd@defBlackPieces}=\value{cpd@blackPieces}}{}%
            {\errmessage{Wrong number of black pieces}}%
         \ifthenelse{\value{cpd@defNeutralPieces}=\value{cpd@neutralPieces}}{}%
             {\errmessage{Wrong number of neutral pieces}}%
      }{}%
   }%
   %
   \global\setbox\dia@box=\hbox{\vbox{%
      \setboolean{@cpd@inside@diagram}{true}%
      \parindent\z@%
      \parskip\z@%
      \baselineskip11\p@\advance\baselineskip\dia@lineskip%
      \hsize\head@width%
      \centering%
      % diagram header
      \vskip\topdist%
      \vbox{\hsize\board@width\hbox{%
         \if@develop\if@label%
            \noindent\raggedright\llap{\labelfont\the\label@tk\ }%
         \fi\fi%
         \vbox{%
            \he@dpos\dia@above%
         }%
      }}%
      \vskip\tw@\p@%
      % diagram itself
      \vtop{\hsize\board@width%
         \hbox to \head@width{\hss\vbox{%
            \hsize\board@width%
            \ifthenelse{\boolean{@textproblem}}{%
               \box\sq@box%
            }{%
               \outer@henbox{\box\sq@box}%
            }%
         }\hss}%
         % diagram trailer
         \hbox to \head@width{\hss\vtop{%
            \hsize\board@width%
            \parskip\z@%
            \raggedright%
            \put@count%
            \dia@below%
         }\hss}%
      }%
      \setboolean{@cpd@inside@diagram}{false}%
   }}% End of \dia@box
   \do@dia@job%
   \cpd@enddiagram@hook%
   \endgroup%
}

\def\do@put@count{%
   \ \ (\arabic{cpd@whitePieces}+\arabic{cpd@blackPieces}%
   \ifthenelse{\value{cpd@neutralPieces}>0}{+\arabic{cpd@neutralPieces}}{})%
}

\def\put@count{%
   % First we build the box with the figure count
   \ifthenelse{\boolean{showcomputer}\OR\boolean{piececounter}}{%
     \global\setbox\@cnt@box=\hbox{%
        \stipfont%
        \ifthenelse{\boolean{showcomputer}}{%
           \ \ \if@computer\computerproofedsymbol\else\notcomputerproofedsymbol\fi%
        }{}%
        \ifthenelse{\boolean{piececounter}}{%
           \do@put@count%
        }{}%
      }%
      \@cnt@wd=\wd\@cnt@box%
      \hangindent-\@cnt@wd%
      \hangafter\m@ne%
      \noindent%
      \hbox to \z@{%
        \hbox to \board@width{\hfil\unhbox\@cnt@box}\hskip -\board@width%
      }%
   }{}%
}

\let\endstereodiagram=\enddiagram
\let\endspacediagram=\enddiagram
\def\figurine{%
   \begingroup%
   \init@vars%
   \let\author=\ds@author%
   \let\day=\ds@day%
   \let\month=\ds@month%
   \let\year=\ds@year%
   \let\label=\ds@label%
   \cpd@begindiagram@hook%
}

\def\endfigurine{%
   \let\author=\orig@author%
   \let\day=\orig@day%
   \let\month=\orig@month%
   \let\year=\orig@year%
   \let\label=\orig@label%
   \if@number%
   \else%
      \refstepcounter{board@nr}% so \label and \ref work properly
   \fi%
   %
   % Now \label@tk should be set, if wanted, so
   % we can generate the index entries
   %
   \@aindex%
   \@sindex%
   \@tindex%
   %
   % Now \@currentlabel will be set right, so we can use
   % the original label
   %
   \if@label%
      \expandafter\@set@label\the\label@tk;%
   \fi%
   %
   \@show@figurine%
   \cpd@enddiagram@hook%
   \endgroup%
}
\gdef\selectelchfont#1{%
   \global\elchfont\csname @#1elch\endcsname\defaultelchfont%
}
\newcommand*{\authorfont}{\bfseries}
\newcommand*{\cityfont}{\slshape}
\newcommand*{\sourcefont}{\bfseries\itshape}
\newcommand*{\awardfont}{\itshape}
\newcommand*{\dedicfont}{\itshape}
\newcommand*{\stipfont}{\rmfamily}
\newcommand*{\remfont}{\rmfamily}
\newcommand*{\labelfont}{\rmfamily}
\newcommand*{\cpd@boardfont}{\rmfamily}
\newcommand*{\legendfont}{\sffamily}
\newcounter{cpd@chessfontsize}
\newcommand*{\diagramx}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch12
      \font\chtextfont=pkelch10
   \else%
      \font\chessfont=fselch12
      \font\chtextfont=fselch10
   \fi%
   \dia@lineskip\z@
   \dia@type\z@
   \setcounter{cpd@chessfontsize}{12}%
}

\newcommand*{\diagramxi}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch14
      \font\chtextfont=pkelch11
   \else%
      \font\chessfont=fselch14
      \font\chtextfont=fselch11
   \fi%
   \dia@lineskip\@ne\p@
   \dia@type\@ne
   \setcounter{cpd@chessfontsize}{14}%
}

\newcommand*{\diagramxii}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch16
      \font\chtextfont=pkelch12
   \else%
      \font\chessfont=fselch16
      \font\chtextfont=fselch12
   \fi%
   \dia@lineskip\tw@\p@
   \dia@type\tw@
   \setcounter{cpd@chessfontsize}{16}%
}
\def\defaultelchfont{%
   \ifcase\@ptsize\relax%
      \diagramx\or%
      \diagramxi\or%
      \diagramxii%
   \fi%
}
\def\dianamestyle#1{\def\@dianame{\csname @#1\endcsname}}
\def\solnamestyle#1{\def\@solname{\csname @#1\endcsname}}
\newcommand*{\diagnum}[2][]{%
   \renewcommand*{\@dianumber@prefix}{#1}%
   \setcounter{board@nr}{#2}%
   \addtocounter{board@nr}{\m@ne}}
\newcommand{\@cpd@pre@arrow}{}
\newcommand{\@cpd@post@arrow}{}
\newcommand{\ra}{\@cpd@pre@arrow\mbox{$\rightarrow$}\@cpd@post@arrow}
\newcommand{\lra}{\@cpd@pre@arrow\mbox{$\leftrightarrow$}\@cpd@post@arrow}
\let\rla=\lra
\newcommand*{\@cpd@prepost@arrow}[2]{%
   \renewcommand*{\@cpd@pre@arrow}{#1}
   \renewcommand*{\@cpd@post@arrow}{#2}
}
\newenvironment{arrowskip}{%
   \@cpd@prepost@arrow%
}{%
}
\newcommand{\x}{\mbox{\ifmmode\times\else$\times$\fi}}
\def\set{\kern -.05em\raise .1ex\hbox{*}}
\def\@O{0\raise.25ex\hbox{-}\kern -.1em\relax}
\def\OO{\@O0}
\def\OOO{\@O\@O0}
\def\any{\ifmmode\sim\else$\sim$\fi}
\def\further{\ifmmode\Rightarrow\else$\Rightarrow$\fi\ \ignorespaces}
\def\spacelayout#1{\csname space@#1\endcsname}
\def\nodiagnumbering{%
    % \global\di@nofalse
    \setboolean{@cpd@numbering@global}{false}
}
\newcommand*{\@dianumber@prefix}{}
\def\diagnumbering#1{%
   \setboolean{@cpd@numbering@global}{true}%
   % \global\di@notrue%
   \diagnum{\@ne}%
   \gdef\thediag{\@dianumber@prefix\csname @#1\endcsname\c@board@nr}%
}
\def\diagcenter{\def\he@dpos{\centering}}
\def\diagleft{\def\he@dpos{\raggedright}}
\def\diagright{\def\he@dpos{\raggedleft}}
\def\setmonthstyle#1{\def\write@month{\csname @#1\endcsname}}
\def\specialdiagnum#1{%
   \ifthenelse{\equal{}{#1}}{%
       % We disable displaying the diagram number
       \setboolean{@cpd@numbering@local}{false}%
   }{%
       \setboolean{@cpd@numbering@local}{true}%
       \@specialtrue%
   }
   \number@tk={#1}\@numbertrue%
   \def\thediag{#1}\def\@currentlabel{#1}%
   \ignorespaces%
}
\def\ds@label{%
   \@ifstar{\ds@labelfalse\ds@xlabel}{\ds@labeltrue\ds@xlabel}%
}
\def\ds@author#1{%
   \aut@tk={#1}\auth@rtrue%
   \ignorespaces%
}
\def\ds@academictitle#1{\ifthenelse{\boolean{showacademictitle}}{#1~}{}\ignorespaces}
\newcommand{\Dr}{\ds@academictitle{Dr.}}
\newcommand{\Prof}{\ds@academictitle{Prof.}}
\newcommand{\ProfDr}{\ds@academictitle{Prof.\,Dr.}}
\def\@cpd@warnIfEmpty#1#2{%
   \begingroup%
       \@cpd@emptytest={#1}%
       \edef\@cpd@param{\the\@cpd@emptytest}%
   \expandafter\endgroup%
   \ifx\@cpd@param\@empty\relax%
       \message{^^JWARNING: empty '#2' argument.^^J}%
   \fi
}
\def\city#1{%
   \city@tk={#1}\@citytrue%
   \ignorespaces%
}
\def\sourcenr#1{%
   \sourcenr@tk={#1}\@sourcenrtrue%
   \ignorespaces%
}
\def\source#1{%
   \source@tk={#1}\@sourcetrue%
   \ignorespaces%
}
\def\ds@day#1{%
   \day@tk={#1}\@daytrue\@datetrue%
   \ignorespaces%
}
\def\ds@month#1{%
   \from@month=#1\@datetrue%
   \ignorespaces%
}
\def\months#1{%
   \@months#1;%
   \ignorespaces%
}
\def\ds@year#1{%
   \year@tk={#1}\@yeartrue\@datetrue%
   \ignorespaces%
}
\def\issue#1{%
   \issue@tk={#1}\@issuetrue%
   \ignorespaces%
}
\def\pages#1{%
   \pages@tk={#1}\@pagestrue%
   \ignorespaces%
}
\def\tournament#1{%
   \tournament@tk={#1}\@tournamenttrue%
   \ignorespaces%
}
\def\award#1{%
    \@cpd@warnIfEmpty{#1}{award}%
    \award@tk={#1}\@awardtrue%
    \ignorespaces%
}
\def\version#1{%
    \@cpd@warnIfEmpty{#1}{version}%
    \version@tk={#1}\@versiontrue%
    \ignorespaces%
}
\def\after#1{%
    \@cpd@warnIfEmpty{#1}{after}%
    \after@tk={#1}\@aftertrue%
    \ignorespaces%
}
\def\correction#1{%
    \@cpd@warnIfEmpty{#1}{correction}%
    \correction@tk={#1}\@correctiontrue%
    \ignorespaces%
}
\def\dedication#1{%
    \@cpd@warnIfEmpty{#1}{dedication}%
    \dedic@tk={#1}\@dedicationtrue%
    \ignorespaces%
}
\def\fidealbum#1{%
   \fidealbum@tk={#1}\@fidealbumtrue%
   \ignorespaces%
}
\def\pieces{%
   \@ifnextchar[%
   {\x@pieces}%
   {\@pieces}%
}
\def\x@pieces[#1]{%
   % We should parse the given piececounts
   \setboolean{cpd@checkPieceCounts}{true}%
   \@parseWhiteAndBlackCount#1+\e@list
   \@pieces%
}
\def\@parseWhiteAndBlackCount#1+#2+{%
   \setcounter{cpd@defWhitePieces}{#1}%
   \setcounter{cpd@defBlackPieces}{#2}%
   \futurelet\n@xt\cpd@checkNeutral%
}
\let\cpd@nextproc=\relax%
\def\cpd@checkNeutral{%
    \if\n@xt\relax%
        \let\cpd@nextproc=\relax%
    \else%
        \let\cpd@nextproc=\@parseNeutralCount%
    \fi%
    \cpd@nextproc%
}
\def\@parseNeutralCount#1+{%
   \setcounter{cpd@defNeutralPieces}{#1}%
}
\def\@pieces#1{%
   \pieces@tk={#1}\@piecestrue%
   \ignorespaces%
}
\newcommand{\fen}[2][]{%
   \ifthenelse{\equal{#1}{}}%
      {}% Do nothing
      {%
         \setboolean{cpd@checkPieceCounts}{true}%
         \@parseWhiteAndBlackCount#1+\e@list%
      }%
   \fen@tk={#2}\setboolean{@cpd@fen}{true}%
   \ignorespaces%
}
\def\fieldtext#1{%
   \fieldtext@tk={#1}\@fieldtexttrue%
   \ignorespaces%
}
\def\nofields#1{%
   \nofields@tk={#1}\@nofieldstrue%
   \ignorespaces%
}
\let\nosquares\nofields
\def\gridlines#1{%
   \gridlines@tk={#1}\@gridlinestrue%
   \ignorespaces%
}
\def\fieldframe#1{%
   \fieldframe@tk={#1}\@fieldframetrue%
   \ignorespaces%
}
\def\stipulation#1{%
   \stipulation@tk={#1}\@stipulationtrue%
   \ignorespaces%
}
\def\condition{%
   \@ifstar{\x@condtrue\@condition}{\@condition}%
}
\def\@condition#1{%
   \condition@tk={#1}\@conditiontrue%
   \ignorespaces%
}
\def\twins{%
   \@ifstar{\x@twinstrue\@twins}{\@twins}%
}
\def\@twins#1{%
   \twins@tk={#1}\@twinstrue%
   \ignorespaces%
}
\def\remark#1{%
   \remark@tk={#1}\@remarktrue%
   \ignorespaces%
}
\def\piecedefs#1{%
   \piecedefs@tk={#1}\@piecedefstrue%
   \ignorespaces%
}
\def\Co#1{%
   \ifx#1+\@computertrue\computer@tk={+}\fi%
   \ignorespaces%
}
\long\def\solution#1{%
   \sol@tk={#1}\global\s@lutrue%
   \ignorespaces%
}
\def\themes#1{%
   \theme@tk={#1}\@themetrue%
   \ignorespaces%
}
\def\genre#1{%
   \relax% Currently not used within diagram.sty
}
\long\def\comment#1{%
   \comment@tk={#1}\@commenttrue%
   \ignorespaces%
}
\long\def\judgement#1{%
   \judgement@tk={#1}\@judgementtrue%
   \ignorespaces%
}
\def\noframe{%
   \@vframefalse\@hframefalse%
   \ignorespaces%
}
\def\noinnerframe{%
   \@leaveOuterfalse\@vframefalse\@hframefalse%
   \ignorespaces%
}
\def\verticalcylinder{%
   \@vframefalse%
   \ignorespaces%
}
\def\horizontalcylinder{%
   \@hframefalse%
   \ignorespaces%
}
\def\stdgrid{%
   \@stdgridtrue%
   \ignorespaces%
}
\let\gridchess=\stdgrid
\let\magic=\fieldframe
\let\tourn=\tournament
\let\dedic=\dedication
\let\stip=\stipulation
\let\cond=\condition
\let\rem=\remark
\let\sol=\solution
\def\develop{%
   \@developtrue%
   \ignorespaces%
}
\def\showcomputer{%
   \setboolean{showcomputer}{true}%
   \ignorespaces%
}
\def\nocomputer{%
   \setboolean{showcomputer}{false}%
   \ignorespaces%
}
\def\putsol{\immediate\closeout\s@lfd\input\jobname.sol\cl@arsol}
\def\widedias{\@widediastrue\diagcenter}
\def\nowidedias{\@widediasfalse}
\def\normalnames{\normal@namestrue}
\def\reversednames{\normal@namesfalse}
\def\makeaindex{%
   \@dia@index%
   \newindex[thediag]{author}{adx}{and}{Autorenverzeichnis}%
   \@aindextrue\reversednames%
}

\def\makesindex{%
   \@dia@index%
   \newindex[thediag]{source}{sdx}{snd}{Quellenregister}%
   \@sindextrue%
}

\def\maketindex{%
   \@dia@index%
   \newindex[thediag]{theme}{tdx}{tnd}{Themenregister}%
   \@tindextrue%
}

\def\authorindex{{\let\@idxitem\@aidxitem\printindex[author]}}
\def\sourceindex{\printindex[source]}
\def\themeindex{\printindex[theme]}
\def\DefinePieces#1#2#3{%
   \@setPieceColor#1\@setPieceSpec#2\@setPieceRotation#3%
   \cpd@piecedef@rotations%
   \expandafter\xdef\csname\ds@black\ds@white\ds@bishop\endcsname{%
      \noexpand\ch@fig{20}%
   }%
   \expandafter\xdef\csname\ds@black\ds@black\ds@bishop\endcsname{%
      \noexpand\ch@fig{32}%
   }%
   \expandafter\xdef\csname\ds@white F\endcsname{{\chessfont\ }}
   \expandafter\xdef\csname\ds@black F\endcsname{{\chessfont\char144}}
   \expandafter\xdef\csname\ds@white Nr\endcsname{%
      \noexpand\ch@fig{109}%
   }%
   \expandafter\xdef\csname\ds@neutral Nr\endcsname{%
      \noexpand\ch@fig{115}%
   }%
   \expandafter\xdef\csname\ds@black Nr\endcsname{%
      \noexpand\ch@fig{121}%
   }%
   \expandafter\xdef\csname\ds@white Gh\endcsname{%
      \noexpand\ch@fig{112}%
   }%
   \expandafter\xdef\csname\ds@neutral Gh\endcsname{%
      \noexpand\ch@fig{118}%
   }%
   \expandafter\xdef\csname\ds@black Gh\endcsname{%
      \noexpand\ch@fig{124}%
   }%
   \expandafter\xdef\csname\ds@white C\endcsname{%
      \noexpand\ch@fig{145}%
   }%
   \expandafter\xdef\csname\ds@neutral C\endcsname{%
      \noexpand\ch@fig{151}%
   }%
   \expandafter\xdef\csname\ds@black C\endcsname{%
      \noexpand\ch@fig{157}%
   }%
}
\def\Imi{\ch@fig{157}}
\def\wE{\ch@fig{216}}
\def\nE{\ch@fig{222}}
\def\sE{\ch@fig{228}}
\def\wX{\ch@fig{180}}
\def\nX{\ch@fig{186}}
\def\sX{\ch@fig{192}}
\def\cpd@whiteField{{\chessfont\ }}
\def\cpd@blackField{{\chessfont\char144}}

\newboolean{above@newline}
\newcommand{\above@newline}{\ifthenelse{\boolean{above@newline}}{\linebreak}{\setboolean{above@newline}{true}}}
\def\dia@above{%
   \setboolean{above@newline}{false}%
   \@dia@number%
   \@dia@authors%
   \@dia@city%
   \@dia@after%
   \@dia@version%
   \@dia@source%
   \@dia@correction%
   \@dia@tournament%
   \@dia@award%
   \@dia@dedic%
   \@dia@fidealbum%
}
\def\dia@below{%
   \bgroup%
   \if@stipulation%
      \@dia@stipulation%
   \fi%
   \ifx@cond\else%
      \@dia@condition%
   \fi%
   \ifx@twins\else%
      \@dia@twins%
   \fi%
   \@dia@piecedefs%
   \@dia@remark%
   \ifthenelse{\boolean{@solafterdiagram}}{%
      \below@newline%
      \the\sol@tk%
   }{}%
   \noindent\hbox{}\newline\hbox{}%
   \egroup%
}
\def\@dia@number{%
   %\ifdi@no\above@newline{\authorfont\thediag}\fi%
   \ifthenelse{\boolean{@cpd@numbering@local}}{%
      \above@newline{\authorfont\thediag}%
   }{}%
}
\def\@dia@authors{%
   \ifauth@r%
      \ifnormal@names%
         \above@newline
         {\authorfont\the\aut@tk}%
      \else%
         \let\@action=\@dia@writename% Parse the list of authors
       \@parseTokenlist\aut@tk;
      \fi%
   \fi%
}
\def\@show@city#1;{\if@notfirst\ \slash\ \else\@notfirsttrue\fi#1}

\def\p@rsecity#1; {\@show@city#1;\l@@klist}

\def\@dia@city{%
   \ifthenelse{\boolean{showcity}}{%
       \if@city%
          \above@newline%
          \bgroup%
          \cityfont\@notfirstfalse%
          \let\@action=\p@rsecity\@parseTokenlist\city@tk;%
          \egroup%
       \fi%
   }{}%
}

\def\@dia@after{%
   \if@after%
      \bgroup%
      \above@newline%
      \dedicfont\the\after@tk%
      \egroup%
   \fi%
}

\def\@dia@version{%
   \if@version%
      \above@newline%
      \bgroup%
      \dedicfont\the\version@tk%
      \egroup%
   \fi%
}

\def\@dia@date{%
   \ifnum\from@month>\z@%
      \if@day%
         \the\day@tk.\write@month\from@month%
      \else%
         \write@month\from@month%
      \fi%
      \ifnum\to@month>\z@--\write@month\to@month\fi%
      \if@day.\else/\fi%
   \fi%
   \if@year\the\year@tk\fi%
}

\def\@dia@source{%
   \if@source%
      \above@newline%
      \bgroup%
      \sourcefont%
      \if@sourcenr\the\sourcenr@tk\ \fi
      \the\source@tk%
      \if@date\ \ \fi\@dia@date%
      \if@issue\ \ \the\issue@tk\fi%
      \if@pages ,\ \the\pages@tk\fi%
      \egroup%
   \else%
      \if@tournament\else\if@date%
         \above@newline%
         \bgroup%
         \sourcefont%
         \@dia@date%
         \egroup%
      \fi\fi%
   \fi%
}

\def\@dia@correction{%
   \if@correction%
      \above@newline%
      \bgroup%
      \dedicfont\the\correction@tk%
      \egroup%
   \fi%
}

\def\@dia@tournament{%
   \if@tournament
      \above@newline%
      \bgroup%
      \awardfont%
      \the\tournament@tk
      \if@source\else\if@date%
         \ \ \@dia@date%
      \fi\fi%
      \egroup%
   \fi%
}

\def\@dia@award{%
   \if@award%
      \above@newline%
      \bgroup%
      \awardfont\the\award@tk%
      \egroup%
   \fi%
}

\def\@dia@dedic{%
   \if@dedication%
      \above@newline%
      \bgroup%
      \dedicfont\the\dedic@tk%
      \egroup%
   \fi%
}

\def\@show@album#1/#2;{#1 FIDE-Album #2}

\def\@dia@fidealbum{%
   \if@fidealbum%
      \above@newline%
      {\expandafter\@show@album\the\fidealbum@tk;}%
   \fi%
}

\def\@twinskip{\ \ }

\def\@dia@stipulation{%
   \if@stipulation%
      \bgroup%
      \stipfont%
      \the\stipulation@tk%
      \ifx@twins%
         \let\below@newline\@twinskip%
         \@dia@twins%
      \else\ifx@cond%
         \let\below@newline\@twinskip%
         \@dia@condition%
      \fi\fi%
      \egroup%
      \let\below@newline\newline%
   \else%
      \x@twinsfalse%
      \x@condfalse%
      \let\below@newline\relax%
   \fi%
}

\def\x@write@twin#1; {%
   \hskip1em#1%
   \@lefttrue\let\below@newline\newline%
   \let\@action\write@twins%
   \l@@klist%
}

\def\write@twins#1; {%
   \setbox\@test@box=\hbox{#1\if@left~~\fi}%
   \ifdim\wd\@test@box>4\sq@width%
      \below@newline%
      \@lefttrue%
      #1%
   \else%
      \if@left%
         \below@newline%
      \fi%
      \noindent\hbox to 4\sq@width{#1\hfil}%
      \if@left%
         \@leftfalse%
      \else%
         \@lefttrue%
      \fi%
   \fi%
   \let\below@newline\newline%
   \l@@klist%
}

\def\@dia@twins{%
   \if@twins%
      \bgroup%
      \@lefttrue%
      \remfont%
      \ifx@twins%
         \let\@action=\x@write@twin%
      \else%
         \let\@action=\write@twins%
      \fi%
      \@parseTokenlist\twins@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\@dia@condition{%
   \if@condition%
      \bgroup%
      \@lefttrue%
      \remfont%
      \ifx@cond%
         \let\@action=\x@write@twin%
      \else%
         \let\@action=\write@twins%
      \fi%
      \@parseTokenlist\condition@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\check@piecedef{%
    \ifx\next@piecedef\relax%
        \let\col@action=\relax%
    \else%
        \let\col@action=\@@piecedef%
    \fi%
    \col@action%
}
\def\@@piecedef#1{\csname#1\x@piecedef\endcsname\parse@piecedef}

\def\parse@piecedef{\futurelet\next@piecedef\check@piecedef}

\def\@piecedef#1#2#3{%
   \def\x@piecedef{#2}%
   \below@newline%
   \hbox{%
   \parse@piecedef#1\relax%
   \ = #3}%
}

\def\write@piecedefs#1; {%
   \@piecedef#1%
   \l@@klist%
}

\def\@dia@piecedefs{%
   \if@piecedefs%
      \bgroup%
      \@lefttrue%
      \let\below@newline\newline%
      \remfont\let\@action=\write@piecedefs%
      \@parseTokenlist\piecedefs@tk;%
      \egroup%
   \fi%
}

\def\@dia@remark{%
   \if@remark%
      \bgroup%
      \@lefttrue%
      \remfont\let\@action=\write@twins%
      \@parseTokenlist\remark@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\parse@params#1{%
   \ifcase\help@a\relax
      \label@tk={#1}\ifx\relax#1\else\@labeltrue\fi\or%
      \number@tk={#1}\ifx\relax#1\else\@numbertrue\fi\or%
      \aut@tk={#1}\ifx\relax#1\else\auth@rtrue\fi\or%
      \city@tk={#1}\ifx\relax#1\else\@citytrue\fi\or%
      \sourcenr@tk={#1}\ifx\relax#1\else\@sourcenrtrue\fi\or%
      \source@tk={#1}\ifx\relax#1\else\@sourcetrue\fi\or%
      \day@tk={#1}\ifx\relax#1\else\@daytrue\fi\or%
      \from@month=#1\or%
      \to@month=#1\or%
      \year@tk={#1}\ifx\relax#1\else\@yeartrue\fi\or%
      \issue@tk={#1}\ifx\relax#1\else\@issuetrue\fi\or%
      \pages@tk={#1}\ifx\relax#1\else\@pagestrue\fi\or%
      \tournament@tk={#1}\ifx\relax#1\else\@tournamenttrue\fi\or%
      \award@tk={#1}\ifx\relax#1\else\@awardtrue\fi\or%
      \after@tk={#1}\ifx\relax#1\else\@aftertrue\fi\or%
      \version@tk={#1}\ifx\relax#1\else\@versiontrue\fi\or%
      \correction@tk={#1}\ifx\relax#1\else\@correctiontrue\fi\or%
      \dedic@tk={#1}\ifx\relax#1\else\@dedicationtrue\fi\or%
      \theme@tk={#1}\ifx\relax#1\else\@themetrue\fi\or%
      \twins@tk={#1}\ifx\relax#1\else\@twinstrue\fi\or%
      \computer@tk={#1}\or%
      \comment@tk={#1}\ifx\relax#1\else\@commenttrue\fi\or%
      \judgement@tk={#1}\ifx\relax#1\else\@judgementtrue\fi\or%
      \sol@tk={#1}%
   \fi%
   \advance\help@a \@ne%
   \l@@klist%
}

\def\split@param#1{%
   \@labelfalse\@numberfalse\auth@rfalse\@cityfalse%
   \@sourcenrfalse\@sourcefalse\@dayfalse\@yearfalse%
   \@issuefalse\@pagesfalse\@tournamentfalse\@awardfalse%
   \@afterfalse\@versionfalse\@correctionfalse\@dedicationfalse%
   \@themefalse\@twinsfalse\@commentfalse\@judgementfalse%
   \help@a=\z@%
   \let\@action=\parse@params\l@@klist#1\e@list%
}
\newcommand{\solpar}{\par}
\def\@dia@solution{%
   \bgroup%
   \parindent\z@%
   \parskip\tw@\p@%
   {\bfseries%
      \noindent\if@label\showlabel{\the\label@tk}\fi%
      \if@number\the\number@tk) \fi%
      \ifauth@r%
         \ifnormal@names%
            \the\aut@tk%
         \else%
            {\@notfirstfalse% We are the first one
            \def\name@sep{, }%
            \let\@action=\@sol@writename%
            \@parseTokenlist\aut@tk;}:%
         \fi%
         \newline%
      \fi%
   }%
   \if@develop\if@judgement\the\judgement@tk\solpar\fi\fi%
   \the\sol@tk\solpar%
   \if@comment\the\comment@tk\solpar\fi%
   \egroup%
}
\grid@width=0.6\p@
\inner@frame=0.6\p@
\outer@frame=1.2\p@
\space@frame=\outer@frame
\v@frame@dist=\tw@\p@%
\h@frame@dist=\tw@\p@%
\space@frame@dist=\z@
\v@space@dist=1em
\def\@show@figurine{%
   \noindent%
   \@figurine@number%
   \@figurine@author%
   \@figurine@city%
   \@figurine@after%
   \@figurine@correction%
   \@figurine@version%
   \@figurine@source%
   \@figurine@tournament%
   \@figurine@award%
   \@figurine@dedic%
   \@figurine@pieces%
   \@figurine@stip%
   \@figurine@twins%
   \@figurine@conditions%
   \@figurine@remarks%
   \@figurine@computer%
}
\def\@figurine@number{{\authorfont\thediag)}}

\def\p@rseauthor@figurine#1,#2; {%
   \if@notfirst, \else\@notfirsttrue\fi#2 #1%
   \l@@klist%
}

\def\@figurine@author{%
   {\ifauth@r%
      \authorfont\@notfirstfalse%
      \let\@action=\p@rseauthor@figurine%
      \@parseTokenlist\aut@tk;%
      \ \ %
   \fi}%
}

\def\@figurine@city{%
   {\if@city%
      \cityfont\@notfirstfalse%
      \let\@action=\p@rsecity\@parseTokenlist\city@tk;%
      \ \ \ %
   \fi}%
}

\def\@figurine@after{\if@after{\dedicfont\ \ \the\after@tk}\fi}

\def\@figurine@correction{%
   \if@correction{\dedicfont\ \ \the\correction@tk}\fi%
}

\def\@figurine@version{%
   \if@version{\dedicfont\ \ \the\version@tk}\fi%
}

\def\@figurine@source{%
   {\if@source%
      \sourcefont%
      \if@sourcenr\the\sourcenr@tk\ \fi%
      \the\source@tk%
      \if@date\ \ \fi\@dia@date%
      \if@issue , \the\issue@tk\fi%
      \if@pages , \the\pages@tk\fi%
   \fi}%
}

\def\@figurine@tournament{%
   \if@tournament{\awardfont\ \ \the\tournament@tk}\fi%
}

\def\@figurine@award{%
   \if@award{\awardfont\ \ \the\award@tk}\fi%
}

\def\@figurine@dedic{%
   \if@dedication{\awardfont\ \ \the\dedic@tk}\fi%
}
\def\show@squares#1\e@list{\ch@fig{\the\help@a}#1, }

\def\@figurine@pieces{%
   {\if@pieces%
      \let\@action=\p@rsepieces%
      \let\piece@job\show@squares%
      \@parseTokenlist\pieces@tk,%
   \fi}%
}
\def\@figurine@stip{%
   \if@stipulation{\stipfont\ \ \the\stipulation@tk}\fi%
}

\def\@figurine@conditions{%
   \if@condition{\remfont\ \ \the\condition@tk}\fi%
}

\def\@figurine@twins{%
   \if@twins{\remfont\ \ \the\twins@tk}\fi%
}

\def\@figurine@computer{%
   \ifthenelse{\boolean{showcomputer}}{%
      \if@computer\ \computerproofedsymbol\fi%
   }{}%
}

\def\@figurine@remarks{%
   \if@remark{\stipfont\ \ \the\remark@tk}\fi%
}
\def\do@dia@job{\@write@sol\ifvmode\noindent\fi\unhbox\dia@box}
\def\solhead#1{{\split@param{#1}\@dia@solution}}
\def\@write@sol{%
   \ifs@lu%
      \immediate\write\s@lfd{%
         \noexpand\solhead{%
            {\the\label@tk}%
            {\thediag}%
            {\the\aut@tk}%
            {\the\city@tk}%
            {\the\sourcenr@tk}%
            {\the\source@tk}%
            {\the\day@tk}%
            {\the\from@month}%
            {\the\to@month}%
            {\the\year@tk}%
            {\the\issue@tk}%
            {\the\pages@tk}%
            {\the\tournament@tk}%
            {\the\award@tk}%
            {\the\after@tk}%
            {\the\version@tk}%
            {\the\correction@tk}%
            {\the\dedic@tk}%
            {\the\theme@tk}%
            {\the\twins@tk}%
            {\the\computer@tk}%
            {\the\comment@tk}%
            {\the\judgement@tk}%
            {\the\sol@tk}%
         } %end of \solhead
      }%
   \fi
}
\def\@months#1-#2;{\from@month=#1\to@month=#2\@datetrue}
\def\@dia@writename#1; {\above@newline{\authorfont\@dianame#1; }\l@@klist}
\def\@sol@writename#1; {\sep@names\@solname#1; \l@@klist}
\def\name@sep{,\ }
\def\sep@names{\if@notfirst\name@sep\else\@notfirsttrue\fi}
\def\@checkshort#1/#2#3;{%
   \@shortformtrue%
   \ifx#2\e@list\relax%
      \@shortformfalse%
   \fi%
}
\def\short@christian#1#2-{%
   \if@notfirst -\else\@notfirsttrue\fi%
   #1.%
   \l@@klist%
}

\def\@write@christian#1/#2;{#1}

\def\write@christian#1;{%
   \@checkshort#1/\e@list;%
   \if@shortform\@write@christian#1;\else#1\fi%
}

\def\@write@short#1/#2;{#2}

\def\write@short#1;{%
   \@checkshort#1/\e@list;%
   \if@shortform%
      \@write@short#1;%
   \else%
      {\@notfirstfalse\let\@action\short@christian\l@@klist#1-\e@list}%
   \fi%
}
\def\@fullname#1, #2; {\write@christian#2; #1}
\def\@sirname#1, #2; {#1}
\def\@short#1, #2; {\write@short#2;\ #1}
\def\@noname#1, #2; {}
\def\@normalname#1; {#1}
\def\space@vertical{\space@verticaltrue}
\def\space@horizontal{\space@verticalfalse}
\def\cl@arsol{\immediate\openout\s@lfd=\jobname.sol\relax}
\def\getc@lor#1{%
   \if#1\ds@white%
     \help@a\z@\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterWhite%
   \else\if#1\ds@neutral%
     \help@a=6\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterNeutral%
   \else\if#1\ds@black%
     \help@a=12\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterBlack%
   \else\errmessage{invalid color!}%
   \fi\fi\fi%
   \getpi@ce%
}

\def\get@text#1{\text@tk={#1}\read@square}

\def\getpi@ce#1{%
   \IfStrEqCase{#1}{%
       {\ds@pawn}{}%
       {\ds@knight}{\advance\help@a\@ne}%
       {\ds@bishop}{\advance\help@a\tw@}%
       {\ds@rook}{\advance\help@a\thr@@}%
       {\ds@queen}{\advance\help@a\f@ur}%
       {\ds@king}{\advance\help@a 5}%
       {C}{%
           \let\cpd@stepcounterPieces\relax
           \advance\help@a 145%
       }%
       {E}{\advance\help@a 216}%
       {X}{\advance\help@a 180}%
   }[\errmessage{invalid piece!}]%
   \futurelet\r@tate\chkr@tate%
}

\def\chkr@tate{%
   \if\r@tate \ds@rotation@upsidedown\advance\help@a 108\let\nextpr@c=\skipr@t\else%
   \if\r@tate \ds@rotation@left\advance\help@a 36\let\nextpr@c=\skipr@t\else%
   \if\r@tate \ds@rotation@right\advance\help@a 72\let\nextpr@c=\skipr@t\else%
   \let\nextpr@c\piece@job\fi\fi\fi%
   \nextpr@c%
}
\def\skipr@t#1{\piece@job}
\def\l@@k{\futurelet\whatsnext\parsefi@lds}
\def\parsefi@lds{%
   \if\whatsnext\e@list%
      \let\nextpr@c\relax%
   \else
      \let\nextpr@c\read@square%
   \fi%
   \nextpr@c%
}

\def\set@current@square@index#1#2{%
  \setcounter{cpd@current@square@index}{#1+\value{cpd@lines}*#2}%
}
\def\set@current@square@value#1{%
  \expandafter%
    \xdef\csname cpd@square@\roman{cpd@current@square@index}\endcsname{#1}%
}
\def\get@current@square@value{%
  \setcounter{cpd@current@square@value}%
    {\csname cpd@square@\roman{cpd@current@square@index}\endcsname}%
}
\def\@cpd@setpiece{%
    \ifthenelse{\value{cpd@plane}=\value{cpd@current@plane}}{%
      \cpd@stepcounterPieces%
      \set@current@square@index{\value{cpd@line}}{\value{cpd@row}}%
      \get@current@square@value%
      \ifthenelse{\value{cpd@current@square@value}=\m@ne}%
        {\set@current@square@value{\the\help@a}}%
        {\ifthenelse{\value{cpd@current@square@value}=144}%
          {\set@current@square@value{\the\help@a+18}}%
          {\errmessage{Trying to set a piece to an occupied square.}}}%
    }{}%
}
\def\set@piece{%
    \@cpd@setpiece%
    \l@@k%
}
\def\set@nofield, {%
    \ifthenelse{\value{cpd@plane}=\value{cpd@current@plane}}{%
      \set@current@square@index{\value{cpd@line}}{\value{cpd@row}}%
      \get@current@square@value%
      \ifthenelse{\value{cpd@current@square@value}=\m@ne}%
        {}% This is an empty white square, nothing to do
        {\ifthenelse{\value{cpd@current@square@value}=144}%
          {\set@current@square@value{\m@ne}}%
          {\errmessage{Trying to set a piece to an occupied square}}}%
    }{}%
    \l@@klist%
}
\def\set@frame, {%
    \ifthenelse{\value{cpd@plane}=\value{cpd@current@plane}}{%
      \@vGrid{\value{cpd@line}}{\value{cpd@row}}\@ne%
      \@hGrid{\value{cpd@line}}{\value{cpd@row}}\@ne%
      \addtocounter{cpd@line}{1}%
      \@vGrid{\value{cpd@line}}{\value{cpd@row}}\@ne%
      \addtocounter{cpd@line}{-1}%
      \addtocounter{cpd@row}{1}%
      \@hGrid{\value{cpd@line}}{\value{cpd@row}}\@ne%
    }{}%
    \l@@klist%
}
\def\e@list{\relax}
\def\l@@klist{\futurelet\nextlist\ch@cklst}
\def\ch@cklst{%
   \ifx\nextlist\e@list%
      \let\nextpr@c=\relax%
   \else%
      \let\nextpr@c=\@action%
   \fi%
   \nextpr@c%
}
\def\@cpd@handle@fen#1{%
   \ifx#1/\relax%
      \ifthenelse{\value{cpd@line}=8}%
      {%
         \setcounter{cpd@line}{0}%
         \addtocounter{cpd@row}{\m@ne}%
      }%
      {%
         \errmessage{FEN: there is now row to end here.}%
      }%
   \fi% FEN space issue
   \IfSubStr{12345678}{#1}{%
      \addtocounter{cpd@line}{#1}%
   }{}%
   \IfSubStr{KQRBNP}{#1}{%
      \let\cpd@stepcounterPieces\cpd@stepcounterWhite%
      \IfStrEqCase{#1}{%
          {K}{\help@a=5}%
          {Q}{\help@a=4}%
          {R}{\help@a=3}%
          {B}{\help@a=2}%
          {N}{\help@a=1}%
          {P}{\help@a=0}%
      }
      \@cpd@setpiece%
      \addtocounter{cpd@line}{\@ne}%
   }{}%
   \IfSubStr{kqrbnp}{#1}{%
      \let\cpd@stepcounterPieces\cpd@stepcounterBlack%
      \IfStrEqCase{#1}{%
          {k}{\help@a=17}%
          {q}{\help@a=16}%
          {r}{\help@a=15}%
          {b}{\help@a=14}%
          {n}{\help@a=13}%
          {p}{\help@a=12}%
      }
      \@cpd@setpiece%
      \addtocounter{cpd@line}{\@ne}%
   }{}%
}
\def\@cpd@parse@fen#1{\@cpd@handle@fen#1\l@@klist}
\def\p@rsepieces#1, {\getc@lor#1\e@list\l@@klist}
\def\p@rsetext#1, {\get@text#1\e@list\l@@klist}
\def\set@text{%
    \ifthenelse{\value{cpd@plane}=\value{cpd@current@plane}}{%
      \raise\value{cpd@row}\sq@width\hbox to \z@{%
         \hskip\value{cpd@line}\sq@width%
         \vbox to \sq@width{\vss%
         \hbox to \sq@width{%
           \hss%
           {\the\text@tk}%
           \hss%
         }\vss}%
         \hss%
      }%
    }{}%
    \l@@klist%
}
\def\p@rseauthor#1; {\sh@wauthor#1;\l@@klist}
\def\read@square#1#2{%
   \setcounter{cpd@line}{`#1-`a}%
   \setcounter{cpd@row}{#2-1}%
   \read@plane%
}
\def\read@plane@normal{\plane@job}

\def\read@plane@stereo{\futurelet\plane@char\get@plane@stereo}

\def\get@plane@stereo{%
   \if\plane@char A%
      \setcounter{cpd@plane}{1}%
      \addtocounter{cpd@row}{-2}%
      \addtocounter{cpd@line}{-2}%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char B%
      \setcounter{cpd@plane}{2}%
      \addtocounter{cpd@row}{-2}%
      \addtocounter{cpd@line}{-2}%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char C%
      \setcounter{cpd@plane}{3}%
      \addtocounter{cpd@row}{-2}%
      \addtocounter{cpd@line}{-2}%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char D%
      \setcounter{cpd@plane}{4}%
      \addtocounter{cpd@row}{-2}%
      \addtocounter{cpd@line}{-2}%
      \let\@plane@job=\skip@plane%
   \else%
      \setcounter{cpd@plane}{0}%
      \let\@plane@job=\plane@job%
   \fi\fi\fi\fi%
   \@plane@job%
}

\def\skip@plane#1{\plane@job}

\def\read@plane@space#1{%
    \setcounter{cpd@plane}{`#1-`A}%
    \plane@job%
}
\def\@vGrid#1#2#3{%
   \raise#2\sq@width\hbox to \z@{%
      \hskip#1\sq@width\hskip-.5\grid@width%
      \vrule height#3\sq@width width\grid@width\hss%
   }%
}

\def\@hGrid#1#2#3{%
   \raise#2\sq@width\hbox to \z@{%
      \hskip#1\sq@width%
      \vrule width#3\sq@width height .5\grid@width depth%
      .5\grid@width\hss%
   }%
}
\def\@selGrid#1#2, {%
    \ifthenelse{\value{cpd@plane}=\value{cpd@current@plane}}{%
      \if#1h%
         \@hGrid#2%
      \else\if#1v%
         \@vGrid#2%
      \else%
         \errmessage{Wrong GridSelector #1}%
      \fi\fi%
    }{}%
    \l@@klist%
}
\def\@stdgrid{%
   \setbox\plane@box=\vbox{\hbox{%
      \help@a=\tw@%
      \whiledo{\help@a<\value{cpd@lines}}{%
         \@vGrid{\the\help@a}{0}{\value{cpd@rows}}%
         \advance\help@a\tw@%
      }%
      \help@a=\tw@%
      \whiledo{\help@a<\value{cpd@rows}}{%
            \@hGrid{0}{\the\help@a}{\value{cpd@lines}}%
            \advance\help@a\tw@%
      }%
      \box\plane@box
   }}%
}
\def\ds@xlabel#1{%
   \label@tk={#1}\@labeltrue%
}

\def\@set@label#1;{\ifds@label\label{#1}\fi}
\def\init@vars{%
   \global\s@lufalse
   \ifthenelse{\boolean{@cpd@numbering@global}}{%
      \setboolean{@cpd@numbering@local}{true}%
   }{%
      \setboolean{@cpd@numbering@local}{false}%
   }%
   \setboolean{cpd@checkPieceCounts}{false}%
   \setcounter{cpd@defWhitePieces}{\z@}%
   \setcounter{cpd@defBlackPieces}{\z@}%
   \setcounter{cpd@defNeutralPieces}{\z@}%
   \setcounter{cpd@whitePieces}{\z@}%
   \setcounter{cpd@blackPieces}{\z@}%
   \setcounter{cpd@neutralPieces}{\z@}%
   \setcounter{cpd@line}{0}%
}

\def\clear@board{%
   \ifthenelse{\boolean{allwhite}\and\boolean{switchcolors}}%
      {\errmessage{'allwhite' and 'switchcolors' do not make sense used together.}}%
      {\@whitefield=\m@ne\@blackfield=144}%
   \ifthenelse{\boolean{allwhite}}{\@blackfield=\m@ne}{}%
   \ifthenelse{\boolean{switchcolors}}{\@whitefield=144\@blackfield=\m@ne}{}%
   \setcounter{cpd@row}{0}%
   \whiledo{\value{cpd@row}<\value{cpd@rows}}{%
      \setcounter{cpd@line}{0}%
      \whiledo{\value{cpd@line}<\value{cpd@lines}}{%
         \set@current@square@index{\value{cpd@line}}{\value{cpd@row}}%
         \setcounter{cpd@helper}{%
                \value{cpd@current@plane}%
                +\value{cpd@line}%
                +\value{cpd@row}}%
         \ifthenelse{\isodd{\value{cpd@helper}}}%
           {\set@current@square@value{\@whitefield}}%
           {\set@current@square@value{\@blackfield}}%
        \addtocounter{cpd@line}{\@ne}%
      }%
      \addtocounter{cpd@row}{\@ne}%
   }%
}

\def\put@row#1{%
   \setcounter{cpd@row}{#1}%
   \setcounter{cpd@row@display}{#1 + 1}%
   \setcounter{cpd@line}{0}%
   \hbox{%
      \ifthenelse{\boolean{legend}}{{%
         \llap{\raise .1\sq@width\hbox{\legendfont\arabic{cpd@row@display}\ \ }}%
      }}{}%
      \if@stereo%
         \ifthenelse{\value{cpd@current@plane}>0}{%
            \ifthenelse{\value{cpd@row} = 3}{%
               \llap{\cpd@boardfont c6\ }%
            }{}%
            % \fi%
         }{}%
         % \fi%
      \fi%
      % \hbox to \z@{\vbox to \sq@width{}}%
      \set@current@square@index{\value{cpd@line}}{#1}%
      \begin{tikzpicture}[x=\sq@width,y=\sq@width]%
          \useasboundingbox (0, 0) rectangle (\value{cpd@lines}, 1);%
          \whiledo{\value{cpd@line} < \value{cpd@lines}}{%
              \get@current@square@value%
              \ifthenelse{\value{cpd@current@square@value}=\m@ne}%
              {}%
              {%
                  \draw (\value{cpd@line}+.5, .5)%
                  node {{\chessfont\char\value{cpd@current@square@value}}};%
              }%
              \addtocounter{cpd@line}{1}%
              \addtocounter{cpd@current@square@index}{1}%
          }%
      \end{tikzpicture}%
   }%
}
\def\cpd@fen@parseTokenlist#1{\expandafter\l@@klist\the#1\e@list}
\def\@parseTokenlist#1#2{\expandafter\l@@klist\the#1#2 \e@list}
\def\@addToPlane#1{%
   \setbox\plane@box=\vbox{\hbox{%
      \@parseTokenlist#1,%
      \box\plane@box%
   }}%
}
\def\put@plane{%
    % We might want gridchess
    \if@stdgrid%
        \@stdgrid%
    \fi%
    % Let us first set the fieldframes
    \if@fieldframe%
        \let\@action\read@square%
        \let\plane@job\set@frame%
        \@addToPlane\fieldframe@tk%
    \fi%
    % Now we set text to all squares which are given using \fieldtext
    \if@fieldtext%
        \let\@action\p@rsetext%
        \let\plane@job\set@text%
        \@addToPlane\fieldtext@tk%
    \fi%
    % Then we should add the gridlines
    \if@gridlines%
        \let\@action\read@plane%
        \let\plane@job\@selGrid%
        \@addToPlane\gridlines@tk%
    \else%
        \if@stereo%
            \stereo@center%
        \fi%
    \fi%
    % In an 'allwhite' diagram we display dotted lines
    \ifthenelse{\boolean{allwhite}}{%
        \setbox\plane@box=\vbox{\hbox{%
            \begin{tikzpicture}[x=\sq@width,y=\sq@width]%
                \useasboundingbox
                    (0, 0) rectangle (\value{cpd@lines}, \value{cpd@rows});
            \setcounter{field@border}{1}%
            \whiledo{\value{field@border}<\value{cpd@lines}}{%
                \draw[densely dotted]
                    (\value{field@border},0)
                    --
                    (\value{field@border},\value{cpd@rows});
                \addtocounter{field@border}{\@ne}%
            }%
            \setcounter{field@border}{1}%
            \whiledo{\value{field@border}<\value{cpd@rows}}{%
                \draw[densely dotted]
                    (0, \value{field@border})
                    --
                    (\value{cpd@lines}, \value{field@border});
                \addtocounter{field@border}{\@ne}%
            }%
            \end{tikzpicture}%
            \box\plane@box%
        }}%
    }{}%
    % Now we should clear the board
    \clear@board%
    % Let us now parse the list of pieces
    \ifthenelse{\boolean{@cpd@fen}}{%
        \ifthenelse{\value{cpd@rows}=8}{}{\errmessage{FEN is only allowed for 8x8 boards.}}% FEN space issue
        \ifthenelse{\value{cpd@lines}=8}{}{\errmessage{FEN is only allowed for 8x8 boards.}}% FEN space issue
        \setcounter{cpd@row}{7}%
        \setcounter{cpd@line}{0}%
        \let\@action\@cpd@parse@fen%
        \cpd@fen@parseTokenlist\fen@tk\e@list% FEN space issue
    }{}%
    \if@pieces%
        \let\@action\p@rsepieces%
        \let\piece@job\l@@k\let\plane@job\set@piece%
        \@parseTokenlist\pieces@tk,%
    \fi%
    % Now we clear all fields, which are given using \nofields
    \if@nofields%
        \let\@action\read@square%
        \let\plane@job\set@nofield%
        \@parseTokenlist\nofields@tk,%
    \fi%
    % Now we can put the pieces to the board
    \global\setbox\plane@box=\hbox{%
        \vbox{\rlap{\box\plane@box}}%
        \vbox{%
           \chessfont%
           \baselineskip=\z@\lineskip=\z@%
           \setcounter{cpd@row}{\value{cpd@rows} - 1}%
           \whiledo{\value{cpd@row} > -1}{%
              \put@row{\value{cpd@row}}%
              \addtocounter{cpd@row}{-1}%
           }%
        }%
        % Put a legend if wanted
        \ifthenelse{\boolean{legend}}{%
            \vbox to \z@{%
                \vbox to \z@{\vss}%
                \llap{\hbox{\hspace*{\inner@frame}%
                    \setcounter{cpd@line}{0}%
                    \setcounter{cpd@line@display}{`a}%
                    \whiledo{\value{cpd@line}<\value{cpd@lines}}{%
                        \hbox to \sq@width{\hfill%
                            {\legendfont\char\value{cpd@line@display}}%
                        \hfill}%
                        \addtocounter{cpd@line}{1}%
                        \addtocounter{cpd@line@display}{1}%
                    }
                }}%
            \vss}%
        }{}%
    }%
}
\def\put@sqs@normal{%
   \put@plane%
   \setbox\sq@box=\hbox{%
      \inner@henbox{\box\plane@box}%
   }%
}
\def\put@sqs@stereo{%
   \setbox\sq@box=\hbox{\hfil\vbox{%
      \vskip\v@space@dist%
      \setcounter{cpd@current@plane}{4}%
      \whiledo{\value{cpd@current@plane}>-1}{%
         \ifthenelse{\value{cpd@current@plane}=0}{%
            \setcounter{cpd@lines}{8}%
            \setcounter{cpd@rows}{8}%
         }{%
            \setcounter{cpd@lines}{4}%
            \setcounter{cpd@rows}{4}%
         }%
         % Now we should clear the board
         \begingroup% We need this for inner loops!
            \clear@board%
            \put@plane%
         \endgroup%
         \hbox to \bd@width{%
            \hfil%
            \inner@henbox{\box\plane@box}%
            \ifcase\value{cpd@current@plane}\or%
               \rlap{{\cpd@boardfont\ A}}\or%
               \rlap{{\cpd@boardfont\ B}}\or%
               \rlap{{\cpd@boardfont\ C}}\or%
               \rlap{{\cpd@boardfont\ D}}%
            \fi%
            \hfil%
         }%
         \vskip\v@space@dist%
         \addtocounter{cpd@current@plane}{-1}%
      }%
   }\hfil}%
}

\def\stereo@center{%
   \ifthenelse{\value{cpd@current@plane}=0}{%
      \setbox\plane@box=\vbox{\hbox{%
         \@hGrid\tw@\tw@\f@ur\@hGrid\tw@ 6\f@ur%
         \@vGrid\tw@\tw@\f@ur\@vGrid6\tw@\f@ur%
         \box\plane@box%
      }}%
   }{}%
}
\def\put@sqs@space@vertical{%
    \setbox\sq@box=\hbox{\hfil\vbox{%
        \setcounter{cpd@current@plane}{\value{cpd@planes}-1}%
        \vskip\v@space@dist%
        \whiledo{\value{cpd@current@plane}>-1}{%
            \begingroup% We use inner loops!
            \clear@board%
            \put@plane%
            \hbox to \bd@width{%
                \inner@henbox{\box\plane@box}%
                \setcounter{cpd@current@plane@display}{`A+\value{cpd@current@plane}}%
                \rlap{{\cpd@boardfont\ \char\value{cpd@current@plane@display}}}%
            }%
            \endgroup%
            \vskip\v@space@dist%
            \addtocounter{cpd@current@plane}{-1}%
        }%
    }\hfil}%
}

\def\put@sqs@space@horizontal{%
   \setbox\sq@box=\hbox{%
      \setcounter{cpd@current@plane}{0}%
      \hskip\h@space@dist%
      \whiledo{\value{cpd@current@plane}<\value{cpd@planes}}{%
         % Now we should clear the board
         \begingroup% We use inner loops!
         \clear@board%
         \put@plane%
         \hbox to \bd@width{%
            \inner@henbox{\box\plane@box}%
            \setcounter{cpd@current@plane@display}{`A+\value{cpd@current@plane}}%
            \rlap{{\cpd@boardfont\ \char\value{cpd@current@plane@display}}}%
         }%
         \endgroup%
         \hskip\h@space@dist%
          \addtocounter{cpd@current@plane}{1}%
      }%
   }%
}

\def\put@sqs@space{%
   \ifspace@vertical%
      \put@sqs@space@vertical%
   \else%
      \put@sqs@space@horizontal%
   \fi%
}
\def\@inner@vframe{%
   \if@vframe%
      \vrule width \inner@frame%
   \else%
      \hskip\inner@frame%
   \fi%
}

\def\@inner@hframe{%
   \if@hframe%
      \hrule height \inner@frame%
   \else%
      \vskip\inner@frame%
   \fi%
}
\def\inner@v@frame@rule{%
   \if@stereo%
      \@inner@vframe%
   \else\if@space%
      \@inner@vframe%
   \else\if@leaveOuter%
      \vrule width \inner@frame%
   \else%
      \@inner@vframe%
   \fi\fi\fi%
}

\def\inner@h@frame@rule{%
   \if@stereo%
      \@inner@hframe%
   \else\if@space%
      \@inner@hframe%
   \else\if@leaveOuter%
      \hrule height \inner@frame%
   \else%
      \@inner@hframe%
   \fi\fi\fi%
}

\def\inner@henbox#1{%
   \hbox{%
      \inner@v@frame@rule%
      \vbox{\inner@h@frame@rule#1\inner@h@frame@rule}%
      \inner@v@frame@rule%
   }%
}
\def\@outer@vrule{\vrule width \outer@frame}

\def\@outer@hrule{\hrule height \outer@frame}
\def\outer@v@frame@rule{%
   \if@stereo%
      \@outer@vrule%
   \else\if@space%
      \@outer@vrule%
   \else\if@leaveOuter%
      \if@vframe\@outer@vrule\else\hskip\outer@frame\fi%
   \else%
      \@outer@vrule%
   \fi\fi\fi%
}

\def\outer@h@frame@rule{%
   \if@stereo%
      \@outer@hrule%
   \else\if@space%
      \@outer@hrule%
   \else\if@leaveOuter%
      \if@hframe\@outer@hrule\else\vskip\outer@frame\fi%
   \else%
      \@outer@hrule%
   \fi\fi\fi%
}

\def\outer@henbox#1{%
   \outer@h@frame@rule%
   \hbox{%
      \outer@v@frame@rule%
      \ifspace@vertical%
         \hskip\h@frame@dist%
      \fi%
      \vbox{%
         \ifspace@vertical%
            \vskip\v@frame@dist%
         \else%
            \vskip\v@space@dist%
         \fi%
         #1%
         \ifspace@vertical%
            \vskip\v@frame@dist%
         \else%
            \vskip\v@space@dist%
         \fi%
      }%
      \ifspace@vertical%
         \hskip\h@frame@dist%
      \fi%
      \outer@v@frame@rule%
   }%
   \outer@h@frame@rule%
}
\def\ch@fig#1{%
   \ifvmode\noindent\fi%
   \hbox{\chtextfont\lower.1\fontdimen\tw@\chtextfont\hbox{\char#1}}%
}
\def\@dia@index{%
   \@ifundefined{newindex}%
   {\errmessage{You should add documentstyle-option 'index'}}{}%
}

\def\showlabel#1{%
   \if@develop%
      \raise1ex\hbox{\labelfont#1}\penalty\exhyphenpenalty%
   \fi%
}

\def\@aidxitem#1, #2, #3{%
   \par\medskip#1, \write@christian#2; \dotfill #3%
}

\def\dia@index#1\@sep#2[#3]{\index[#3]{#2|showlabel{#1}}}

\def\parse@aindex#1; {%
   \expandafter\dia@index\the\label@tk\@sep#1[author]\l@@klist%
}

\def\@aindex{%
   \if@aindex%
      \ifnormal@names%
         \errmessage{Cannot create index entries with normalnames}%
      \else\ifauth@r%
         \let\@action=\parse@aindex\@parseTokenlist\aut@tk;%
      \fi\fi%
   \fi%
}

\def\x@sindex#1\@sep{\expandafter\dia@index\the\label@tk\@sep#1[source]}

\def\@sindex{%
   \if@sindex\if@source%
      \expandafter\x@sindex\the\source@tk\@sep%
   \fi\fi%
}

\def\parse@tindex#1, {%
   \expandafter\dia@index\the\label@tk\@sep#1[theme]\l@@klist%
}

\def\@tindex{%
   \if@tindex\if@theme%
      \let\@action=\parse@tindex\@parseTokenlist\theme@tk,%
   \fi\fi%
}
\def\@setPieceColor#1#2#3{%
   \gdef\ds@white{#1}\gdef\ds@black{#2}\gdef\ds@neutral{#3}%
}

\def\@setPieceSpec#1#2#3#4#5#6{%
   \gdef\ds@king{#1}\gdef\ds@queen{#2}\gdef\ds@rook{#3}%
   \gdef\ds@bishop{#4}\gdef\ds@knight{#5}\gdef\ds@pawn{#6}%
}

\def\@setPieceRotation#1#2#3{%
   \gdef\ds@rotation@left{#1}\gdef\ds@rotation@right{#2}\gdef\ds@rotation@upsidedown{#3}%
}
\newcommand{\cpd@piecedef@rotations}{%
    \def\@theRotation{}\cpd@piecedef@colors{0}%
    \def\@theRotation{\ds@rotation@left}\cpd@piecedef@colors{36}%
    \def\@theRotation{\ds@rotation@right}\cpd@piecedef@colors{72}%
    \def\@theRotation{\ds@rotation@upsidedown}\cpd@piecedef@colors{108}%
}
\newcommand{\cpd@piecedef@colors}[1]{%
    \def\@theColor{\ds@white}\cpd@piecedef@types{#1}{0}%
    \def\@theColor{\ds@neutral}\cpd@piecedef@types{#1}{6}%
    \def\@theColor{\ds@black}\cpd@piecedef@types{#1}{12}%
}
\newcommand{\cpd@piecedef@types}[2]{%
    \def\@thePiece{\ds@pawn}\cpd@piecedef{#1}{#2}{0}%
    \def\@thePiece{\ds@knight}\cpd@piecedef{#1}{#2}{1}%
    \def\@thePiece{\ds@bishop}\cpd@piecedef{#1}{#2}{2}%
    \def\@thePiece{\ds@rook}\cpd@piecedef{#1}{#2}{3}%
    \def\@thePiece{\ds@queen}\cpd@piecedef{#1}{#2}{4}%
    \def\@thePiece{\ds@king}\cpd@piecedef{#1}{#2}{5}%
}
\newcommand{\cpd@piecedef}[3]{%
    \setcounter{cpd@piece@index}{#1+#2+#3}%
    \edef\cpd@piecedef@index{\arabic{cpd@piece@index}}%
    \expandafter\xdef%
    \csname\@theColor\@thePiece\@theRotation\endcsname{%
        \ch@fig{\cpd@piecedef@index}%
    }
}

\elchfont\@fselch

\defaultelchfont%
\diagnum{\@ne}
%% \figcnttrue
\setboolean{piececounter}{true}
\def\@dianame{\@fullname}
\def\@solname{\@fullname}
\space@verticaltrue
\diagnumbering{arabic}
\def\write@month{\@arabic}%
\diagleft
\cl@arsol
\let\orig@author=\author
\let\orig@day=\day
\let\orig@month=\month
\let\orig@year=\year
\let\orig@label=\label
\DefinePieces{wsn}{KDTLSB}{LRU}
\newdimen\normalboardwidth
\def\setboardwidth{%
   \normalboardwidth=\@ight\fontdimen\tw@\chessfont%
   \advance\normalboardwidth\tw@\inner@frame%
   \advance\normalboardwidth\tw@\h@frame@dist%
   \advance\normalboardwidth\tw@\outer@frame%
}

\setboardwidth

\endinput
%%
%% End of file `diagram.sty'.
