% tex-squares.sty  1 Mar 90

% Macros for inserting pictures of square dance formations into TeX documents.
%
% This style option is designed to work with the article document
% style of LaTeX version 2.09.  Use
% \documentstyle[tex-squares]{article}

% Authors: Larry Denenberg <larry@bbn.com>, Stephen Gildea <gildea@bbn.com>
%  Comments and suggestions welcome.

%  29 Jul 88: allow dancers to be on half-spots.
%  30 Aug 88: made font-independent, added \displayfive
%  31 Aug 88: added offset phantom dancers
%  14 Sep 88: added other useful non-picture commands and renamed .tex => .sty
%  27 Apr 89: added \setdancersize to allow changing the size of the dancers
%  04 May 89: fix to \setdancersize to scale offset dancer offset, too
%  30 May 89: added table of contents support
%  17 Oct 89: added \caption
%   1 Mar 90: modified by sue to have more space in displaythree

%
%  To do:
%    Eric wants to see the space between setups in the \displayn
%       family to be more if possible (stretchable glue)

%\font\dancerfont=\fontname\tenrm scaled\magstep2
%\font\bulletfont=\fontname\tensy scaled\magstep2
\font\dancerfont=\fontname\tenrm
\font\bulletfont=\fontname\tensy

\def\bulletchar{{\bulletfont\char15}}

\newdimen\side			%size of dancers
\newdimen\thickness\thickness=0.6pt %width of rules
\newskip\formationhspread\formationhspread=0.5em %1/2 the total dist
\newskip\formationvspread\formationvspread=0.5em %1/2 the total dist
\newcount\phantomdashes\phantomdashes=2	%Eric's value.  Larry used 4.
\newdimen\bullethmargin\bullethmargin=1.4pt
\newdimen\bulletvmargin\bulletvmargin=0.9pt
\newdimen\captionskip\captionskip=0.2cm

\newdimen\outside
\newbox\bulletbox\setbox\bulletbox=\hbox{\bulletchar}
\newdimen\totalheight

\newbox\left\setbox\left=\hbox to \wd\bulletbox{} \let\right=\left
\newbox\top\setbox\top=\vbox to \ht\bulletbox{} \let\bottom=\top
\newbox\hbullet
\newbox\vbullet

\newbox\vbar
\newbox\vpbar
\newbox\hbar
\newbox\hpbar

\newskip\halfhoffset 
\newskip\halfvoffset 

% Set the size of the box that is a dancer.  This does not change
% the font used inside the dancer or the font used for the nose.

\def\setdancersize#1{
  \side=#1
  \outside=\side
    \advance\outside by 2\thickness
  \totalheight=\outside
    \advance\totalheight by 2\ht\bulletbox
    \advance\totalheight by -2\bulletvmargin

  \setbox\hbullet=\vbox to \totalheight{\vfil\copy\bulletbox\vfil}
  \setbox\vbullet=\hbox to \side{\hfil\copy\bulletbox\hfil}

  \setbox\vbar=\vbox to \totalheight
    {\vfil\hrule height\outside width\thickness\vfil}
  \dimen0=\outside \divide\dimen0 by \phantomdashes
  \setbox0=\vbox to \dimen0
    {\xleaders\vrule width\thickness\vfil\vfil\vfil
     \xleaders\vrule width\thickness\vfil}
  \setbox\vpbar=\vbox to \totalheight
    {\vfil\vbox to \outside{\xleaders\box0\vfil}\vfil}

  \setbox\hbar=\hbox{\vrule height\thickness width\side}
  \dimen0=\side \divide\dimen0 by \phantomdashes
  \setbox0=\hbox to \dimen0
    {\xleaders\hrule height\thickness\hfil\hfil\hfil
     \xleaders\hrule height\thickness\hfil}
  \setbox\hpbar=\hbox to \side{\xleaders\box0\hfil}

  \halfhoffset=\totalheight \advance\halfhoffset\formationhspread
  \halfvoffset=\totalheight \advance\halfvoffset\formationvspread
} % end of \setdancersize

% Set up default size

%\setdancersize{3.7ex}		%Larry's original
\setdancersize{2ex}

