% Macros for R^nRS.

% tex2page.sty mucks with in some manner
\let\centerlinesaved=\centerline
\usepackage{tex2page}
\let\centerline=\centerlinesaved

\usepackage{xr-hyper}

\usepackage{makeidx}
\usepackage{hyperref}

% \let\htmlonly=\iffalse
% \let\endhtmlonly=\fi
% \let\texonly=\iftrue
% \let\endtexonly=\fi

\makeatletter

\texonly
\newcommand{\topnewpage}{\@topnewpage}
\endtexonly

\htmlonly
\newcommand{\topnewpage}[0][]{#1}
\endhtmlonly

\newcommand{\authorsc}[1]{{\scriptsize\scshape #1}}

% Chapters, sections, etc.

\newcommand{\extrapart}[1]{
 % \chapter{#1}
  \chapter*{#1}
  \markboth{#1}{#1}
  \vskip 1ex
  \addcontentsline{toc}{chapter}{#1}}

\newcommand{\clearchaptergroupstar}[1]{
  \texonly
  \clearpage
  \addcontentsline{toc}{chaptergroup}{#1}
  \topnewpage[
    \centerline{\large\bf\uppercase{#1}}
    \bigskip]
    \endtexonly
  }

\newcommand{\clearchapterstar}[1]{
  \clearpage
  \topnewpage[
    \centerline{\large\bf\uppercase{#1}}
    \bigskip]}

\newcommand{\clearextrapart}[1]{
  \clearchapterstar{#1}
  \markboth{#1}{#1}
  \addcontentsline{toc}{chapter}{#1}}

\newcommand{\vest}{}
\newcommand{\dotsfoo}{$\ldots\,$}

\newcommand{\sharpfoo}[1]{{\tt\##1}}
\newcommand{\schfalse}{\sharpfoo{f}}
\newcommand{\schtrue}{\sharpfoo{t}}

\newcommand{\ampfoo}[1]{{\tt\&#1}}

\newcommand{\libfoo}[1]{{\tt(#1)}}

\newcommand{\singlequote}{{\tt'}}  %\char19
\newcommand{\doublequote}{{\tt"}}
\newcommand{\backquote}{{\tt\char18}}
\newcommand{\backwhack}{{\tt\char`\\}}
\newcommand{\comma}{{\tt\char`\@}}
\newcommand{\atsign}{{\tt\char`\@}}
\newcommand{\bang}{{\tt\char`\!}}
\newcommand{\sharpsign}{{\tt\#}}
\newcommand{\verticalbar}{{\tt|}}
\newcommand{\openbracket}{{\tt\char`\[}}
\newcommand{\closedbracket}{{\tt\char`\]}}
\newcommand{\ampersand}{{\tt\char`\&}}

\newcommand{\coerce}{\discretionary{->}{}{->}}

% Knuth's \in sucks big boulders
\def\elem{\hbox{\raise.13ex\hbox{$\scriptstyle\in$}}}

\newcommand{\meta}[1]{{\noindent\hbox{\rm$\langle$#1$\rangle$}}}
\let\hyper=\meta
\newcommand{\hyperi}[1]{\hyper{#1$_1$}}
\newcommand{\hyperii}[1]{\hyper{#1$_2$}}
\newcommand{\hyperiii}[1]{\hyper{#1$_3$}}
\newcommand{\hyperiv}[1]{\hyper{#1$_4$}}
\newcommand{\hyperj}[1]{\hyper{#1$_i$}}
\newcommand{\hypern}[1]{\hyper{#1$_n$}}
\texonly
\newcommand{\var}[1]{\noindent\hbox{\textnormal{\textit{#1}}}}
\endtexonly
\htmlonly
\newcommand{\var}[1]{\textnormal{\textit{#1}}}
\endhtmlonly
\newcommand{\vari}[1]{\var{#1$_1$}}
\newcommand{\varii}[1]{\var{#1$_2$}}
\newcommand{\variii}[1]{\var{#1$_3$}}
\newcommand{\variv}[1]{\var{#1$_4$}}
\newcommand{\varj}[1]{\var{#1$_j$}}
\newcommand{\vark}[1]{\var{#1$_k$}}
\newcommand{\varn}[1]{\var{#1$_n$}}

\newcommand{\vr}[1]{{\noindent\hbox{$#1$\/}}}  % Careful, is \/ always the right thing?
\newcommand{\vri}[1]{\vr{#1_1}}
\newcommand{\vrii}[1]{\vr{#1_2}}
\newcommand{\vriii}[1]{\vr{#1_3}}
\newcommand{\vriv}[1]{\vr{#1_4}}
\newcommand{\vrv}[1]{\vr{#1_5}}
\newcommand{\vrj}[1]{\vr{#1_j}}
\newcommand{\vrn}[1]{\vr{#1_n}}

%%R4%% The excessive use of the code font in the numbers section was
% confusing, somewhat obnoxious, and inconsistent with the rest
% of the report and with parts of the section itself.  I added
% a \tupe no-op, and changed most old uses of \type to \tupe,
% to make it easier to change the fonts back if people object
% to the change.

\newcommand{\type}[1]{{\it#1}}
\newcommand{\tupe}[1]{{#1}}

\newcommand{\defining}[1]{\mainindex{#1}{\em #1}}
\newcommand{\ide}[1]{{\schindex{#1}\frenchspacing\tt{#1}}}

\newcommand{\lambdaexp}{{\cf lambda} expression}

\newcommand{\callcc}{{\tt call-with-current-continuation}}

\newcommand{\mainschindex}[1]{\label{#1}\index{#1@\texttt{#1}}}
\newcommand{\mainindex}[1]{\index{#1}}
\newcommand{\schindex}[1]{\index{#1@\texttt{#1}}}
\newcommand{\sharpindex}[1]{\index{#1@\texttt{\#{}#1}}}
\newcommand{\sharpbangindex}[1]{\index{#1@\texttt{\#!#1}}}
\newcommand{\ampindex}[1]{\index{#1@\texttt{\&{}#1}}}
\newcommand{\libindex}[1]{\index{#1@\texttt{(#1)}}}

\texonly
\newcommand{\extref}[2]{\ref{#1}}
\endtexonly
\htmlonly
\newcommand{\extref}[2]{on ``#2''}
\endhtmlonly

\renewenvironment{theindex}
{\texonly\clearpage\endtexonly
\topnewpage[
    \begin{center}
      \large\bf\MakeUppercase{\indexheading}
    \end{center}
    \vskip 1ex \bigskip]
    \markboth{Index}{Index}
    \addcontentsline{toc}{chapter}{\indexheading}
    \parindent\z@
    \texonly\parskip\z@ plus .1pt\endtexonly\relax\let\item\@idxitem
    \indexintro\par\bigskip}
               {\texonly\clearpage\endtexonly}


\newcommand{\domain}[1]{#1}
\newcommand{\nodomain}[1]{}
%\newcommand{\todo}[1]{{\rm$[\![$!!~#1$]\!]$}}
\newcommand{\todo}[1]{}

% \frobq will make quote and backquote look nicer.
\def\frobqcats{%\catcode`\'=13
\catcode`\`=13{}}
{\frobqcats
\gdef\frobqdefs{%\def'{\singlequote}
\def`{\backquote}}}
\def\frobq{\frobqcats\frobqdefs}

% \cf = code font
% Unfortunately, \cf \cf won't work at all, so don't even attempt to
% next constructions which use them...
\newcommand{\cf}{\frenchspacing\frobq\tt}

\texonly
% Same as \obeycr, but doesn't do a \@gobblecr.
{\catcode`\^^M=13 \gdef\myobeycr{\catcode`\^^M=13 \def^^M{\\}}%
\gdef\restorecr{\catcode`\^^M=5 }}
\endtexonly

{\obeyspaces\gdef {\hbox{\hskip0.5em}}}

\gdef\gobblecr{\@gobblecr}

\def\setupcode{\@makeother\^}

% Scheme example environment
% At 11 points, one column, these are about 56 characters wide.
% That's 32 characters to the left of the => and about 20 to the right.

\newcommand{\exception}[1]{{\cf#1} \textnormal{\textit{exception}}}
\newenvironment{schemenoindent}{
  % Commands for scheme examples
  \newcommand{\ev}{\>\>\evalsto}
  \newcommand{\xev}{\>\>\hspace*{-1em}\evalsto}
  \newcommand{\lev}{\\\>\evalsto}
  \newcommand{\unspecified}{{\em{}unspecified}}
  \newcommand{\theunspecified}{{\em{}unspecified}}
  \setupcode
  \small \cf \obeyspaces \myobeycr
  \begin{tabbing}%
\qquad\=\hspace*{5em}\=\hspace*{9em}\=\evalsto~\=\kill%   was 16em
\gobblecr}{\unskip\end{tabbing}}

%\newenvironment{scheme}{\begin{schemenoindent}\+\kill}{\end{schemenoindent}}
\newenvironment{scheme}{
  % Commands for scheme examples
  \newcommand{\ev}{\>\>\evalsto}
  \newcommand{\xev}{\>\>\hspace*{-1em}\evalsto}
  \newcommand{\lev}{\\\>\evalsto}
  \renewcommand{\em}{\rmfamily\itshape}
  \newcommand{\unspecified}{{\em{}unspecified}}
  \newcommand{\theunspecified}{{\em{}unspecified}}
  \setupcode
  \small \cf \obeyspaces \myobeycr
  \begin{tabbing}%
\qquad\=\hspace*{5em}\=\hspace*{9em}\=\evalsto~\=\+\kill%   was 16em
\gobblecr}{\unskip\end{tabbing}}

\texonly
\newcommand{\evalsto}{$\Longrightarrow$}
\endtexonly
 \htmlonly
\newcommand{\evalsto}{$\Rightarrow$}
\endhtmlonly

% Rationale

\newenvironment{rationale}{%
\bgroup\small\noindent{\em Rationale:}\space}{%
\egroup}

% Notes

\newenvironment{note}{%
\bgroup\small\noindent{\em Note:}\space}{%
\egroup}

% Names of library modules

\newcommand{\library}[1]{{\tt (#1)}}
\newcommand{\deflibrary}[1]{\library{#1}\libindex{#1}}

\newcommand{\rsixlibrary}[1]{\library{rnrs #1 (6)}}
\newcommand{\defrsixlibrary}[1]{\deflibrary{rnrs #1 (6)}}

\newcommand{\thersixlibrary}{\library{rnrs (6)}}
\newcommand{\defthersixlibrary}{\deflibrary{rnrs (6)}}

% Manual entries

\newenvironment{entry}[1]{
  \vspace{3.1ex plus .5ex minus .3ex}\noindent#1%
\unpenalty\nopagebreak}{\vspace{0ex plus 1ex minus 1ex}}

\newcommand{\exprtype}{syntax}

\newcommand{\unspecifiedreturn}{unspecified values}
\newcommand{\isunspecified}{is unspecified}
\newcommand{\areunspecified}{are unspecified}

% Primitive prototype
\newcommand{\pproto}[2]{\unskip%
\hbox{\cf\spaceskip=0.5em#1}\hfill\penalty 0%
\hbox{ }\nobreak\hfill\hbox{\rm #2}\break}

% Parenthesized prototype
\newcommand{\proto}[3]{\pproto{(\mainschindex{#1}\hbox{#1}{\it#2\/})}{#3}}

% Variable prototype
\newcommand{\vproto}[2]{\mainschindex{#1}\pproto{#1}{#2}}

% Condition-type prototype
 \newcommand{\ctproto}[1]{\ampindex{#1}\pproto{\ampfoo{#1}}{condition type}}

% Prototype for literal syntax, no index
\newcommand{\litprotonoindex}[1]{\pproto{#1}{auxiliary syntax}}

% Prototype for literal syntax
\newcommand{\litproto}[1]{\mainschindex{#1}\litprotonoindex{#1}}

% Prototype for literal syntax at level 1, no index
\newcommand{\litprotoexpandnoindex}[1]{\pproto{#1}{auxiliary syntax ({\tt expand)}}}

% Prototype for literal syntax at level 1
\newcommand{\litprotoexpand}[1]{\mainschindex{#1}\litprotoexpandnoindex{#1}}

% Extending an existing definition (\proto without the index entry)
\newcommand{\rproto}[3]{\pproto{(\hbox{#1}{\it#2\/})}{#3}}

% Extending an existing definition, with index entry
\newcommand{\irproto}[3]{\schindex{#1}\rproto{#1}{#2}{#3}}

% Variable prototype
\newcommand{\rvproto}[2]{\pproto{#1}{#2}}

% Grammar environment

\newenvironment{grammar}{
  \def\:{\goesto{}}
  \def\|{$\vert$}
  \cf \myobeycr
  \begin{tabbing}
    %\qquad\quad \= 
    \qquad \= $\vert$ \= \kill
  }{\unskip\end{tabbing}}

%\newcommand{\unsection}{\unskip}
\newcommand{\unsection}{{\vskip -2ex}}

% Allow line break after hyphen
\newcommand{\hp}{\linebreak[0]}

\texonly
\newcommand{\itspace}{\hspace{1pt}}
\endtexonly
\htmlonly
\newcommand{\itspace}{}
\endhtmlonly

% Commands for grammars
\newcommand{\arbno}[1]{#1\hbox{\rm*}}  
\newcommand{\atleastone}[1]{#1\hbox{$^+$}}

\texonly
\newcommand{\goesto}{$\longrightarrow$}
\endtexonly
 \htmlonly
\newcommand{\goesto}{$\rightarrow$}
\endhtmlonly

\newcommand{\syntax}{{\em Syntax: }}
\newcommand{\semantics}{{\em Semantics: }}
\newcommand{\implresp}{{\em Implementation responsibilities: }}

\newcommand{\rrs}[1]{\textit{Revised$^#1$ Report on the Algorithmic Language Scheme}}

\newcommand{\libindexentry}[1]{#1 (library)}

\makeatother

\input{revision}
