diff options
author | Karl Berry <karl@freefriends.org> | 2006-06-01 22:46:03 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-06-01 22:46:03 +0000 |
commit | 89fb5de10a767340ae26188164fae4ae80f99efc (patch) | |
tree | db6cb3083533684dbce6f593e9e8c3a69da24a3a /Master/texmf-dist/source/latex/texmate | |
parent | 483caddbc7d58da2c9ca51b9cc616c6c6446e889 (diff) |
texmate2
git-svn-id: svn://tug.org/texlive/trunk@1644 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/texmate')
-rw-r--r-- | Master/texmf-dist/source/latex/texmate/texmate.dtx | 1052 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/texmate/texmate.ins | 4 |
2 files changed, 717 insertions, 339 deletions
diff --git a/Master/texmf-dist/source/latex/texmate/texmate.dtx b/Master/texmf-dist/source/latex/texmate/texmate.dtx index 13e97f2b69e..45aed877612 100644 --- a/Master/texmf-dist/source/latex/texmate/texmate.dtx +++ b/Master/texmf-dist/source/latex/texmate/texmate.dtx @@ -1,7 +1,7 @@ % \iffalse meta-comment % % texmate - Chess typesetting. -% Copyright 2005 Federico Garcia (feg8@pitt.edu, federook@gmail.com) +% Copyright 2005-6 Federico Garcia (federook@gmail.com) % ------------------------------------------- % % @@ -13,11 +13,11 @@ % %<*driver> % \fi -\ProvidesFile{texmate.dtx}[2005/03/13 v1 Chess typesetting] +\ProvidesFile{texmate.dtx}[2006/05/31 v2 Chess typesetting] % \iffalse \documentclass{ltxdoc} \GetFileInfo{texmate.dtx} -\title{\TeX mate\\(comprehensive chess annotation in \LaTeX)\\Implementation} +\title{\TeX mate\,2\\(comprehensive chess annotation in \LaTeX)\\Implementation} \date{\filedate{}} \author{Federico Garcia\\\texttt{federook@gmail.com}} @@ -27,278 +27,154 @@ \end{document} %</driver> % \fi -%The user's manual and a sample of the package are found as an independent document (it \emph{uses} the package, so it has to be typeset after installation): \texttt{texmatesample.tex}. Here is the code, somewhat commented. +%The user's manual and a sample of the package are found as an independent document (it \emph{uses} the package, so it has to be typeset after installation): \texttt{texmate2manual.pdf} (source \texttt{texmate2manual.tex}). Here is the code. % +%I have had no time to comment this yet. I've divided the code into parts, but beyond that, I have to refer the interested reader to the implementation of version~1, which provides some explanation. +% +%Each `part' usually follows the same order: variables are declared, the main one or two functions are defined, then auxiliary functions, then commands for user customization, and then defaults. Sometimes this order changes. +% +%\tableofcontents %\section{Prelimitary matters} % \begin{macrocode} %<*package> \NeedsTeXFormat{LaTeX2e}[1995/12/01] -\ProvidesPackage{texmate}[2005/03/12 v1 Chess typesetting (Federico Garcia)] -\newif\if@filling\@fillingfalse -\DeclareOption{filling}{\@fillingtrue} -\DeclareOption{notfilling}{\@fillingfalse} +\ProvidesPackage{texmate}[2005/06/31 v2 Chess typesetting (Federico Garcia)] +\newcommand*\TeXmate{\TeX mate} +\newif\if@skakon\@skakontrue +\newif\if@skaking +\newif\if@diagnostics\@diagnosticsfalse +\DeclareOption{filling}{\typeout{Option `filling' obsolete.}} +\DeclareOption{notfilling}{\typeout{Option `nofilling' obsolete.}} +\DeclareOption{skakoff}{\@skakonfalse + \typeout{Using TeXmate 2 without skak is dangerous. % + Consider using skak too, or using TeXmate 1 instead.}% + \@skakingfalse + } +\DeclareOption{diagnostics}{\@diagnosticstrue} \DeclareOption*{\typeout{Unknown option (`\CurrentOption')}} -\ExecuteOptions{filling} +\ExecuteOptions{} \ProcessOptions +\RequirePackage{amssymb} +\RequirePackage{chessfss} +\usesymfig +\if@skakon + \RequirePackage{skak}[2005/06/29 v1.4a] + \smallboard + \notationoff + \@skakontrue\@skakingtrue + \newtoks\@tmtoskak +\fi % \end{macrocode} % -%\section{The pieces} -%By default, the pieces are referred to in the input by their initials in English (Knight is N because K is King). That's standard in the {\small PGN} format, which should be importable into \TeX mate. But of course a way has to be provided for the user to change it. Six uppercase letters are the argument of -%\DescribeMacro{\pieceinitials}|\pieceinitials|, corresponding to Pawn, Rook, kNight, Bishop, Queen, and King. -% \begin{macrocode} -\def\pieceinitials#1{\@initials#1} -\def\@initials#1#2#3#4#5#6{% - \def\@Pawn{#1}\def\@Rook{#2}\def\@Knight{#3}% - \def\@Bishop{#4}\def\@Queen{#5}\def\@King{#6}% - \lowercase{\def\@pawn{#1}\def\@rook{#2}\def\@knight{#3}% - \def\@bishop{#4}\def\@queen{#5}\def\@king{#6}}} -% \end{macrocode} -%\section{Diagrams} -%This is the easy part, now that beautiful chess fonts have been created for \textsf{skak}. By the way, let's start by setting the font. The user can decide on the size with the length \DescribeMacro{\diagramsize}|\diagramsize|. Default is 18pt. Loading the font will be done when the user calls for |\diagram|, since there could be a need for different-size diagrams in the same document. -% \begin{macrocode} -\newlength\diagramsize -% \end{macrocode} -% -%Some new variables have to be defined. -% \begin{macrocode} -\newcount\SquareNo -\newcount\@squarecount -\newif\if@blacksq\@blacksqfalse -\def\@togglesq{\if@blacksq\@blacksqfalse\else\@blacksqtrue\fi} -\newcount\@piececode -% \end{macrocode} -%The only user macro in this section is \DescribeMacro{\diagram}|\diagram|. It will first set up the stage, and then read the input with |\@diagline|. -% \begin{macrocode} -\def\diagram#1{\font\diagramfont=skak10 at \the\diagramsize - \@squarecount\SquareNo - \bgroup - \setlength\fboxsep{.8pt}% - \fbox{\parbox{\the\SquareNo\diagramsize}{% - \baselineskip\diagramsize\diagramfont\@diagline#1.}}\egroup} -% \end{macrocode} -%Now, \DescribeMacro{\@diagline}|\@diagline| reads the diagram proper. The input can contain only numbers, the initials of pieces (set by |\pieceinitials| through |\@diaginitials|), and |/|, indicating the end of the board file. The diagram is input from left to right, top to bottom. Consequtive empty squares are taken by numbers, so that \texttt{2} means `next are two empty squares.' First, let's adopt the piece initials: -% \begin{macrocode} -\def\@diagpiece#1{\def\temp{#1}\symbol{% - \ifx\temp\@pawn\if@blacksq'157\else'160\fi\else - \ifx\temp\@rook\if@blacksq'163\else'162\fi\else - \ifx\temp\@knight\if@blacksq'155\else'156\fi\else - \ifx\temp\@bishop\if@blacksq'141\else'142\fi\else - \ifx\temp\@queen\if@blacksq'154\else'161\fi\else - \ifx\temp\@king\if@blacksq'152\else'153\fi\else - \ifx\temp\@Pawn\if@blacksq'117\else'120\fi\else - \ifx\temp\@Rook\if@blacksq'123\else'122\fi\else - \ifx\temp\@Knight\if@blacksq'115\else'116\fi\else - \ifx\temp\@Bishop\if@blacksq'101\else'102\fi\else - \ifx\temp\@Queen\if@blacksq'114\else'121\fi\else - \ifx\temp\@King\if@blacksq'112\else'113\fi\else - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}} -% \end{macrocode} -%\DescribeMacro{\@diagpiece}The effect of all that is that |\@diagpiece| will produce the character with the particular piece indicated by its argument, white if uppercase, black if lowercase, and on the appropriate square (light or black) according to |\if@blacksq|. Of course, it's |\@diagline| that calls for |\@diagpiece|, if it finds that the next character in the input is \emph{not} a number, `|/|,' or `.'\ (this latter is the delimitation to the whole diagram, not by the user, but by |\diagram| above): -% \begin{macrocode} -\def\@diagline#1{\@tempcnta0 \let\next\@diagline - \ifx#1.\let\next\relax\if@filling\@dospaces{\@squarecount}\fi - \else\ifx#1/\def\next{\if@filling\@dospaces{\@squarecount}\fi - \newline\@togglesq\@squarecount\SquareNo\relax - \@diagline}% - \else\ifcat1#12\@dospaces{#1}% - \else\@diagpiece#1\advance\@squarecount-1 \@togglesq - \fi\fi\fi - \next} -% \end{macrocode} -%The last thing is the interpolation of empty squares through \DescribeMacro{\@dospaces}|\@dospaces|. Its argument is either a digit input by the user, or the number of squares remaining in the current board file, which \TeX mate has been keeping track of with |\@squarecount| if \texttt{filling} is an active option. -% \begin{macrocode} -\def\@dospaces#1{\ifnum#1>0 - \if@blacksq\symbol{'132}\else\hphantom{\symbol{'132}}\fi - \@togglesq\@tempcntb#1 \advance\@tempcnta1 \advance\@squarecount-1 - \ifnum\@tempcnta<\@tempcntb\let\@next\@dospaces\else - \let\@next\@gobble\fi - \@next\@tempcntb\fi} -% \end{macrocode} -%\section{Chess notation} -%\subsection{Figurines} -%\TeX mate uses the beautiful fonts that come with the \textsf{skak} package. -%\DescribeMacro{\rook}\DescribeMacro{\knight}\DescribeMacro{\bishop}\DescribeMacro{\queen}\DescribeMacro{\king}% -%\DescribeMacro{\@piece}\DescribeMacro{\@@piece}Chess notation is done nowdays with figurines (instead of letters) standing for the pieces. This is the default in \TeX mate, but it can be changed. The user-modifiable commands |\rook|, |\knight|, etc., hold the symbol(s) for each piece. By default, they call |\@piece|, which basically prints the character of the chess font in place (which changes with context, from |\textskakbf| to |\textskak|). The business about \texttt{x}'s category code is explained below. -% \begin{macrocode} -\newcommand{\skakfamily}{\usefont{U}{skak}{m}{n}} -\DeclareTextFontCommand{\textskakbf}{\skakfamily\bfseries} -\DeclareTextFontCommand{\textskak}{\skakfamily} -\newcount\@rk\@rk'122 -\newcount\@kt\@kt'116 -\newcount\@bp\@bp'102 -\newcount\@qn\@qn'121 -\newcount\@kg\@kg'113 -\DeclareRobustCommand\rook{\@piece\@rk } -\DeclareRobustCommand\knight{\@piece\@kt } -\DeclareRobustCommand\bishop{\@piece\@bp } -\DeclareRobustCommand\queen{\@piece\@qn } -\DeclareRobustCommand\king{\@piece\@kg } -\def\@piece#1{\bgroup\catcode`\x=11 \textpiece{\symbol{#1}}\egroup} -\def\@@piece#1{\def\temp{#1}% - \ifx\temp\@Rook\rook\else - \ifx\temp\@Knight\knight\else - \ifx\temp\@Bishop\bishop\else - \ifx\temp\@Queen\queen\else - \ifx\temp\@King\king\else - #1\fi\fi\fi\fi\fi} -% \end{macrocode} -% -%At any point, then, the commands |\rook|, |\knight|, etc., can be used to produce the desired figurine. -% -%\subsection{Captures and checks} -%\DescribeMacro{\takes}There are several ways to notate captures. They are universally input with `x,' but many styles simply do not indicate capture with any particular symbol. Others do, usually with `$\times$,' but also with `:'. The thing is that the |x| has changed into an active character in \TeX mate. It is desirable to keep this change at a minimum, because |\relax| and |\ifx| are used all over the place (by all kinds of commands, not only defined by \TeX mate: for example, |x| cannot be active when the chess selected is set by |\@piece|, because \LaTeX\ runs into all kinds of confusions). So, first realization: the \texttt{x} doesn't make sense but after a category-12 character (a piece or a pawn). So it is |\@@piece| that makes the change. All delimiters change it back, to allow for user-created commands that include |x|. -% \begin{macrocode} -\DeclareRobustCommand\takes{\makebox[1.2ex][c]{$\times$}} -{\catcode`\x=13 \gdefx{\takes}} -% \end{macrocode} -% -%\DescribeMacro{\checksign}Checks are some times indicated, some times not. They are input, universally again, with a plus sign. So it will be made active too in chess mode. The definitions take place inside chess mode, below, and in the chess symbols section. -% -%\subsection{Chess symbols} -%\textsf{skak}'s fonts also provide for the symbols of the \emph{Informator}. \TeX mate implements them using those characters, adjusting them for size and position (with the admittedly annoying result that they should be typed manually if the surrounding text is not in normal size). Check and mate signs can be boldface, the others are usually not, even in the main line. -% \begin{macrocode} -\def\@chesssymbol#1{\bgroup\catcode`\x=11 - \smash{\textskak{\symbol{#1}}}\egroup } -\DeclareRobustCommand\checksign{\smash{\@piece{'053}}} -\DeclareRobustCommand\mate{\smash{\@piece{'155}}} -\DeclareRobustCommand\wbetter{\raisebox{-.1ex}{\@chesssymbol{'146}}} -\DeclareRobustCommand\bbetter{\raisebox{-.1ex}{\@chesssymbol{'147}}} -\DeclareRobustCommand\wBetter{\raisebox{-.35ex}{\@chesssymbol{'143}}} -\DeclareRobustCommand\bBetter{\@chesssymbol{'145}} -\DeclareRobustCommand\WBetter{{\large\@chesssymbol{'150}}} -\DeclareRobustCommand\BBetter{{\large\@chesssymbol{'151}}} -\DeclareRobustCommand\equal{=} -\DeclareRobustCommand\unclear{\raisebox{-.5ex}{{\Large\@chesssymbol{'153}}}} -\DeclareRobustCommand\compensation{{\large\@chesssymbol{'156}}} -\DeclareRobustCommand\development{{\footnotesize\@chesssymbol{'164}}} -\DeclareRobustCommand\spaceadv{{\footnotesize\@chesssymbol{'171}}} -\DeclareRobustCommand\attack{\raisebox{-.3ex}{{\large\@chesssymbol{'101}}}} -\DeclareRobustCommand\initiative{\raisebox{-.2ex}{{\large\@chesssymbol{'103}}}} -\DeclareRobustCommand\counterplay{{\large\@chesssymbol{'126}}} -\DeclareRobustCommand\zugzwang{{\small\@chesssymbol{'104}}} -\DeclareRobustCommand\withidea{{\footnotesize\@chesssymbol{'105}}} -\DeclareRobustCommand\onlymove{{\footnotesize\@chesssymbol{'106}}} -\DeclareRobustCommand\betteris{{\footnotesize\@chesssymbol{'142}}} -\DeclareRobustCommand\boardfile{\@chesssymbol{'110}} -\DeclareRobustCommand\boarddiagonal{{\small\@chesssymbol{'107}}} -\DeclareRobustCommand\boardcenter{{\small\@chesssymbol{'111}}} -\DeclareRobustCommand\kingside{\@chesssymbol{'117}} -\DeclareRobustCommand\queenside{\@chesssymbol{'115}} -\DeclareRobustCommand\weak{{\small\@chesssymbol{'170}}} -\DeclareRobustCommand\ending{{\footnotesize\@chesssymbol{'114}}} -\DeclareRobustCommand\bishops{\@chesssymbol{'141}} -\DeclareRobustCommand\oppositebishops{\@chesssymbol{'157}} -\DeclareRobustCommand\samebishops{\@chesssymbol{'163}} -\DeclareRobustCommand\unitedpawns{\@chesssymbol{'153}} -\DeclareRobustCommand\separatedpawns{\@chesssymbol{'161}} -\DeclareRobustCommand\doubledpawns{\@chesssymbol{'144}} -\DeclareRobustCommand\passedpawn{\@chesssymbol{'162}} -\DeclareRobustCommand\pawnsno{{\small\@chesssymbol{'123}}} -\DeclareRobustCommand\timetrouble{{\small\@chesssymbol{124}}} -\DeclareRobustCommand\with{{\small\@chesssymbol{'166}}} -\DeclareRobustCommand\without{{\small\@chesssymbol{'167}}} -\DeclareRobustCommand\chessetc{\@chesssymbol{'120}} -\DeclareRobustCommand\chesssee{\@chesssymbol{'154}} -% \end{macrocode} -%\subsection{Contexts and fonts} -%\DescribeMacro{\ifont}\DescribeMacro{\iifont}\DescribeMacro{\iiifont}\DescribeMacro{\ivfont}An annotated game of chess has several contexts and fonts: the main line is usually boldface, comments are not. Some times different fonts are chosen for different levels of commentary. \TeX mate defines four levels: by default, the first is boldface; the second and third are set in regular type; the fourth is italicized. Figurines come in boldface and regular. Since levels three and four will happen only after level two, there is no need for them to define the chess font. -% \begin{macrocode} -\def\ifont{\bfseries\let\textpiece\textskakbf} -\def\iifont{\normalfont\let\textpiece\textskak} -\def\iiifont{\normalfont} -\def\ivfont{\itshape} -% \end{macrocode} -% -%\DescribeMacro{\iopen}\DescribeMacro{\iclose}\marginpar{\hfill$\vdots$\quad\null}Different contexts are indicated also by delimiters. Square parenthesis [~] are the usual 2\textsuperscript{nd}-level marker; parenthesis (~) and \textit{(~)} are used for the third and fourth levels. The first level, the actual game, is not delimited. Two sets of delimiters and hooks are provided. The first (accessed with |[| in chess mode, see below) is intended for in-game, not-much-text commentaries. The second (accessed with |\[|, and with a |t| in command names) is for freer commentary. All delimiters are user-modifiable. -% \begin{macrocode} -\newcount\@commlevel -\let\iopen\relax\let\iclose\relax -\DeclareRobustCommand\iopent{\par\noindent } -\DeclareRobustCommand\icloset{\par} -\DeclareRobustCommand\iiopen{ [} -\DeclareRobustCommand\iiclose{\leavevmode\unskip]\textbf{;} } -\DeclareRobustCommand\iiiopen{ (} -\DeclareRobustCommand\iiiclose{\leavevmode\unskip) } -\DeclareRobustCommand\ivopen{ (} -\DeclareRobustCommand\ivclose{\leavevmode\unskip) } -\DeclareRobustCommand\iiopent{} -\DeclareRobustCommand\iicloset{} -\DeclareRobustCommand\iiiopent{} -\DeclareRobustCommand\iiicloset{} -\DeclareRobustCommand\ivopent{} -\DeclareRobustCommand\ivcloset{} +%\section{Chess mode} +% +% \begin{macrocode} +\def\@chesscodes{\catcode`\ =\active \catcode`\.=\active \catcode`\;=\active + \catcode`\[=\active \catcode`\]=\active + \catcode`\>=\active \catcode`\+=\active + \catcode`\:=\active } +\def\@nochesscodes{\catcode`\ =10 \catcode`\.=12 \catcode`\;=12 + \catcode`\]=12 \catcode`\[=12 + \catcode`\>=12 \catcode`\x=11 \catcode`\+=12 + \catcode`\:=12 } +\def\@semicolon{; } +{\@chesscodes\iffalse +\fi\gdef\@chesschars{\iffalse + \fi\def+{\checksign}\iffalse + \fi\long\def ##1{\ifx ##1\else\iffalse + \fi\if@delimited\else\@@turn\fi\expandafter\@execute\fi##1}\iffalse + \fi\def.{ }\gdef;{ }\global\let\;\@semicolon\iffalse + \fi\def[{\@opencomm{open}}\iffalse + \fi\def\[{\@opencomm{opent}}\iffalse + \fi\def]{ \@closecomm{close} }\iffalse + \fi\def\]{\@closecomm{closet} }\iffalse + \fi\let>\egroup}\iffalse +\fi} +\def\@@openchess{% + \advance\@commlevel-1\relax + \if@skaking + \@tmtoskak{}% + \fi + \csname\@roman{\the\@commlevel}font\endcsname + \@chesscodes + \@chesschars + \@execute} +\def\@@closechess{% + \@nochesscodes + \if@delimited\else\@@turn\fi + \advance\@commlevel1\relax + \normalfont + \@resumingtrue\unskip} +\newcommand*\makebarother{\catcode`\|=12 } +{\catcode`\|=\active +\gdef\makebarchess{\catcode`\|=\active + \let|\@openchess} +\gdef\@openchess{\null + \let|\@closechess + \@@openchess} +\gdef\@closechess{\let|\@openchess + \@@closechess} +} +\AtBeginDocument{\ifnum\catcode`\|=12\relax + \makebarchess + \else + \PackageWarning{TeXmate}{`|' not used for chess + (it seems to have a special meaning for another package). + Use \string\begin{texmate} instead.}% + \fi} +\newenvironment{texmate}{\@@openchess}{\@@closechess} % \end{macrocode} -%\subsection{Delimiting the input} -%There are several of the typical ways of notating moves, such as: -% -%\texttt{1.\ d4 Nf6; 2.\ c4 g6} % -%\texttt{1.e4 e5; 2.f4 exf4} -% -%\texttt{3 Nc3 Bg7 4 e4 d6} -% -%Of course, we don't want to force the user into any particular one. Indeed, we want the user to be free to change the way moves are notated even within the same game. So \TeX mate has to take care of spacing, punctuation, etc. Two or three spaces should behave exactly as one, or as a period. -% -%Moreover, the chess-game typist not always is clear about the move number. Most times it's not a crucial piece of information, so one is not thinking of it; and when many levels of variations are involved, it can get pretty confusing. Later, if you realize a mistake in a move number, you will have to change all move numbers from then on\dots -% -%So, the move number should be totally optional for the user. An input with at least some move numbers is easier to edit, so it's expectable that users will type move numbers now and then. In addition, games in {\small PGN} format do have numbers, so \TeX mate needs to understand them. -% -%All that means that something like a `chess~mode' is needed, in which different types of character have special meanings. I chose the character \texttt{\textbar} to delimit the `chess mode:' all chess-related stuff happens within two of these symbols. +%\section{The input} % % \begin{macrocode} -\def\makebarother{\catcode`\|=12 } -\def\makebarchess{\catcode`\|=13 } -\makebarchess -\def\@chesscodes{\catcode`\ =\active \catcode`\.=\active - \catcode`\;=\active \catcode`\[=\active \catcode`\]=\active - \catcode`\>=\active \catcode`\+=\active } -\def\@restorecodes{\catcode`\ =10 \catcode`\.=12 - \catcode`\;=12 \catcode`\]=12 \catcode`\[=12 - \catcode`\>=12 \catcode`\x=11 \catcode`\+=12 } +\def\pieceinitials#1{\@initials#1} +\def\@initials#1#2#3#4#5#6{% + \if@skakon + \newskaklanguage{texmate}{#6#5#2#4#3#1}% + \skaklanguage[texmate]% + \fi + \setfigtextchars #6#5#2#4#3#1% + \gdef\@Pawn{#1}\gdef\@Rook{#2}\gdef\@Knight{#3}% + \gdef\@Bishop{#4}\gdef\@Queen{#5}\gdef\@King{#6}% + \lowercase{\gdef\@pawn{#1}\gdef\@rook{#2}\gdef\@knight{#3}% + \gdef\@bishop{#4}\gdef\@queen{#5}\gdef\@king{#6}}} +\pieceinitials{PRNBQK} +\def\@Castle{O} % \end{macrocode} % -%\TeX mate has to be able to understand who's turn it is at every moment, so that it types the moves, and interpolates the move numbers, properly. So far this is easy enough, it's just the boolean test \DescribeMacro{\if@white}|\if@white|. But there are different kinds of move, at least of Black's moves: some follow immediately after a White move, so they don't need a move number; others resume a line after a commentary, so it's customary to insert the move number and something like `\dots' Thus, there is a second test, \DescribeMacro{\if@resuming}|\if@resuming|, that holds this information. -% -%In principle, spaces in the input delimit the moves. But also other characters, such as \verb"|" itself, and the commentary openers, can function as move delimiters. Several consecutive spaces should not delimit several moves. The way this all is handled is through a third test, \DescribeMacro{\if@delimited}|\if@delimited|. Each delimiting macro will delimit only if this is |false|, and then will make it |true|. +%\section{The moves} % % \begin{macrocode} \newif\if@white \newif\if@resuming \newif\if@delimited -% \end{macrocode} -% -%`Delimiting' amounts to advancing the turn: if a white move was found and delimited, the next thing is a black move. The macro \DescribeMacro{\@turn}|\@turn| toggles |\if@white|, so that \TeX mate knows what to expect next. Of course, |\if@delimited| is set to |true|. -% \begin{macrocode} -\def\@turn{\@delimitedtrue\if@white\@whitefalse\else\@whitetrue\fi} -% \end{macrocode} -% -%\subsection{Formatting the input} -%\TeX mate reads the chess-mode input character by character, and decides what to do with it. If it's a number, it will read it as the move number; if it's a letter, it will interpret it as the beginning of a move, and will set up things to typeset that move, according to whose turn it is, and whether it's resuming or not. Among other things, it will turn |x| into an active character, for captures. -% -%If the next character is not a number or a letter, it must be a command, so it will do nothing. -% -%All of this is coded as \DescribeMacro{\@execute}|\@execute|. The business about 0 is to provide for castling (usually input as 0-0 or 0-0-0). The repetitious way in which it's handled is not the most elegant, but it is the safest. -% \begin{macrocode} +\newcount\move \long\def\@execute#1{\let\next\relax \ifcat1\noexpand#1% \ifnum0=#1 \if@white \if@resuming - \def\next{\beforeno\the\move\afterno - \catcode`\x=\active\@@piece}% + \def\next{% + \beforeno\the\move\afterno + \expandafter\@castle\@gobble + }% \else - \def\next{\afterb\beforeno\the\move\afterno - \catcode`\x=\active\@@piece}% + \def\next{% + \afterb\beforeno\the\move\afterno + \expandafter\@castle\@gobble}% \fi \else \if@resuming - \def\next{\beforeb - \advance\move1 - \catcode`\x=\active\@@piece}% + \def\next{% + \beforeb + \advance\move1\relax + \expandafter\@castle\@gobble}% \else - \def\next{\afterw - \advance\move1 - \catcode`\x=\active\@@piece}% + \def\next{% + \afterw + \advance\move1\relax + \expandafter\@castle\@gobble}% \fi \fi \@delimitedfalse @@ -311,143 +187,645 @@ \if@white \if@resuming \def\next{\beforeno\the\move\afterno - \catcode`\x=\active\@@piece}% + \catcode`\x=\active + \@@piece}% \else \def\next{\afterb\beforeno\the\move\afterno - \catcode`\x=\active\@@piece}% + \catcode`\x=\active + \@@piece}% \fi \else \if@resuming - \def\next{\beforeb + \def\next{% + \beforeb \advance\move1 - \catcode`\x=\active\@@piece}% + \catcode`\x=\active + \@@piece}% \else - \def\next{\afterw + \def\next{% + \afterw \advance\move1 - \catcode`\x=\active\@@piece}% + \catcode`\x=\active + \@@piece}% \fi \fi \@delimitedfalse \@resumingfalse \fi\fi \next#1} +\def\@@piece#1{% + \ifcat\noexpand~\noexpand#1% + \def\next{\@#1}% + \else + \ifcat\relax\noexpand#1% + \def\next{\@#1}% + \else + \def\next{\@@piece}% + \if@skaking + \ifcat1\noexpand#1% + \@tmtoskak\expandafter{\the\@tmtoskak #1}% + \else\ifcat a#1% + \@tmtoskak\expandafter{\the\@tmtoskak #1}% + \fi\fi + \fi + \def\temp{#1}% + \ifx\temp\@Rook\textsymrook\else + \ifx\temp\@Knight\textsymknight\else + \ifx\temp\@Bishop\textsymbishop\else + \ifx\temp\@Queen\textsymqueen\else + \ifx\temp\@King\textsymking\else + \ifx\temp\@Castle\let\next\@castle\else + \def\next{#1\@@piece}% + \fi\fi\fi\fi\fi\fi + \fi\fi + \next} +\def\@castleadd{--\@castlechar} +\def\CastleO{\def\@castlechar{O}} +\def\Castle#1{\def\@castlechar{0}} +\long\def\@castle#1#2#3{% + \ifx-#3% + \mbox{\@castlechar\@castleadd\@castleadd}% + \if@skaking\@tmtoskak{O-O-O}\fi + \let\next\@gobble + \else + \mbox{\@castlechar\@castleadd}% + \if@skaking\@tmtoskak{O-O}\fi + \def\next{#3}% + \fi + \next + } +\Castle0 +\def\takes{\makebox[1.2ex][c]{$\times$}} +\if@skakon + \def\@takes{\catcode`\x=11\relax\@tmtoskak\expandafter + {\the\@tmtoskak x}\takes\@@piece} +\else + \def\@takes{\catcode`\x=11\relax\takes} +\fi +{\catcode`\x=\active \catcode`\:=\active \gdefx{\@takes}\gdef:{\@takes}} % \end{macrocode} -%|\@execute| makes reference to many things. |\@@piece| was defined above. But each type of move (according to |\if@white| and |\if@resuming|) is formatted in different ways, which are user-modifiable macros: -% \begin{macrocode} -\newcount\move -\DeclareRobustCommand\afterno{.~} -\DeclareRobustCommand\afterw{ } -\DeclareRobustCommand\afterb{; } -\DeclareRobustCommand\beforeb{\the\move.~\dots\ } -\DeclareRobustCommand\beforeno{} -% \end{macrocode} -% -%\subsection{Chess mode} -%Entering chess mode \DescribeMacro{\@openchess}(|\@openchess|) involves a number of actions. First of all, the next \textbar\ has to be re-defined to \emph{exit} chess mode. -% -%The main line of a game is usually boldface. Any text that the user wants to introduce between the moves is presumably intended as regular type. So, normal conditions are actually level 2; |\@openchess| will decrease the level, so that the main game becomes 1, and is typeset boldface. Then the font has to be set accordingly. Category codes are set to chess mode then, and the first character of the input is read. -% -%Exiting chess mode \DescribeMacro{\@closechess}(|\@closechess|) un-does all this, and in addition has to delimit any move that precedes it and has not been delimited. Finally, the next move will always be a resuming one, so |\if@resuming| is made |true|. -% \begin{macrocode} -\def\@openchess{\let|\@closechess - \advance\@commlevel-1\relax - \csname\@roman{\the\@commlevel}font\endcsname - \@chesscodes - \@execute} -\let|\@openchess -\def\@closechess{\let|\@openchess - \if@delimited\else\@turn\fi - \@restorecodes\normalfont - \@resumingtrue\advance\@commlevel1\relax} -% \end{macrocode} -% -%\subsection{Commentary} % -%Commentaries are groups. All font changes, modifications in the move number, the turn, the resuming state, etc., are local, so that when we step back to the previous level, the conditions in which it was left are restored. +%\section{Commentary} % -%A commentary usually mentions a move that was an alternative to the one in the game (or in the superior-level line). So, if the last move was Black's tenth move, the commentary should expect, by default, another move no.~10 by Black. In \DescribeMacro{\@opencomm}(|\@opencomm|), move number and turn are properly modified. A group is open, the level is increased, the font of the new level is chosen, and the next character is read. \DescribeMacro{\@closecomm}|\@closecomm| basically closes the group. -% -%But both commands have a further feature. They insert punctuation signs, or whatever is defined in user-modifiable macros, according to the type of commentary being open. The argument to the commands is provided by |[| and |]| or by |\[| and |\]|. % \begin{macrocode} +\newcount\@commlevel +\let\tm@aftermove\relax \def\@opencomm#1{% \@resumingtrue - \catcode`\x=11 + \catcode`\x=11\relax + \if@skaking + \expandafter\storegame\expandafter{\@roman{\the\@commlevel}comm-game}% + \if@diagnostics\message{Stored position for comment at level + \the\@commlevel\ after \tm@tomainline.}\fi + \else{} \fi \bgroup - \if@delimited - \@turn - \fi - \@delimitedtrue + \renewcommand\@diagramtop{\analysistop}% + \renewcommand\@diagrambottom{}% + \if@delimited\else\@@turn\fi + \@turn \if@white\else\advance\move-1\fi - \advance\@commlevel1\relax + \advance\@commlevel1 + \if@skaking + \expandafter\restoregame\expandafter{\@roman{\the\@commlevel}comm-game}% + \if@diagnostics\message{Restored position for comment at level + \the\@commlevel}\fi + \else{} \fi \csname\@roman{\the\@commlevel}font\endcsname \csname\@roman{\the\@commlevel}#1\endcsname + \expandafter\let\expandafter\tm@var\csname tm@var#1\endcsname + \expandafter\let\expandafter\tm@vars\csname tm@var#1s\endcsname + \expandafter\let\expandafter\@preparevar\csname @preparevar#1\endcsname + \expandafter\let\expandafter\@finvar\csname @finvar#1\endcsname + \def\result##1{ ##1}% \@execute} \def\@closecomm#1{\csname\@roman{\the\@commlevel}#1\endcsname - \egroup} + \egroup + \if@skaking + \expandafter\restoregame\expandafter{\@roman{\the\@commlevel}comm-game}% + \if@diagnostics\message{Restored position + after comment at level \the\@commlevel.}\fi + \else{} \fi} +\def\steplevel{\advance\@commlevel1\relax\csname + \@roman{\the\@commlevel}font\endcsname} +\def\backlevel{\advance\@commlevel-1\relax + \ifnum\@commlevel<1\relax\@commlevel1\relax\fi + \csname\@roman{\the\@commlevel}font\endcsname} +\def\@turn{\@delimitedtrue\if@white\@whitefalse\else\@whitetrue\fi} +\def\@@turn{% + \tm@aftermove + \global\let\tm@aftermove\relax + \if@skaking + \@tempcnta\@commlevel\advance\@tempcnta1\relax + \expandafter\storegame\expandafter{\@roman{\the\@tempcnta}comm-game}% + \@tempcnta\move\advance\@tempcnta-1\relax + \edef\tm@tomainline{\noexpand{\if@white\the\move + \else\the\@tempcnta..\fi.\the\@tmtoskak}}% + \if@diagnostics\message{Stored position at level + \the\@commlevel+1, before \tm@tomainline}\fi + \expandafter\hidemoves\tm@tomainline + \@tmtoskak{}% + \fi + \if@delimited\else\@turn\fi} % \end{macrocode} % +%\section{Fonts and contexts} % -%\subsection{Additional tools} -% Sometimes reference to a future move is made without the intervening moves. Macros \DescribeMacro{\dummy}\DescribeMacro{\ddummy}|\dummy| and |\ddummy|, `dummy moves,' instruct \TeX mate to expect not what it was expecting, but something that comes afterwards. The former thus `skips' a turn, the latter a complete move (by both sides). % \begin{macrocode} -\def\dummy{\@turn - \if@white\advance\move1\relax\fi\@execute} -\def\ddummy{\advance\move1\relax\@execute} +\let\ifont\bfseries +\let\iifont\normalfont +\let\iiifont\normalfont +\let\ivfont\itshape +\let\varfont\bfseries +\newcommand*\iopen{}\newcommand*\iclose{} +\newcommand\iiopen{[}\newcommand\iiclose{\leavevmode\unskip]} +\newcommand\iiiopen{(}\newcommand\iiiclose{\leavevmode\unskip)} +\newcommand\ivopen{(}\newcommand\ivclose{\leavevmode\unskip)} +\newcommand*\iiopent{}\newcommand*\iicloset{} +\newcommand*\iiiopent{}\newcommand*\iiicloset{} +\newcommand*\ivopent{}\newcommand*\ivcloset{} +\def\afterno{.~} +\def\afterw{\ } +\def\afterb{\ } +\def\beforeb{\the\move\dots} +\def\beforeno{} % \end{macrocode} +%\section{Commentary tools} % -%\DescribeMacro{\white}\DescribeMacro{\black}|\white| and |\black| force the next input move to be either a white or a black move. In conjunction with typing the move number (they themselves don't try to guess what move number the user is referring to), they provide complete control as to what \TeX mate expects next. % \begin{macrocode} -\def\black{\@whitefalse\@execute} -\def\white{\@whitetrue\@execute} +\long\def\dummy{\PackageWarning{TeXmate}{Ignoring moves for + skak after \string\dummy}% + \@skakingfalse + \@turn + \if@white\advance\move1\relax\fi} +\long\def\ddummy{\PackageWarning{TeXmate}{Ignoring moves for + skak after \string\ddummy}% + \@skakingfalse + \advance\move1\relax} +\def\black{\if@skaking + \PackageWarning{TeXmate}{Ignoring moves for skak. + \string\black command is now almost obsolete}% + \@skakingfalse + \fi + \@whitefalse\@execute} +\def\white{\if@skaking + \PackageWarning{TeXmate}{Ignoring moves for skak. + \string\white command is now almost obsolete}% + \@skakingfalse + \fi + \@whitetrue\@execute} +\def\ahead{% + \if@skaking + \expandafter\hidemoves\tm@tomainline + \fi + \@turn + \if@white\advance\move1\relax\fi + \@execute} +\long\def\threat#1{\bgroup\@skakingfalse\ifcase\@commlevel\or + \iifont\or\iiifont\or\ivfont\or\ivfont\fi\ + \catcode`\>\active\withidea\@@piece} +\long\def\Threat#1{\bgroup + \@skakingfalse + \@resumingtrue + \ifcase\@commlevel\or + \iifont\or\iiifont\or\ivfont\or\ivfont\fi + \catcode`\>\active + \if@delimited\@turn\fi + \ddummy\@execute} % \end{macrocode} % -%To complete user's control, macros \DescribeMacro{\steplevel}\DescribeMacro{\backlevel}|\steplevel| and |\backlevel| allow him to jump from one level of commentary to another, without having to invoke commentaries and all their side-effects. -% \begin{macrocode} -\def\steplevel{\advance\@commlevel1\relax\csname - \@roman{\the\@commlevel}font\endcsname} -\def\backlevel{\advance\@commlevel-1\relax\csname - \@roman{\the\@commlevel}font\endcsname} +%\section{Variations environments} +% +% \begin{macrocode} +\newcommand*\var{\relax} +\newenvironment{variations}{% + \renewcommand\var{\@ifstar{\tm@vars}{\tm@var}}% + \if@skaking + \null\expandafter\storegame\expandafter + {\@roman{\the\@commlevel}comm-var}\leavevmode\unskip + \if@diagnostics + \message{Stored position for variations at level \the\@commlevel.}% + \fi + \fi + \@preparevar\ignorespaces}% + {\@finvar} +\newenvironment{variations*}{% + \renewcommand\var{\tm@vars}% + \if@skaking + \null\expandafter\storegame\expandafter + {\@roman{\the\@commlevel}comm-var}\leavevmode\unskip + \if@diagnostics + \message{Stored position for variations at level \the\@commlevel.}% + \fi + \fi + \@preparevaropen\ignorespaces} + {\@finvaropen} +\def\tm@varopen{\@semicolon\egroup + \if@skaking + \null\expandafter\restoregame\expandafter + {\@roman{\the\@commlevel}comm-var}\leavevmode\unskip + \if@diagnostics + \message{Restored position for variation at level \the\@commlevel.}% + \fi + \fi + \bgroup\varfont\def\tm@aftermove{\backlevel\steplevel}% + \@execute} +\def\tm@varopens{\egroup + \if@skaking + \null\expandafter\restoregame\expandafter + {\@roman{\the\@commlevel}comm-var}\leavevmode\unskip + \if@diagnostics + \message{Restored position for variation at level \the\@commlevel.}% + \fi + \fi + \bgroup\def\tm@aftermove{\backlevel\steplevel}% + \@execute} +\def\tm@varopent{\egroup + \item + \bgroup + \if@skaking + \expandafter\restoregame\expandafter{\@roman{\the\@commlevel}comm-var}% + \if@diagnostics\message{Restored position for variation at level + \the\@commlevel.}\fi + \fi + \@execute} +\let\tm@varopents\tm@varopens +\let\tm@var\tm@varopen +\let\tm@vars\tm@varopens +\def\@preparevaropen{\bgroup\let\@semicolon\relax} +\let\@preparevar\@preparevaropen +\let\@finvaropen\egroup +\let\@finvar\@finvaropen +\newcommand\VariationsEnvironment[2]{% + \def\@preparevaropent{#1\bgroup}\def\@finvaropent{\egroup#2}} +\VariationsEnvironment{\begin{itemize}}{\end{itemize}} % \end{macrocode} % -%The macro \DescribeMacro{\newgame}|\newgame| initializes everything for a new game: +%\section{Diagram information} +% % \begin{macrocode} -\def\newgame{\@whitetrue\@resumingtrue\@commlevel2 \move1 \@delimitedtrue} +\newif\if@turnright +\newif\if@movebottom +\newif\if@turnleft +\newif\if@numbertop +\newif\if@defaultturnright +\newif\if@defaultmovebottom +\newif\if@defaultnumbertop +\newif\if@defaultturnleft +\newcommand*\TheDiagram{\textit{\small\bfseries\arabic{diagram}}} +\newcommand*\diagramnames{\renewcommand*\diagramtop{\textbf{\bname}}% + \renewcommand*\diagrambottom{\@name}% + \@restorediagramdefaults} +\newcommand*\topdiagramnames{\renewcommand*\diagramtop{\textbf{\wname--\bname}}% + \renewcommand*\diagrambottom{}% + \@restorediagramdefaults} +\newcommand*\bottomdiagramnames{\renewcommand*\diagramtop{}% + \renewcommand*\diagrambottom{\textbf{\wname--\bname}}% + \@restorediagramdefaults} +\newcommand*\nodiagramnames{% + \global\let\@diagramtop\relax + \global\let\@diagrambottom\relax} +\newcommand*\whiteturnmarker{\raisebox{.75\expandafter + \ht\csname chessdiag\@roman\@tempcnta\endcsname}{\textsl{W}}\ } +\newcommand*\blackturnmarker{\raisebox{.75\expandafter + \ht\csname chessdiag\@roman\@tempcnta\endcsname}{\textsl{B}}\ } +\newcommand*\diagramnumber{\@numbertoptrue} +\newcommand*\nodiagramnumber{\@numbertopfalse} +\newcommand*\leftdiagramturn{\@turnlefttrue\@turnrightfalse} +\newcommand*\rightdiagramturn{\@turnrighttrue\@turnleffalse} +\newcommand*\nodiagramturn{\@turnleftfalse\@turnrightfalse} +\newcommand*\diagrammove{\@movebottomtrue} +\newcommand*\nodiagrammove{\@movebottomfalse} +\newcommand*\nextdiagramtop[1]{\renewcommand*\@diagramtop{#1}} +\newcommand*\nextdiagrambottom[1]{\renewcommand*\@diagrambottom{#1}} +\newcommand\@restorediagramdefaults{% + \global\let\@diagramtop\diagramtop + \global\let\@diagrambottom\diagrambottom + \global\let\if@turnright\if@defaultturnright + \global\let\if@movebottom\if@defaultmovebottom + \global\let\if@numbertop\if@defaultnumbertop + \global\let\if@turnleft\if@defaultturnleft} +\@turnleftfalse +\@movebottomtrue +\@turnrightfalse +\@defaultmovebottomtrue +\@defaultturnrightfalse +\@defaultturnleftfalse +\@defaultnumbertopfalse +\@restorediagramdefaults +\let\makediagramsfont\small +\newcommand*\analysistop{Analysis} +\newcommand*\diagramtop{\textbf{\bname}} +\newcommand*\diagrambottom{\textbf{\wname}} +\newcommand*\diagramsign{~\mdseries(\textit{D})} +\let\@diagramtop\diagramtop +\let\@diagrambottom\diagrambottom % \end{macrocode} % -%\medskip -%Another very common thing in chess commentary is threats. The \DescribeMacro{\threat}|\threat| macro typesets the symbol for `with the idea of\dots' (a triangle) and allows any text (its argument, delimited by |<| and |>|) to follow. (It momentarily goes out of chess mode.) +%\section{Diagram handling} +% % \begin{macrocode} -\long\def\threat#1{\bgroup\ifcase\@commlevel\or - \iifont\or\iiifont\or\ivfont\or\ivfont\fi\ - \@restorecodes\catcode`\>\active\withidea} +\newcount\@diagramsbuilt +\newcommand*\DiagramCache[1]{% + \@tempcnta#1 + \@whilenum\@tempcnta>0\do{% + \expandafter\newbox\csname chessdiag\@roman\@tempcnta\endcsname + \expandafter\newbox\csname chessdiag\@roman\@tempcnta top\endcsname + \expandafter\newbox\csname chessdiag\@roman\@tempcnta bottom\endcsname + \expandafter\newbox\csname chessdiag\@roman\@tempcnta move\endcsname + \@namedef{chessdiag\@roman\@tempcnta turn}{}% + \advance\@tempcnta-1\relax}% + } +\DiagramCache3 +\newcounter{diagram} +\newcommand*\makediagrams[1][\@diagramsbuilt]{% + \noindent\null\hfill + {\makediagramsfont + \@tempcnta0 + \@whilenum\@tempcnta<#1\do{% + \advance\@tempcnta1\relax + \refstepcounter{diagram}% + \quad\shortstack{% + \if@numbertop\TheDiagram\\\fi + \ifnum\expandafter\wd\csname + chessdiag\expandafter\@roman\@tempcnta top\endcsname>0\relax + \makebox[\expandafter\wd\csname + chessdiag\expandafter\@roman\@tempcnta\endcsname][c]{% + \expandafter\usebox\csname + chessdiag\expandafter\@roman\@tempcnta top\endcsname}% + \\ + \fi + \if@turnleft + \makebox[0pt][r]{\csname + chessdiag\@roman\@tempcnta turn\endcsname}% + \fi + \expandafter\usebox\csname + chessdiag\expandafter\@roman\@tempcnta\endcsname + \if@turnright + \makebox[0pt][l]{\csname + chessdiag\@roman\@tempcnta turn\endcsname}% + \fi + \\ + \expandafter\usebox + \csname chessdiag\expandafter\@roman\@tempcnta bottom\endcsname + \if@movebottom + \ifnum\expandafter\wd\csname + chessdiag\expandafter\@roman\@tempcnta move\endcsname>0 + \ifnum\expandafter\wd\csname + chessdiag\expandafter\@roman\@tempcnta bottom\endcsname>0 + \\ + \fi\expandafter\usebox + \csname chessdiag\expandafter\@roman\@tempcnta move\endcsname + \fi\fi}% + \hfill\quad}}% + \@killdiagrams{#1}% + } +\newcommand*\@killdiagrams[1]{% + \global\advance\@diagramsbuilt-#1\relax + \ifnum\@diagramsbuilt>0\relax + \@tempcnta0\relax + \@tempcntb#1\relax + \@whilenum\@tempcnta<\@diagramsbuilt\do{% + \advance\@tempcnta1\relax + \advance\@tempcntb1\relax + \expandafter\global\expandafter\sbox + \csname chessdiag\expandafter\@roman\@tempcnta\endcsname{% + \expandafter\usebox\csname + chessdiag\@roman\@tempcntb\endcsname}% + \expandafter\global\expandafter\sbox + \csname chessdiag\expandafter\@roman\@tempcnta top\endcsname{% + \expandafter\usebox\csname + chessdiag\@roman\@tempcntb top\endcsname}% + \expandafter\global\expandafter\sbox + \csname chessdiag\expandafter\@roman\@tempcnta bottom\endcsname{% + \expandafter\usebox\csname + chessdiag\@roman\@tempcntb bottom\endcsname}% + \expandafter\global\expandafter\sbox + \csname chessdiag\expandafter\@roman\@tempcnta move\endcsname{% + \expandafter\usebox\csname + chessdiag\@roman\@tempcntb move\endcsname}% + }% + \fi + } +\newcommand*\drawdiagram[2]{% + \global\advance\@diagramsbuilt1\relax + \expandafter\global\expandafter + \sbox\csname chessdiag\@roman\the\@diagramsbuilt\endcsname{\showboard}% + \expandafter\global\expandafter + \sbox\csname chessdiag\@roman\the\@diagramsbuilt + top\endcsname{\makediagramsfont#1}% + \expandafter\global\expandafter + \sbox\csname chessdiag\@roman\the\@diagramsbuilt + bottom\endcsname{\makediagramsfont#2}% + \expandafter\global\expandafter + \sbox\csname chessdiag\@roman\the\@diagramsbuilt + move\endcsname{}% + \if@white + \expandafter\let\csname chessdiag\@roman\@diagramsbuilt + turn\endcsname\whiteturnmarker + \else + \expandafter\let\csname chessdiag\@roman\@diagramsbuilt + turn\endcsname\blackturnmarker + \fi + } +\newcommand*\@toD[1]{\if@delimited\else\@@turn\fi + \global\advance\@diagramsbuilt1\relax + \expandafter\global\expandafter + \sbox\csname chessdiag\expandafter + \@roman\@diagramsbuilt\endcsname{\showboard}% + \expandafter\global\expandafter + \sbox\csname chessdiag\expandafter\@roman\@diagramsbuilt + move\endcsname{% + \mdseries\makediagramsfont\strut\@skakingfalse + \@turn + \if@white + \the\move\afterno + \else + \advance\move-1\relax + \beforeb + \fi + \@@piece#1\relax}% + \expandafter\global\expandafter + \sbox\csname chessdiag\expandafter\@roman\@diagramsbuilt + top\endcsname{\makediagramsfont\@diagramtop}% + \expandafter\global\expandafter + \sbox\csname chessdiag\expandafter\@roman\@diagramsbuilt + bottom\endcsname{\makediagramsfont\@diagrambottom}% + \if@white + \expandafter\let\csname ifwfordiag\expandafter + \@roman\@diagramsbuilt\endcsname\whiteturnmarker + \else + \expandafter\let\csname ifwfordiag\expandafter + \@roman\@diagramsbuilt\endcsname\blackturnmarker + \fi + \@restorediagramdefaults + } % \end{macrocode} % -%\subsection{Inside chess mode} -%Many of the functions described above will be called by active characters inside chess mode. Spaces cannot be used there, so |\iffalse\fi| is used instead of |%|. Since the period and the semicolon are treated especially by \TeX mate in chess mode, |\.| and |\;| are provided to typeset those signs. +%\section{Position setup} +% % \begin{macrocode} -\def\@chessperiod{. } -\def\@chesssemicolon{; } -{\@chesscodes\iffalse -\fi\global\let\.\@chessperiod\iffalse -\fi\global\let\;\@chesssemicolon\iffalse -\fi\gdef+{\checksign}\iffalse -\fi\gdef\#{\mate}\iffalse -\fi\long\gdef #1{\ifx #1\else\iffalse - \fi\if@delimited\else\@turn\fi\expandafter\@execute\fi#1}\iffalse -\fi\gdef.#1{ }\gdef;{ }\iffalse -\fi\global\let>\egroup\iffalse -\fi\gdef[{\@opencomm{open}}\iffalse -\fi\gdef\[{\@opencomm{opent}}\iffalse -\fi\gdef]{\@closecomm{close} }\iffalse -\fi\gdef\]{\@closecomm{closet} }} -% \end{macrocode} +\newcount\@squarecount +\newif\if@blacksq +\newcommand\diagram[2][w 1]{% + \position[#1]{#2}% + \showdiagram} +\newcommand*\fenposition[1]{\@fenposition#1.} +\if@skakon + \newcommand*\toD{\if@delimited\else\@@turn\fi\@ifstar{\@toD}{\diagramsign\@toD}} + \newcommand\position[2][w 1]{% + \@squarecount8\relax + \def\tm@tofen{}% + \@convertdiagram#2.% + \@completefen#1.% + \expandafter\fenboard\tm@tofen% + } + \def\@convertdiagram#1{% + \let\next\@convertdiagram + \ifx#1. + \let\next\relax + \ifnum\@squarecount>0 \edef\tm@tofen{\tm@tofen\the\@squarecount}\fi + \else + \ifx#1/% + \edef\tm@tofen{\tm@tofen\ifnum\@squarecount>0 \the\@squarecount\fi/}% + \@squarecount8\relax + \else + \ifcat1#1% + \edef\tm@tofen{\tm@tofen#1}% + \advance\@squarecount-#1% + \else + \edef\tm@tofen{\tm@tofen#1}% + \advance\@squarecount-1\relax + \fi + \fi\fi + \next} + \def\@completefen#1 #2.{% + \edef\tm@tofen{{\tm@tofen\space #1 KQkq - 0 #2}}% + \move#2\relax + \ifx#1w\@whitetrue\else\@whitefalse\fi} + \def\@fenposition#1 #2 #3 #4 #5 #6.{% + \@squarecount8\relax + \def\tm@tofen{}% + \@convertdiagram#1.% + \edef\tm@tofen{{\tm@tofen\space #2 #3 #4 #5 #6}}% + \expandafter\fenboard\tm@tofen + \move#6\relax + \ifx#2w\@whitetrue\else\@whitefalse\fi + } +\else + \newcommand*\toD{\let\toD\relax + \PackageError{TeXmate}{\string\toD\space requires skak. All occurrences ignored}{% + Go on, diagrams will not be automatically generated.}}% + \let\showboard\relax + \newcommand\position[2][w 1]{% + \@blacksqfalse + \@squarecount8\relax + \bgroup + \nointerlineskip + \boardfont + \noindent + \setlength\fboxsep{.6pt}% + \expandafter\fbox{\parbox{8\len@cfss@squarewidth}{\@diagline#2.}}\egroup} + \def\@diagpiece#1{\def\temp{#1}% + \ifx\temp\@pawn\csname BlackPawnOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@rook\csname BlackRookOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@knight\csname BlackKnightOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@bishop\csname BlackBishopOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@queen\csname BlackQueenOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@king\csname BlackKingOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@Pawn\csname WhitePawnOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@Rook\csname WhiteRookOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@Knight\csname WhiteKnightOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@Bishop\csname WhiteBishopOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@Queen\csname WhiteQueenOn\if@blacksq Black\else White\fi\endcsname\else + \ifx\temp\@King\csname WhiteKingOn\if@blacksq Black\else White\fi\endcsname\else + \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi + } + \def\@diagline#1{\@tempcnta0\relax\let\next\@diagline + \ifx#1.\let\next\relax\@dospaces{\@squarecount}% + \else\ifx#1/\def\next{\@dospaces{\@squarecount}% + \newline\@togglesq\@squarecount8\relax + \@diagline}% + \else\ifcat1#1\@dospaces{#1}% + \else\@diagpiece#1\advance\@squarecount-1\relax\@togglesq + \fi\fi\fi + \next} + \def\@dospaces#1{\null\ifnum#1>0\relax + \csname\if@blacksq Black\else White\fi EmptySquare\endcsname + \@togglesq\@tempcntb#1\relax\advance\@tempcnta1\relax\advance\@squarecount-1\relax + \ifnum\@tempcnta<\@tempcntb\let\@next\@dospaces\else + \let\@next\@gobble\fi + \@next\@tempcntb\fi} + \def\@togglesq{\if@blacksq\@blacksqfalse\else\@blacksqtrue\fi} + \def\@fenposition#1 #2 #3 #4 #5 #6.{% + \position[#2 #6]{#1}} +\fi +% +%\section{Game mark-up} % -%\section{Initialization values} % \begin{macrocode} -\setlength\diagramsize{18pt} -\SquareNo8 -\pieceinitials{PRNBQK} -\let\textpiece\textskak +\def\wname{} +\def\bname{} +\let\@welo\relax +\let\@belo\relax +\let\@tourn\relax +\let\@opening\relax +\let\@eco\relax +\newcommand\whitename[1]{\def\wname{#1}} +\newcommand\blackname[1]{\def\bname{#1}} +\newcommand*\whiteelo[1]{\def\@welo{(#1)}} +\newcommand*\blackelo[1]{\def\@belo{(#1)}} +\newcommand*\chessevent[1]{\def\@tourn{#1}} +\newcommand*\chessopening[1]{\def\@opening{#1}} +\newcommand*\ECO[1]{\def\@eco{\ -- \textbf{#1}}} +\newcommand*\makegametitle{\bigskip\newgame + \noindent\hrule\nopagebreak\smallskip + \noindent\strut$\Box$\quad\textbf{\wname}\ \@welo\hfill\@tourn\nopagebreak\\ + \noindent\strut$\blacksquare$\quad\textbf{\bname}\ \@belo\hfill\@opening\@eco + \noindent\hrule\nopagebreak\medskip\nopagebreak + } +\newcommand*\result[1]{{\unskip\nobreak\hfil\penalty50 + \qquad\null\nobreak\hfill\textbf{#1}% + \parfillskip0pt \finalhyphendemerits0 \par}} +\newcommand\whitewins{\result{1\,:\,0}} +\newcommand\blackwins{\result{0\,:\,1}} +\newcommand\drawn{\result{1/2\,:\,1/2}} +\newcommand\resigns{\if@delimited\else\@@turn\fi + \if@white\blackwins\else\whitewins\fi} +\if@skakon + \let\skak@newgame\newgame +\else + \let\skak@newgame\relax +\fi +\def\newgame{\@whitetrue\@resumingtrue\@commlevel2\move1\@delimitedtrue + \skak@newgame} \newgame -%</package> % \end{macrocode} +% +%\section{Miscellaneous} +% +% \begin{macrocode} +\def\SkakOn{\global\@skakingtrue} +\def\SkakOff{\global\@skakingfalse} +\setboardfontsize{12pt} +\DeclareRobustCommand\BlackRookOnWhite{\cfss@boardsymbol{\cfss@BlackRookOnWhite}} +\let\checksign\checksymbol +\let\wBetter\wupperhand +\let\bBetter\bupperhand +\let\WBetter\wdecisive +\let\BBetter\bdecisive +\let\development\devadvantage +\let\spaceadv\moreroom +\let\attack\withattack +\let\initiative\withinit +\let\boardfile\file +\let\boarddiagonal\diagonal +\let\boardcenter\centre +\let\bishops\bishoppair +\let\oppositebishops\opposbishops +\let\separatedpawns\seppawns +\let\doubledpawns\doublepawns +\let\pawnsno\morepawns +\let\timetrouble\timelimit +\let\chessetc\etc +% \end{macrocode} +%</package> diff --git a/Master/texmf-dist/source/latex/texmate/texmate.ins b/Master/texmf-dist/source/latex/texmate/texmate.ins index 937c943a2fd..86ec7365221 100644 --- a/Master/texmf-dist/source/latex/texmate/texmate.ins +++ b/Master/texmf-dist/source/latex/texmate/texmate.ins @@ -2,7 +2,7 @@ \keepsilent
\preamble
-Copyright 2005 Federico Garcia
+Copyright 2005-6 Federico Garcia
\endpreamble
\generate{\file{texmate.sty}{\from{texmate.dtx}{package}}}
@@ -12,7 +12,7 @@ Copyright 2005 Federico Garcia \Msg{* To finish the installation you have to move the file}
\Msg{* `texmate.sty' into a directory searched by TeX.}
\Msg{*}
-\Msg{* To produce the documentation run the file `texmate.dtx'}
+\Msg{* To typeset the implementation run the file `texmate.dtx'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{***********************************************************}
|