% Draw a male dancer.
% First arg: character to draw inside.
% Second arg: n, s, e, or w (the direction the dancer is facing).
%    Can also be v (n and s combined) or h (e and w combined).
%    Using x causes no nose at all to be drawn.
\def\dancer#1#2{{\offinterlineskip
\if#2n\let\top\vbullet\fi\if#2e\let\right\hbullet\fi
\if#2s\let\bottom\vbullet\fi\if#2w\let\left\hbullet\fi
\if#2v\let\top\vbullet\let\bottom\vbullet\fi
\if#2h\let\left\hbullet\let\right\hbullet\fi
\hbox{\copy\left\kern-\bullethmargin\copy\vbar
      \vbox{\copy\top\kern-\bulletvmargin\copy\hbar
            \vbox to \side{\vss\hbox to \side{\hss\dancerfont #1\hss}\vss}
            \copy\hbar\kern-\bulletvmargin\copy\bottom}\relax
      \copy\vbar\kern-\bullethmargin\copy\right}}}
\def\bdancern#1#2{\dancer{#1}{#2}}

% Draw a female dancer.
% First arg: character to draw inside.
% Second arg: n, s, e, or w (the direction the dancer is facing).
%    Can also be v (n and s combined) or h (e and w combined).
%    Using x causes no nose at all to be drawn.
\def\gdancern#1#2{{\offinterlineskip
\if#2n\let\top\vbullet\fi\if#2e\let\right\hbullet\fi
\if#2s\let\bottom\vbullet\fi\if#2w\let\left\hbullet\fi
\if#2v\let\top\vbullet\let\bottom\vbullet\fi
\if#2h\let\left\hbullet\let\right\hbullet\fi
\begin{picture}(0,0)
\put(9,9){\circle{12}}
\end{picture}
\hbox{\copy\left\kern-\bullethmargin
      \vbox{\copy\top\kern-\bulletvmargin
            \vbox to \side{\vss\hbox to \side{\hss\dancerfont #1\hss}\vss}
            \kern-\bulletvmargin\copy\bottom}\relax
      \kern-\bullethmargin\copy\right}}}

\def\bdancer#1{\bdancern {}{#1}}
\def\gdancer#1{\gdancern {}{#1}}

% Phantom dancer: drawn with dashes
\def\pbdancern#1#2{{\let\vbar\vpbar\let\hbar\hpbar\bdancern{#1}{#2}}}
\def\pgdancern#1#2{{\let\vbar\vpbar\let\hbar\hpbar\gdancern{#1}{#2}}}

\def\pbdancer#1{\pbdancern {}{#1}}
\def\pgdancer#1{\pgdancern {}{#1}}

% Invisible dancer: just takes up space.
\def\idancer{\nsdancerbox{}}

% Four dancers that are offset half a position
%  to the n, s, e, and w respectively
\def\bndancern#1#2{\nsdancerbox{\vss\kern -\halfvoffset\bdancern{#1}{#2}\vss}}
\def\bsdancern#1#2{\nsdancerbox{\vss\kern +\halfvoffset\bdancern{#1}{#2}\vss}}
\def\bedancern#1#2{\ewdancerbox{\hss\kern +\halfhoffset\bdancern{#1}{#2}\hss}}
\def\bwdancern#1#2{\ewdancerbox{\hss\kern -\halfhoffset\bdancern{#1}{#2}\hss}}
\def\gndancern#1#2{\nsdancerbox{\vss\kern -\halfvoffset\gdancern{#1}{#2}\vss}}
\def\gsdancern#1#2{\nsdancerbox{\vss\kern +\halfvoffset\gdancern{#1}{#2}\vss}}
\def\gedancern#1#2{\ewdancerbox{\hss\kern +\halfhoffset\gdancern{#1}{#2}\hss}}
\def\gwdancern#1#2{\ewdancerbox{\hss\kern -\halfhoffset\gdancern{#1}{#2}\hss}}
\def\bndancer#1{\nsdancerbox{\vss\kern -\halfvoffset\bdancer{#1}\vss}}
\def\bsdancer#1{\nsdancerbox{\vss\kern +\halfvoffset\bdancer{#1}\vss}}
\def\bedancer#1{\ewdancerbox{\hss\kern +\halfhoffset\bdancer{#1}\hss}}
\def\bwdancer#1{\ewdancerbox{\hss\kern -\halfhoffset\bdancer{#1}\hss}}
\def\gndancer#1{\nsdancerbox{\vss\kern -\halfvoffset\gdancer{#1}\vss}}
\def\gsdancer#1{\nsdancerbox{\vss\kern +\halfvoffset\gdancer{#1}\vss}}
\def\gedancer#1{\ewdancerbox{\hss\kern +\halfhoffset\gdancer{#1}\hss}}
\def\gwdancer#1{\ewdancerbox{\hss\kern -\halfhoffset\gdancer{#1}\hss}}

