% -*- Mode: TeX -*-

\ifx\thisfileis\anUndefinedMacro\input maybeload \fi

\thisfileis{<eb.tex.texlocal>sentences} % abort loading if we're already loaded

\input redefine

% A referenceable "sentences" list environment for Latex.  Remember to
% put "{}" % after the \item command if the sentence begins with "[".
% There is also a "subsentences" environment.

\makeatletter

\newif\ifinsentences
\insentencesfalse

\newcounter{sentence}
\newcounter{subsentence}[sentence]

% These next definitions define the format of the "sentence"
% and "subsentence" counters.  It is tricky to get them right.
% First of all, the parentheses in "(4)" and "(2iii)" are
% defined to be part of the printed representation of the
% "sentence" and "subsentence" counters.  This is so that
% parentheses will be included in \ref - \label constructions.
% Second, the "subsentence" counter must print out with the
% "sentence" number included as well; this is similar to
% what happens with the section and chapter counters. 
% Third, despite the second requirement, the "subsentence"
% counter must appear without the sentence number when it
% is actually used to number a subsentence.
%
% We use two auxiliary control sequences here and below in order
% to make it easier to change the subsentence numbering style.
% The two control sequences are \subsentencenumbering, which should
% be \let to something like \roman or \alph, and
% \subsentencepunctuation, which controls the format of subsentence
% numbers as they appear before the subsentences.

\def\thesentence{(\arabic{sentence})}
\def\thesubsentence{(\arabic{sentence}\subsentencenumbering{subsentence})}

% These next two definitions are defaults.

\let\subsentencenumbering\roman
\def\subsentencepunctuation#1{(#1)}

%%% Using \begin{list} and \end{list} in the argument of a
%%% \newenvironment command doesn't work properly; I have to call
%%% \list and \endlist directly.

\newenvironment{sentences}{\list{\thesentence}%
{\edef\sent@nbr{\the\c@sentence}\usecounter{sentence}%
\setcounter{sentence}{\sent@nbr}%
\ifinsentences \errmessage{Nested sentences environment.} \fi
\def\makelabel##1{##1\hfil}%
\leftmargin\leftmargini\labelwidth\leftmargin
  \advance\labelwidth-\labelsep
\insentencestrue}}{\endlist}

\newenvironment{subsentences}{\list
{\subsentencepunctuation{\subsentencenumbering{subsentence}}}%
{\edef\sent@nbr{\the\c@subsentence}\usecounter{subsentence}%
\setcounter{subsentence}{\sent@nbr}%
\leftmargin\leftmargini\labelwidth\leftmargin
  \advance\labelwidth-\labelsep
\def\makelabel##1{##1\hfil}%
\ifinsentences\relax\else
   \errmessage{\string\begin{subsentences} not in sentences environment}\fi}}%
{\endlist}

% These sentence-judgement macros are for use with the sentences
% environment; they back up over preceding space.  They're designed
% for use just after an \item.

\newcommand{\sentencejudgement}[1]{\strut\llap{#1\hskip 2pt}}
\newcommand{\bad}{\sentencejudgement{$\ast$}}
\newcommand{\quest}{\sentencejudgement{?}}
\newcommand{\qquest}{\sentencejudgement{?\kern -0.5pt?}}

% An abbreviation.

\newcommand{\sentence}[1]{\begin{sentences}\item{#1}\end{sentences}}

% Local references.
%
% \nextsentence           the next sentence
% \nextsentence[2]        the sentence after the next sentence
% \nextsentencesub{1}     the first subsentence of the next sentence
% \nextsentencesub[2]{1}  the first subsentence of the sentence after
%                         the next sentence
%

\newdef\nextsentence{\@ifnextchar[{\@argnextsentence}{\@argnextsentence[1]}%]
}

\newdef\@argnextsentence[#1]{\bgroup
  \advance\c@sentence by #1\relax 
  \thesentence
  \egroup}

\newdef\nextsentencesub{\@ifnextchar[{\@argnextsentencesub
   }{\@argnextsentencesub[1]}%]
}

\newdef\@argnextsentencesub[#1]#2{\bgroup
  \advance\c@sentence by #1\relax
  \c@subsentence=#2\relax
  \thesubsentence
  \egroup}

% Define labeled brackets.  Write ``[\ntype:NP foo bar ...'' to get an
% NP bracket. \ctype is acceptable as an abbreviation.

\newdef\ntype:#1 {{$_{\mbox{\tiny #1}}$} }
\newlet\ctype=\ntype % synonmym

% Common symbols with bars over them.

\newcommand{\Bar}[1]{\ifmmode \overline{\mbox{#1}}\else $\Bar{#1}$\fi}
\newcommand{\Sbar}{\Bar S}
\newcommand{\Nbar}{\Bar N}
\newcommand{\Abar}{\Bar A}
\newcommand{\Xbar}{\Bar X}
\newcommand{\Twobar}[1]{\Bar{\Bar{#1}}}

\newcommand{\thetabar}{\overline\theta}

% More common symbols.

\newcommand{\wh}{{\it wh}}

