%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% typoref.tex. V : January 18, 2000. 
% Author : Anthony PHAN
% Warning : syntaxe +- LaTeX 
% Sources :
% T. Lachand--Robert, ``La Ma\^\i trise de \TeX'',
% R\'ef\'erences crois\'ees;
% latex.ltx's sources;
% and of course the \TeX book.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\catcode`@=11
%
% style (look at the behavior of \item dans \bibitem too,
% and at one ,\  in \re@dreferenceslist)
% Feel free to change: 	\bibn@me (title like ``R\'ef\'erences'')
%			\bibliographym@rk (general style)
%
\def\bibn@me{R\'ef\'erences}
\def\bibliographym@rk{\centerline{{\sc\bibn@me}}
	\sectionmark\section{\ignorespaces}{\unskip\bibn@me}
	\bigbreak\bgroup
	\ifx\ninepoint\undefined\relax\else\ninepoint\fi}
%
% Beware of the \bgroup: it will be closed by \endthebibliography
%
% \refsp@ce is the spacing command that appens between multiple
% references.
%
\let\refsp@ce=\ 
\let\bibleftm@rk=[
\let\bibrightm@rk=]
%
% if you want more space between brackets...
%\let\refsp@ce=\thinspace
%\def\bibleftm@rk{[\thinspace}
%\def\bibrightm@rk{\thinspace]}
%
% frenchy stuff
%
\def\numero{n\raise.82ex\hbox{$\fam0\scriptscriptstyle o$}~\ignorespaces}
%
% new variables
%
\newcount\equationc@unt
\newcount\bibc@unt
\newif\ifref@changes\ref@changesfalse
\newif\ifpageref@changes\ref@changesfalse
\newif\ifbib@changes\bib@changesfalse
\newif\ifref@undefined\ref@undefinedfalse
\newif\ifpageref@undefined\ref@undefinedfalse
\newif\ifbib@undefined\bib@undefinedfalse
\newwrite\@auxout
%
% mark an equation
%
\def\eqnum{\global\advance\equationc@unt by 1%
\edef\lastref{\number\equationc@unt}%
\eqno{(\lastref)}}
%
% One can reference anything, just copy the former macro
% and use it so: \machin \label{truc}
% In machin you would have defined \lastref by some number
% or any text.
%
% References macros
%
% The next macros are the core of \ref and \cite commands.
% Its first argument may be ref, pageref or bib.
%
% It is too tricky to be explained.
% (It is a bit recursive.)
% It allows using \cite or \ref or ...
% with arbitrary many arguments,
% for instance:
% \cite{knuth1,knuth2,ma pomme}
%
% First argument is always ref, pageref or bib.
%
\def\re@dreferences#1#2{{%
	\re@dreferenceslist{#1}#2,\undefined\@@}}
\def\re@dreferenceslist#1#2,#3\@@{\def\next{#2}%
	\expandafter\ifx\csname#1@@\meaning\next\endcsname\relax
	??\immediate\write16
	{Warning, #1-reference "\next" on page \the\pageno\space
	is undefined.}%
	\global\csname#1@undefinedtrue\endcsname
	\else\csname#1@@\meaning\next\endcsname\fi
	\ifx#3\undefined\relax
	\else,\refsp@ce\re@dreferenceslist{#1}#3\@@\fi}
%
% notice that the former ``,\refsp@ce'' will separate
% multiple arguments. But beware of spaces
% while defining a reference or calling for it!
%
% tricky thing: \newlabel has two arguments
% {labelname}{{\lastref}{\pageref}}
% The second argument is read as two arguments
% by \newl@bel. This was necessary to get
% a jobname.aux containing the same syntax
% LaTeX would produce and use.
%
\def\newlabel#1#2{{\def\next{#1}\newl@bel#2}}
\def\newl@bel#1#2{%
	\expandafter\xdef\csname ref@@\meaning\next\endcsname{#1}%
	\expandafter\xdef\csname pageref@@\meaning\next\endcsname{#2}}
\def\label#1{{%
	\toks0={#1}\message{ref(\lastref) \the\toks0,}%
	\ignorespaces\immediate\write\@auxout%
	{\noexpand\newlabel{\the\toks0}{{\lastref}{\the\pageno}}}%
	\def\next{#1}%
	\expandafter\ifx\csname ref@@\meaning\next\endcsname\lastref%
	\else\global\ref@changestrue\fi%
	\newlabel{#1}{{\lastref}{\the\pageno}}}}
\def\ref#1{\re@dreferences{ref}{#1}}
\def\pageref#1{\re@dreferences{pageref}{#1}}
%
% bibliography macros
%
\def\bibcite#1#2{{\def\next{#1}%
	\expandafter\xdef\csname bib@@\meaning\next\endcsname{#2}}}
\def\cite#1{\bibleftm@rk\re@dreferences{bib}{#1}\bibrightm@rk}
%
% The argument of \beginthebibliography
% is any sequence of numerals which will represent
% the maximum \item's length. If you have less than 9
% \bibitem's, this argument may be {any numeral}.
% if you have between 100 and 999 \bibitem's
% this argument may be {any three numerals},
% and so on.
%
\def\beginthebibliography#1{\bibliographym@rk
	\setbox0\hbox{\bibleftm@rk#1\bibrightm@rk\enspace}
	\parindent=\wd0
	\global\bibc@unt=0
	\def\bibitem##1{\global\advance\bibc@unt by 1
		\edef\lastref{\number\bibc@unt}
		{\toks0={##1}
		\message{bib[\lastref] \the\toks0,}%
		\immediate\write\@auxout
		{\noexpand\bibcite{\the\toks0}{\lastref}}}
		\def\next{##1}%
		\expandafter\ifx
		\csname bib@@\meaning\next\endcsname\lastref
		\else\global\bib@changestrue\fi%
		\bibcite{##1}{\lastref}
		\medbreak
		\item{\hfill\bibleftm@rk\lastref\bibrightm@rk}%
		}
	}
\def\endthebibliography{\egroup\par}
%
% THE NEXT MACRO MUST BE INCLUDED
% IN THE \BYE COMMAND. FOR INSTANCE:
%
% \catcode`@=11
% \outer\def\bye{\@closeaux
% 	\par\vfill\supereject\end}
% \catcode`@=12
%
\def\@closeaux{\closeout\@auxout
	\ifref@changes\immediate\write16
	{Warning, changes in references.}\fi
	\ifpageref@changes\immediate\write16
	{Warning, changes in page references.}\fi
	\ifbib@changes\immediate\write16
	{Warning, changes in bibliography.}\fi
	\ifref@undefined\immediate\write16
	{Warning, references undefined.}\fi
	\ifpageref@undefined\immediate\write16
	{Warning, page references undefined.}\fi
	\ifbib@undefined\immediate\write16
	{Warning, citations undefined.}\fi}
%
% initialization of jobname.aux
%
\immediate\openin\@auxout=\jobname.aux
\ifeof\@auxout \immediate\write16
  {Creating file \jobname.aux}
\immediate\closein\@auxout
\immediate\openout\@auxout=\jobname.aux
\immediate\write\@auxout {\relax}%
\immediate\closeout\@auxout
\else\immediate\closein\@auxout\fi
%
% Let's read this file and open it out
%
\input\jobname.aux
\immediate\openout\@auxout=\jobname.aux
% this file will be closed by \bye.
%
% That's all, folks!
%
\catcode`@=12
\endinput




