% \iffalse meta-comment
%
% Copyright 1993-1995 the LaTeX3 project and any individual authors
% listed elsewhere in this file.  All rights reserved.
% 
% For further copyright information see the file legal.txt, and any
% other copyright notices in this file.
% 
% This file is part of the LaTeX2e system.
% ----------------------------------------
%   This system is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
%   For error reports concerning UNCHANGED versions of this file no more
%   than one year old, see bugs.txt.
% 
%   Please do not request updates from us directly.  Primary
%   distribution is through the CTAN archives.
% 
% 
% IMPORTANT COPYRIGHT NOTICE:
% 
% You are NOT ALLOWED to distribute this file alone.
% 
% You are allowed to distribute this file under the condition that it is
% distributed together with all the files listed in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% Permission is granted to copy this file to another file with a clearly
% different name and to customize the declarations in that copy to serve
% the needs of your installation, provided that you comply with
% the conditions in the file legal.txt.
% 
% However, NO PERMISSION is granted to produce or to distribute a
% modified version of this file under its original name.
%  
% You are NOT ALLOWED to change this file.
% 
% 
% \fi
%
% \iffalse
%%% File: ltxref
%
%<*driver>
% \fi
\ProvidesFile{ltxref.dtx}
             [1995/06/19 v1.1f LaTeX Kernel (Cross Referencing)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltxref.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Rainer Sch\"opf}

\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{84}
%
% \changes{v1.0c}{1994/03/29}
%     {Create file ltcntlen from parts of ltmiscen and ltherest.}
% \changes{v1.1a}{1994/05/19}
%     {Extract file ltxref from ltcntlen.}
% \changes{v1.1b}{1994/05/21}{Use new warning commands}
% \changes{v1.1c}{1994/05/25}{Modify documentation}
%
% \section{Cross Referencing}
%  The user writes  |\label|\marg{foo}  to define the following
%  cross-references:
%
%   |\ref|\marg{foo}: value of most recently incremented referencable
%             counter. in the current environment. (Chapter, section,
%             theorem and enumeration counters counters are
%             referencable, footnote counters are not.)
%
%   |\pageref|\marg{foo}: page number at which |\label{foo}|  command
%             appeared.  where  foo  can be any string of characters not
%             containing  `|\|', `|{|' or `|}|'.
%
%  Note: The scope of the |\label| command is delimited by environments,
%  so\\
%  |\begin{theorem} \label{foo} ... \end{theorem} \label{bar}|\\
%  defines |\ref{foo}| to be the theorem number and |\ref{bar}| to be
%  the current section number.
%
%  Note: |\label| does the right thing in terms of spacing -- i.e.,
%  leaving a space on both sides of it is equivalent to leaving
%  a space on either side.
%
%
% \StopEventually{}
%
% \subsection{Cross Referencing}
%
% \begin{oldcomments}
%    \begin{macrocode}
%<*2ekernel>
\message{x-ref,}
%    \end{macrocode}
%
%  This is implemented as follows.  A referencable counter  CNT  is
%  incremented by the command  \refstepcounter{CNT} , which sets
%  \@currentlabel == {CNT}{eval(\p@cnt\theCNT)}.   The command
%  \label{FOO} then writes the following on file \@auxout :
%        \newlabel{FOO}{{eval(\@currentlabel)}{eval(\thepage)}}
%
%  \ref{FOO} ==
%    BEGIN
%      if \r@foo undefined
%        then  @refundefined := G T
%              ??
%              Warning: 'reference foo on page ... undefined'
%        else  \@car \eval(\r@FOO)\@nil
%      fi
%    END
%
%  \pageref{foo} =
%    BEGIN
%      if \r@foo undefined
%        then  @refundefined := G T
%              ??
%              Warning: 'reference foo on page ... undefined'
%        else  \@cdr \eval(\r@FOO)\@nil
%      fi
%    END
%
%    \begin{macrocode}
\newif\ifG@refundefined
\def\G@refundefinedtrue{\global\let\ifG@refundefined\iftrue}
\def\G@refundefinedfalse{\global\let\ifG@refundefined\iffalse}
%    \end{macrocode}
%
% RmS 91/10/25: added a few extra \reset@font,
%               as suggested by Bernd Raichle
% RmS 92/08/14: made \ref and \pageref robust
% RmS 93/09/08: Added setting of @refundefined switch.
% \end{oldcomments}
%
%  \begin{macro}{\ref}
% \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
%  \begin{macro}{\pageref}
% \changes{LaTeX2e}{1993/12/11}{Macro reimplemented}
%  \begin{macro}{\@setref}
% \changes{LaTeX2e}{1993/12/11}{Macro added}
%    Referencing a |\label|.
%    \begin{macrocode}
\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries ??}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}
\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
                                   \@secondoftwo{#1}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%
%  \begin{macro}{\newlabel}
% \changes{v1.1b}{1994/05/21}{Use new warning commands}
% \changes{v1.1e}{1995/04/24}{Make \cs{@onlypreamble} for /1388.}
% \changes{v1.1e}{1995/06/19}
%      {Use \cs{@newl@bel} to share code with \cs{bibcite}}
%    This command will be written to the \texttt{.aux} file to
%     pass label information from one run to another.
%  \begin{macro}{\@newl@bel}
% The internal form of |\newlabel| and |\bibcite|.
%    \begin{macrocode}
\def\@newl@bel#1#2#3{%
  \@ifundefined{#1@#2}%
    \relax
    {\global\@multiplelabelstrue
     \@latex@warning@no@line{Label `#2' multiply defined}}%
  \global\@namedef{#1@#2}{#3}}
%    \end{macrocode}
%  
%    \begin{macrocode}
\def\newlabel{\@newl@bel r}
%    \end{macrocode}
%  
%    \begin{macrocode}
\@onlypreamble\newlabel
\@onlypreamble\@newl@bel
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\if@multiplelabels}
%    This switch is set true if at least on label is defined more than
%    once. It will be check by the |\enddocument| command.
%    \begin{macrocode}
\newif\if@multiplelabels
%    \end{macrocode}
%  \end{macro}
%
% |\label| and |\refstepcounter| changed to allow |\protect|'ed commands
% to work properly.  For example,
%\begin{verbatim}
%   \def\thechapter{\protect\foo{\arabic{chapter}.\roman{section}}}
%\end{verbatim}
% will cause a |\label{bar}| command to define |\ref{bar}| to expand to
% something like |\foo{4.d}|.  Change made 20 Jul 88.
%
% \changes{v1.1d}{1994/11/04}{Added \cs{protected@write} to
%    \cs{label}.  ASAJ.}
%
%    \begin{macrocode}
\def\label#1{\@bsphack
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
  \@esphack}
%    \end{macrocode}
%
% \changes{v1.1d}{1994/11/04}{Added \cs{protected@edef} to
%    \cs{refstepcounter}.  ASAJ.}
%
%    \begin{macrocode}
\def\refstepcounter#1{\stepcounter{#1}%
    \protected@edef\@currentlabel
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}
%    \end{macrocode}
%
%
% For |\label| commands that come before any environment
%    \begin{macrocode}
\def\@currentlabel{} 
%    \end{macrocode}
%
%    \begin{macrocode}
%</2ekernel>
%    \end{macrocode}
%
% \Finale
%