% offset phantom dancers.
%\def\npdancer#1#2{\nsdancerbox{\vss\kern -\halfvoffset\pdancer{#1}{#2}\vss}}
%\def\spdancer#1#2{\nsdancerbox{\vss\kern +\halfvoffset\pdancer{#1}{#2}\vss}}
%\def\epdancer#1#2{\ewdancerbox{\hss\kern +\halfhoffset\pdancer{#1}{#2}\hss}}
%\def\wpdancer#1#2{\ewdancerbox{\hss\kern -\halfhoffset\pdancer{#1}{#2}\hss}}

% Not user-level macros, but useful in the above definitions.
% Larry:
%   The first \totalheight in this definition is technically wrong.  Tough.
\def\nsdancerbox#1{\hbox to \totalheight{\hss\vbox to \totalheight{#1}}}
\def\ewdancerbox#1{\vbox to \totalheight{\vss\hbox to \totalheight{#1}}}

% designated boy and girl, named

\def\dbdancern#1#2{\bdancern{$\cdot$#1}{#2}}
\def\dgdancern#1#2{\gdancern{$\cdot$#1}{#2}}

% designated boy and girl, unnamed

\def\dbdancer#1{\bdancern {$\cdot$}#1}
\def\dgdancer#1{\gdancern {$\cdot$}#1}

% Allemande spots

\def\xallemandea#1{$\formation{\bdancern #1x  \bdancer x \bdancer x
\bdancer x}$}
\def\xallemandeb#1{$\formation{\bdancer x \bdancern #1x \bdancer x
\bdancer x}$}
\def\xallemandec#1{$\formation{\bdancer x \bdancer x \bdancern #1x
\bdancer x}$}
\def\xallemanded#1{$\formation{\bdancer x \bdancer x \bdancer x
\bdancern #1x}$}

\def\allemandeaO{\xallemandea{\o}}
\def\allemandebO{\xallemandeb{\o}}
\def\allemandecO{\xallemandec{\o}}
\def\allemandedO{\xallemanded{\o}}
\def\allemandeaX{\xallemandea{\x}}
\def\allemandebX{\xallemandeb{\x}}
\def\allemandecX{\xallemandec{\x}}
\def\allemandedX{\xallemanded{\x}}

\def\vxallemanded#1{$\formation{\bdancern #1x \\ \bdancer x \\ \bdancer x \\
\bdancer x}$}
\def\vxallemandec#1{$\formation{\bdancer x \\ \bdancern #1x \\ \bdancer x \\
\bdancer x}$}
\def\vxallemandeb#1{$\formation{\bdancer x \\ \bdancer x \\ \bdancern #1x \\
\bdancer x}$}
\def\vxallemandea#1{$\formation{\bdancer x \\ \bdancer x \\ \bdancer x \\
\bdancern #1x}$}

\def\vallemandeaO{\vxallemandea{\o}}
\def\vallemandebO{\vxallemandeb{\o}}
\def\vallemandecO{\vxallemandec{\o}}
\def\vallemandedO{\vxallemanded{\o}}
\def\vallemandeaX{\vxallemandea{\x}}
\def\vallemandebX{\vxallemandeb{\x}}
\def\vallemandecX{\vxallemandec{\x}}
\def\vallemandedX{\vxallemanded{\x}}

\def\call#1{{\sc{#1}}}
\def\highlight#1{\begin{quote}#1\end{quote}}

\def\x{${\cal X}$}
\def\o{${\cal O}$}

