%% scmac.tex
%% TeX macros for typesetting scripts version 2.02
%% Copyright (C) 1989 by Na Choon Piaw
%% This file may be freely used, distributed, and modified provided
%% credit is given to the original author.  You can even try to sell it,
%% assuming someone's willing to pay for this, of course.

%% \begin documentation

%% 2.02 Alpha
%% There never was a 2.00 release.
%% Changes from the documentation are found here:

%% Syntax change:
%% From the beginning of the file we have:
%%	\input scmac.tex
%%	\Style=
%%	\FootNoteStyle=

%% For the \Style, you may choose from:
%%	\OldStyle			(pre 2.00)
%%	\NewStyle			(post 2.00)

%% \OldStyle is fully compatible with version 1.xx
%% \NewStyle is fully compatible with version 2.00

%% For \FootNoteStyle, you may choose from:
%%	\EndNotes			(Put footnotes at the end)
%%	\FootNotes			(Put footnotes at the bottom)

%% Note that these are now the ONLY supported ways of specifying styles.
%% If you put in numbers directly, they might work in this version, but
%% if I change the macros in anyway in the next, they will no longer
%% work.

%% \end documentation

%% macros proper

%% tell user what version
\message{Loading scmac version 2.01 Alpha ...}

%% fonts --- Use Computer Modern.  Substitute these with local
%%           equivalents if no Computer Modern.
\message{fonts.}
\font\bigtenrm=cmr10 scaled\magstep2	%% big font for title
\font\rm=cmr10				%% standard roman text
\font\bf=cmbx10				%% for bold
\font\sl=cmsl10				%% slanted text
\font\it=cmti10				%% italics

%% variable declarations
\message{counters.}
\newcount\fnotecnt
\newcount\FootNoteStyle
\newcount\EndNotes
\newcount\FootNotes
\EndNotes=0
\FootNotes=1
\newcount\Style
\newcount\OldStyle
\newcount\NewStyle
\OldStyle=1
\NewStyle=2
\newwrite\auxfile
\newread\auxrfile
\fnotecnt=1
\FootNoteStyle=\FootNotes		%% "true" footnotes
\Style=\NewStyle

%% preamble handling
\message{preamble.}
\def\Title{}
\def\transl{}
\def\oth{}
\def\cpmessage{}
\def\heading#1{\global\headline={\bf #1 \hfil Page \folio}}
\def\translator#1{\edef\transl{\noindent\it Translation by #1.\hfil}}
\def\others#1{\edef\oth{\noindent\it #1.\hfil}}
\footline={\hfil}

%% open auxilary file.
\message{output files.}
\immediate\openout\auxfile=\jobname.aux

%% little patch to let me do the \let in side \beginscript
%% now, when i rewrite this, i'd better use @s in them just like
%% in plain.tex
\message{macros.}
\gdef\Styleone#1#2{
			\centerline{\bf \noexpand#1}
			{
			\parindent=1in
			\rm\narrower\raggedright\noindent
			\noexpand#2
			\par
			}
			\bigskip\goodbreak
		}
\gdef\Styletwo#1:#2\par{
	\centerline{\bf #1}
		{
			\parindent=1in
			\rm\narrower\raggedright\noindent
			\noexpand
			\hskip -1em\relax #2
			%% horizontal skip to combat the speech-offset
			%% problem.  Remove it if the problem
			%% disappears.
			\par
		}
		\bigskip\goodbreak
	}

%% global \say --- in standard old style --- to warn people that
%% the \style is not set

\def\say#1#2{\message{! scmac Fatal Error: You must start the script with \string\beginscript and
end it with \string\endscript!} \end}

% Environments
\def\beginscript{
	\Title
	\cpmessage
	\transl
	\oth
%%	Remember to recode in case format after I get the TeXbook back from
%%	Case. (Yech!  Just realized the horrible pun)
	\ifnum\Style=\OldStyle
		%% old style: version 1.xx
		\let\say=\Styleone
		\let\errcheck=\relax
	\else
		\ifnum\Style=\NewStyle
			%% version 2.xx
			\let\say=\Styletwo
			\let\errcheck=\relax
		\else
			\message{!Scmac Fatal Error: Style \the\Style is not supported!}
			\let\errcheck=\end
		\fi
	\fi
	\errcheck
}

\def\endscript{
\immediate\closeout\auxfile
\ifnum\FootNoteStyle=\FootNotes
	\relax
\else 
	\ifnum\FootNoteStyle=\EndNotes
		%% read in from aux file.
		\bigskip
		\filbreak
		\line{\bf Footnotes\hfil}
		\openin\auxrfile = \jobname.aux
		\readfootnotes
	\else
		\message{scmac Warning: \the\FootNoteStyle is not supported}
	\fi
\fi
}

%% songs
\def\beginsong{\bigskip\begingroup\obeylines\narrower}
\def\endsong{\par\endgroup\bigskip}

\def\readfootnotes{
%% recursive TeX macro!  Can WordPerfect do this?
\def\temp{}
\ifeof 1
	\relax
\else
	\read \auxrfile to \temp
	\ifeof \auxrfile
		\relax
	\else
		\item{[\temp]}
		\read \auxrfile to \temp
		\temp
		\readfootnotes
	\fi
\fi
}

%% describe and desc are unchanged.
\def\describe#1{\sl #1 \medskip\goodbreak}
\def\desc#1{\it (#1\/)\rm}

%% footnoting
\def\fnote#1{\ifnum\FootNoteStyle=1				
%% footnotes at bottom of page
 	\footnote{$^{\the\fnotecnt}$}{\rm #1}
\else 
%% new-style typeinto aux file  for readback
%% remember to change the \hskip value for different fonts!
	$^{\the\fnotecnt}$ \hskip -0.15in
	\immediate\write\auxfile{\the\fnotecnt}
	\immediate\write\auxfile{#1}
\fi
\global\advance\fnotecnt by 1
}
\message{done.}