summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/skak/skak.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2008-10-16 23:42:13 +0000
committerKarl Berry <karl@freefriends.org>2008-10-16 23:42:13 +0000
commitccfb7362e633d55206b5f6cdb66668f835625b32 (patch)
tree001d278e31ccd01c95474e7d05bab68f4bb4ba14 /Master/texmf-dist/tex/latex/skak/skak.sty
parent8ecd07ed332dbd3cd8cdfc02f03137b19b9b8f4a (diff)
skak 1.5 (16oct08)
git-svn-id: svn://tug.org/texlive/trunk@10991 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/skak/skak.sty')
-rw-r--r--Master/texmf-dist/tex/latex/skak/skak.sty295
1 files changed, 236 insertions, 59 deletions
diff --git a/Master/texmf-dist/tex/latex/skak/skak.sty b/Master/texmf-dist/tex/latex/skak/skak.sty
index 895af5ef79f..f3190357760 100644
--- a/Master/texmf-dist/tex/latex/skak/skak.sty
+++ b/Master/texmf-dist/tex/latex/skak/skak.sty
@@ -27,9 +27,15 @@
% Joao Nabais reported a problem related to switching
% back and forth from styleC - this has been fixed using
% \leavestylec command complex.
+% 1.5 2008-10-09 Fixed a major problem with longmoves - the pawn moves
+% are now displayed correctly. Changed the \storegame and
+% \restoregame to store both the current position and the
+% previous positon so a full restore can be made.
+% Added new variation commands.
+
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{skak}[2005/06/29 v1.4a Chess typesetting]
+\ProvidesPackage{skak}[2008/10/09 v1.5 Chess typesetting]
\DeclareOption{tiny}{\AtEndOfClass{\tinyboard}}
\DeclareOption{small}{\AtEndOfClass{\smallboard}}
@@ -601,16 +607,23 @@
\newcounter{halfmove}
\newcounter{move}
-\def\fenboard#1{\FenBoard#1)}
+\def\@fenboard#1{\FenBoard#1)}
\def\FenBoard#1 #2 #3 #4 #5 #6){%
\InitBoard(#1)%
- \def\WhiteToMove{\EqStr{w}{#2}}%
- \ExtractWhiteCastling{#3}%}
- \ExtractBlackCastling{#3}%}
- \def\EnPassantSquare{#4}%
+ \EqStr{w}{#2}%
+ {\gdef\WhiteToMove{\True}}%
+ {\gdef\WhiteToMove{\False}}%\EqStr{w}{#2}}%
+ \ExtractWhiteCastling{#3}%}
+ \ExtractBlackCastling{#3}%}
+ \edef\EnPassantSquare{#4}%
\setcounter{halfmove}{#5}%
\setcounter{move}{#6}}
+\def\fenboard#1{%
+% \@fenboard#1%
+ \FenBoard#1)%
+ \@initstorage}
+
\newcounter{helpgobble}
\def\PieceToFen#1{%
@@ -952,8 +965,8 @@
\addtocounter{move}{-1}%
\beforenumber\arabic{move}\blackopen\beforeblack%
\addtocounter{move}{1}}%
- {\beforenumber\arabic{move}\whiteopen\beforewhite}%
- \expandafter\wmove\expandafter{\LastMoveString}}}
+ {\beforenumber\arabic{move}\whiteopen\beforewhite}%
+ \expandafter\wmove\expandafter{\LastMoveString}}}
\def\ParseMoveA(#1#2){% char -> string -> unit
\IsPieceName{#1}%
@@ -1219,25 +1232,48 @@
{}}}}}}}}}
\def\InitialRank{\WhiteToMove{2}{7}}
+% \def\ExecutePawnMove{% relies on the info obtained by ParseMove
+% \setcounter{halfmove}{0}%
+% \Capture%
+% {\EqPiece{E}{\Get{\MoveTo}}%
+% {\Set{\MoveToFile\FromRank}{E}}%
+% {}%
+% \DoTheMove{\FileDiscriminator\FromRank}%
+% \xdef\EnPassantSquare{-}}%
+% {\EqPiece{E}{\Get{\MoveToFile\FromRank}}%
+% {\xdef\EnPassantSquare{\MoveToFile\FromRank}% two square move
+% \DoTheMove{\MoveToFile\InitialRank}}%
+% {\xdef\EnPassantSquare{-}%
+% \DoTheMove{\MoveToFile\FromRank}% one square move
+% }}%
+% \Promotion%
+% {\Set{\MoveTo}{\PieceNameToPiece{\PromotionPieceName}{\WhiteToMove}}}%
+% {}}
+
+% Bug-fix for longmove
\def\ExecutePawnMove{% relies on the info obtained by ParseMove
\setcounter{halfmove}{0}%
\Capture%
{\EqPiece{E}{\Get{\MoveTo}}%
{\Set{\MoveToFile\FromRank}{E}}%
{}%
- \DoTheMove{\FileDiscriminator\FromRank}%
+ \xdef\PawnFrom{\FileDiscriminator\FromRank}%
+ \DoTheMove{\PawnFrom}%
\xdef\EnPassantSquare{-}}%
{\EqPiece{E}{\Get{\MoveToFile\FromRank}}%
{\xdef\EnPassantSquare{\MoveToFile\FromRank}% two square move
- \DoTheMove{\MoveToFile\InitialRank}}%
+ \xdef\PawnFrom{\MoveToFile\InitialRank}%
+ \DoTheMove{\PawnFrom}}%
{\xdef\EnPassantSquare{-}%
- \DoTheMove{\MoveToFile\FromRank}% one square move
+ \xdef\PawnFrom{\MoveToFile\FromRank}%
+ \DoTheMove{\PawnFrom}% one square move
}}%
\Promotion%
{\Set{\MoveTo}{\PieceNameToPiece{\PromotionPieceName}{\WhiteToMove}}}%
{}}
+
\def\MakeMove#1{% string -> unit
\ParseMoveInit%
\ParseMove{#1}%
@@ -1254,28 +1290,53 @@
{\gdef\WhiteToMove{\False}}%
{\gdef\WhiteToMove{\True}\addtocounter{move}{1}}}%
{}% moves are not executed
- \printmove%
- }
+ \printmove}
\def\mainline{\begingroup\catcode`\#=12 \@mainline}
+% \def\@mainline#1{\endgroup\gdef\NumberNext{\True}%
+% \gdef\AfterBlack{\False}%
+% \gdef\PrintMoves{\True}%
+% \gdef\ExecuteMoves{\True}%
+% \gdef\StoreLastMove{\True}%
+% {\mainlinestyle\opencommands%
+% \Mainline(#1 Z )%
+% \closecommands}}
+
+% new version of @mainline
\def\@mainline#1{\endgroup\gdef\NumberNext{\True}%
- \gdef\AfterBlack{\False}%
+ \let\currentstyle=\mainlinestyle%
\gdef\PrintMoves{\True}%
\gdef\ExecuteMoves{\True}%
\gdef\StoreLastMove{\True}%
- {\mainlinestyle\opencommands%
- \Mainline(#1 Z )%
- \closecommands}}
+ \@restoremainline%
+ \runmoves{#1}%
+ \@storemainline}
+
+\def\@restoremainline{%
+ \@restoregame{skak.mainline.previous}%
+ \@storegame{skak.temp.previous}%
+ \@restoregame{skak.mainline}}
+
\def\hidemoves{\begingroup\catcode`\#=12 \@hidemoves}
+% \def\@hidemoves#1{\endgroup\gdef\NumberNext{\True}%
+% \gdef\AfterBlack{\False}%
+% \gdef\PrintMoves{\False}%
+% \gdef\ExecuteMoves{\True}%
+% \gdef\StoreLastMove{\True}% just in case you want to refer to the last move.
+% {\relax@typesetting%
+% \Mainline(#1 Z )}}
+
+% new version af @hidemoves
\def\@hidemoves#1{\endgroup\gdef\NumberNext{\True}%
- \gdef\AfterBlack{\False}%
\gdef\PrintMoves{\False}%
\gdef\ExecuteMoves{\True}%
\gdef\StoreLastMove{\True}% just in case you want to refer to the last move.
- {\relax@typesetting%
- \Mainline(#1 Z )}}
+ \let\currentstyle=\relax@typesetting%
+ \@restoremainline%
+ \runmoves{#1}%
+ \@storemainline}
\newcounter{helpnumber}
@@ -1294,7 +1355,7 @@
{\setcounter{helpnumber}{#1}%
\ifthenelse{\value{helpnumberMove}=\value{helpnumber}}%
{\LookForMove(.#2)}% sets \ExpectedColour and \CurrentMove
- {\errmessage{mainline: not the correct move number}}}%
+ {\errmessage{mainline: #1 is not the correct move number}}}%
{\LookForMove(.#2)}%
}
@@ -1317,6 +1378,8 @@
{\gdef\NumberNext{\False}}%
{\StripMove(#1)}}
\def\StripMove(#1W){% handles things like 1.e4
+ \@storegame{skak.temp.previous}% store the previous position
+ % TO-DO: need a more effective way of going a move back.
\MakeMoveMainline{#1}}
% The tricky part! Has to integrate \typeset@A@move
@@ -1331,6 +1394,7 @@
{\errmessage{mainline: white, not black, to move (#1)}}%
{\MakeMove{#1}\gdef\NumberNext{\True}}}}}
+
\def\MakeMoveMainline#1{%
\ExecuteMoves%
{\ExpectedColour%
@@ -1346,6 +1410,23 @@
\beforeblack\MakeMove{#1}\gdef\NumberNext{\True}}}
+% \def\Mainline(#1 #2){%
+% \EqStr{ }{#1}%
+% {\Mainline(#2)}%
+% {%
+% \EqStr{Z}{#1}%
+% {}%
+% {\NumberNext%
+% {\EatNumber{#1}% sets \NumberOK, \ExpectedColour
+% % executes a move not separated from the
+% % number with a space, eg, 1.e4
+% %{\gdef\NumberNext{\False}\Mainline(#2)}%
+% %\gdef\NumberNext{\False}%
+% \Mainline(#2)}%
+% {\MakeMoveMainline{#1}%
+% \Mainline(#2)}}}}
+
+% New version for longmoves in variation
\def\Mainline(#1 #2){%
\EqStr{ }{#1}%
{\Mainline(#2)}%
@@ -1356,10 +1437,12 @@
{\EatNumber{#1}% sets \NumberOK, \ExpectedColour
% executes a move not separated from the
% number with a space, eg, 1.e4
- %{\gdef\NumberNext{\False}\Mainline(#2)}%
+ % {\gdef\NumberNext{\False}\Mainline(#2)}%
%\gdef\NumberNext{\False}%
\Mainline(#2)}%
- {\MakeMoveMainline{#1}%
+ {\@storegame{skak.temp.previous}% store the previous position
+ % TO-DO: need a more effective way of going a move back.
+ \MakeMoveMainline{#1}%
\Mainline(#2)}}}}
@@ -1496,18 +1579,18 @@
\def\styleC{%
-\let\opencommands=\styleC@opencommands
-\let\closecommands=\styleC@closecommands
-\let\whiteopen=\styleC@whiteopen
-\let\blackopen=\styleC@blackopen
-\let\beforenumber=\styleC@beforenumber
-\let\beforewhite=\styleC@beforewhite
-\let\afterwhite=\styleC@afterwhite
-\let\beforeblack=\styleC@beforeblack
-\let\afterblack=\styleC@afterblack
-\def\mainlinestyle{\styleC\bfseries}
-\def\variationstyle{\styleB}
-\def\styleC@on{\True}
+\let\opencommands=\styleC@opencommands%
+\let\closecommands=\styleC@closecommands%
+\let\whiteopen=\styleC@whiteopen%
+\let\blackopen=\styleC@blackopen%
+\let\beforenumber=\styleC@beforenumber%
+\let\beforewhite=\styleC@beforewhite%
+\let\afterwhite=\styleC@afterwhite%
+\let\beforeblack=\styleC@beforeblack%
+\let\afterblack=\styleC@afterblack%
+\def\mainlinestyle{\styleC\bfseries}%
+\def\variationstyle{\styleB}%
+\def\styleC@on{\True}%
}
\def\mainlinestyle{\bfseries}% could also contain
@@ -1557,22 +1640,22 @@
{\checksymbol}% was "\ensuremath{\dagger}" before
{\EqStr{-}{#1}%
{\LastCharWasCastle
- {\castlinghyphen}% %%changed UF, dash from Textfont short dash for castlings
- {\hbox{--}}}% longer dash for moves
- {\EqStr{O}{#1}%
- {\gdef\LastCharWasCastle{\True}%
- \castlingchar}% %% UF added to be able to change from O to 0
- {\gdef\LastCharWasCastle{\False}%
- \EqStr{##}{#1}%added 2004.04.14 for \mate
- {\mate}
- {#1}}}}}}}%
+ {\castlinghyphen}% %%changed UF, dash from Textfont short dash for castlings
+ {\hbox{--}}}% longer dash for moves
+ {\EqStr{O}{#1}%
+ {\gdef\LastCharWasCastle{\True}%
+ \castlingchar}% %% UF added to be able to change from O to 0
+ {\gdef\LastCharWasCastle{\False}%
+ \EqStr{##}{#1}%added 2004.04.14 for \mate
+ {\mate}
+ {#1}}}}}}}%
\typeset@A@moveA(#2)}}
\def\typeset@A#1{\gdef\TypeSetNumberNext{\True}%
\gdef\TypeSetAfterBlack{\False}\opencommands\typeset@AA(#1 Z )%
\closecommands}
-%\typeset@AA is isomorf with \Mainline
+% \typeset@AA is isomorf with \Mainline
\def\typeset@AA(#1 #2){%
\EqStr{ }{#1}%
{\typeset@AA(#2)}%
@@ -1580,34 +1663,98 @@
{}%
{\TypeSetNumberNext%
{\typeset@number{#1}% sets \TypeSetColour
- %\gdef\TypeSetNumberNext{\False}%
+ % \gdef\TypeSetNumberNext{\False}%
\typeset@AA(#2)}%
{\typeset@A@move{#1}%
\typeset@AA(#2)}}}}
-%\typeset@cmoves and \typeset@comment added by db <2002-01-06>
+% \typeset@cmoves and \typeset@comment added by db <2002-01-06>
\def\movewhite{ }
\def\typeset@cmoves(#1 #2){%
\EqStr{ }{#1}%
{\typeset@cmoves(#2)}%
{\EqStr{Y}{#1}%
- {}%
- {\typeset@A@moveA(#1Z)\movewhite\typeset@cmoves(#2)}}}
+ {}%
+ {\typeset@A@moveA(#1Z)\movewhite\typeset@cmoves(#2)}}}
\def\typeset@comment#1{\opencommands\typeset@cmoves(#1 Y )%
- \closecommands}
+ \closecommands}
%\def\variation{\begingroup\catcode`\#=12 \@variation}
\DeclareRobustCommand{\variation}{\begingroup\catcode`\#=12 \@variation}
%\def\@variation#1{\endgroup{\variationstyle\typeset@A{#1}}}
+\DeclareRobustCommand{\variationcurrent}{\begingroup\catcode`\#=12 \@variationcurrent}
+\DeclareRobustCommand{\continuevariation}{\begingroup\catcode`\#=12 \@continuevariation}
+\DeclareRobustCommand{\continuevariationcurrent}{\begingroup\catcode`\#=12 \@continuevariationcurrent}
+
+% \def\@variation#1{\endgroup\gdef\NumberNext{\True}%
+% \gdef\AfterBlack{\False}%
+% \gdef\PrintMoves{\True}%
+% \gdef\ExecuteMoves{\False}%
+% \gdef\StoreLastMove{\False}%
+% {\variationstyle\opencommands%
+% \Mainline(#1 Z )%
+% \closecommands}}
+
+% new version of \@variation
+\def\@variation#1{\endgroup%
+ \let\currentstyle=\variationstyle%
+ \gdef\Printmoves{\True}%
+ \gdef\ExecuteMoves{\True}%
+ \gdef\StoreLastMove{\False}%
+ \@restoregame{skak.mainline.previous}% roll-back of last move.
+ \runmoves{#1}%
+ \storegame{skak.variation}\@restoremainline}
+
+% \def\@storevariationdata{%
+% \storegame{skak.variation}%
+% \restoregame{skak.temp.previous}%
+% \storegame{skak.variation.previous}}
+
+\def\@storemainline{% Only to be called after executing moves in \@mainline
+% or in \@hidemoves!
+ \@storegame{skak.mainline}%
+ \@restoregame{skak.temp.previous}%
+ \@storegame{skak.mainline.previous}%
+ \@restoregame{skak.mainline}}
+
+\def\@variationcurrent#1{\endgroup%
+ \let\currentstyle=\variationstyle%
+ \gdef\Printmoves{\True}%
+ \gdef\ExecuteMoves{\True}%
+ \gdef\StoreLastMove{\False}%
+ \@restoregame{skak.mainline}%
+ \runmoves{#1}%
+ \storegame{skak.variation}\@restoremainline}
-\def\@variation#1{\endgroup\gdef\NumberNext{\True}%
- \gdef\AfterBlack{\False}%
- \gdef\PrintMoves{\True}%
- \gdef\ExecuteMoves{\False}%
+\def\@continuevariation#1{\endgroup%
+ \let\currentstyle=\variationstyle%
+ \gdef\Printmoves{\True}%
+ \gdef\ExecuteMoves{\True}%
\gdef\StoreLastMove{\False}%
- {\variationstyle\opencommands%
+ \@restoregame{skak.variation.previous}% roll-back of last move.
+ \runmoves{#1}%
+ \storegame{skak.variation}\@restoremainline}
+
+
+\def\@continuevariationcurrent#1{\endgroup%
+ \let\currentstyle=\variationstyle%
+ \gdef\Printmoves{\True}%
+ \gdef\ExecuteMoves{\True}%
+ \gdef\StoreLastMove{\False}%
+ \@restoregame{skak.variation}%
+ \runmoves{#1}%
+ \storegame{skak.variation}\@restoremainline}
+
+
+
+
+% \runmoves is common to \variation, \mainline and \hidemoves
+\newcommand\runmoves[1]{%
+ \gdef\NumberNext{\True}%
+ \gdef\AfterBlack{\False}%
+ {\currentstyle\opencommands%
\Mainline(#1 Z )%
\closecommands}}
@@ -1857,7 +2004,13 @@
\def\showmoveroff{\showmoverOff}
\def\newgame{%
-\fenboard{rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1}}
+ \fenboard{rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1}}
+
+% Stores the initial boards for board manipulation.
+\def\@initstorage{%
+ \@storegame{skak.mainline}%
+ \@storegame{skak.mainline.previous}% no previous move for starters.
+ \@storegame{skak.temp.previous}}
%%%% storing and loading of games
@@ -1869,6 +2022,14 @@
\immediate\write\skakstore{\temp@board}%
\immediate\closeout\skakstore}
+\def\savegame#1{% writes the board as fen to #1.fen
+ \immediate\openout0=#1.fen%
+ \Fen@calculate%
+ \immediate\write0{\temp@board}%
+ \immediate\closeout0}
+
+
+
% loading a board from a fen file is also possible
% the file #1.fen should contain nothing but a fen of
% a game
@@ -1884,10 +2045,26 @@
% \def\storegame#1{\Fen@calculate%
% \def#1{\temp@board}}
% \def\restoregame#1{\expandafter\FenBoard#1)}
-\def\storegame#1{\Fen@calculate%
+\def\@storegame#1{\Fen@calculate%
\expandafter\xdef\csname chessgame.#1\endcsname{\temp@board}}
-\def\restoregame#1{%
- \edef\restore@temp{\csname chessgame.#1\endcsname}
+\def\@restoregame#1{%
+ \edef\restore@temp{\csname chessgame.#1\endcsname}%
\expandafter\FenBoard\restore@temp)}
+\let\mystore=\@storegame
+\let\myrestore=\@restoregame
+
+\def\storegame#1{%
+ \@storegame{#1}%
+ \@restoregame{skak.temp.previous}%
+ \@storegame{#1.previous}%
+ \@restoregame{#1}}
+
+\def\restoregame#1{%
+ \@restoregame{#1.previous}%
+ \@storegame{skak.temp.previous}%
+ \@storegame{skak.mainline.previous}%
+ \@restoregame{#1}%
+ \@storegame{skak.mainline}}
+
% end skak.sty