\def\note#1{{\bf Note:} {\em #1\/}}
\newenvironment{sequence}{\begin{quote}\sc}{\end{quote}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Dancer Display Environments %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\formation#1{
  {\def\quad{\hskip\formationhspread}
   \def\cr{\crcr\noalign{\vskip\formationvspread}}
   \let\\=\cr
   \matrix{#1}}}

% \wideformation and \tallformation make quarter tags look better

\def\wideformation#1{
  {\def\quad{\hskip 2\formationhspread}
   \def\cr{\crcr\noalign{\vskip\formationvspread}}
   \matrix{#1}}}

\def\tallformation#1{
  {\def\quad{\hskip\formationhspread}
   \def\cr{\crcr\noalign{\vskip 2\formationvspread}}
   \matrix{#1}}}

\def\displayone#1#2{\nopagebreak[2]$$
\begin{array}{c}
\formation{#1}\\*[\captionskip]
\mbox{#2}
\end{array}
$$\afterdisplay}

\def\displaytwo#1#2#3#4{\nopagebreak[2]$$
\begin{array}{c@{\hspace{1in}}c}
\formation{#1}
&\formation{#3}\\*[\captionskip]
\mbox{#2}&\mbox{#4}
\end{array}
$$\afterdisplay}

\def\displaytworv#1#2#3#4#5#6{\nopagebreak[2]$$
\begin{array}{cl@{\hspace{1in}}cl}
\formation{#1} & \mbox{#2}
&\formation{#4} & \mbox{#5}\\*[\captionskip]
\mbox{#3}&&\mbox{#6}&
\end{array}
$$\afterdisplay}

\def\displaytwolv#1#2#3#4#5#6{\nopagebreak[2]$$
\begin{array}{cl@{\hspace{1in}}cl}
\mbox{#2} & \formation{#1} 
& \mbox{#5} &\formation{#4} \\*[\captionskip]
&\mbox{#3}&&\mbox{#6}
\end{array}
$$\afterdisplay}

\def\displaythree#1#2#3#4#5#6{\nopagebreak[2]$$
\begin{array}{c@{\hspace{0.5in}}c@{\hspace{0.5in}}c}
\formation{#1}
&\formation{#3}
&\formation{#5}\\*[\captionskip]
\mbox{#2}&\mbox{#4}&\mbox{#6}
\end{array}
$$\afterdisplay}

\def\displayfour#1#2#3#4#5#6#7#8{\nopagebreak[2]$$
\begin{array}{c@{\hspace{0.25in}}c@{\hspace{0.25in}}c@{\hspace{0.25in}}c}
\formation{#1}
&\formation{#3}
&\formation{#5}
&\formation{#7}\\*[\captionskip]
\mbox{#2}&\mbox{#4}&\mbox{#6}&\mbox{#8}
\end{array}
$$\afterdisplay}

% \displayfive is tricky because a macro can only have up to nine
% parameters.  Nevertheless, this behaves exactly as if it had ten.

\def\displayfive#1#2{\toks0={#1}\toks1={#2}\displayfivex}
\def\displayfivex#1#2#3#4#5#6#7#8{\nopagebreak[2]$$
\begin{array}{c@{\hspace{0.25in}}%
  c@{\hspace{0.25in}}c@{\hspace{0.25in}}c@{\hspace{0.25in}}c}
\formation{\the\toks0}
&\formation{#1}
&\formation{#3}
&\formation{#5}
&\formation{#7}\\*[\captionskip]
\mbox{\the\toks1}&\mbox{#2}&\mbox{#4}&\mbox{#6}&\mbox{#8}
\end{array}
$$\afterdisplay}

% useful for multi-line captions.  You can use \\ inside of this.
\newcommand\ctablebox[1]{\begin{tabular}[c]{@{}c@{}}#1\end{tabular}}

% Puts a page-wide caption under the FOLLOWING display.
% Yes, you specify this before the display, and it appears after.
% That's because we have to set up to ensure no page break after the display.
\def\newcaption#1{\postdisplaypenalty=\@M
  \def\afterdisplay{\par \vskip-\lastskip
    {\centering\ctablebox{#1}\par}\postdisplaypenalty=\z@
    \def\afterdisplay{}}}

\def\afterdisplay{}
