1 % \iffalse meta-comment
3 % Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
24 %% File: xr.dtx Copyright (C) 1994-1994 David Carlisle
26 %<package>\NeedsTeXFormat{LaTeX2e}
27 %<package>\ProvidesPackage{xr}
28 %<package> [1994/05/28 v5.02 eXternal References (DPC)]
31 \documentclass{ltxdoc}
35 \title{The \textsf{xr} package\thanks{This file
36 has version number \fileversion, last
38 \author{David Carlisle\thanks{%
39 The Author of Versions 1--4 was Jean-Pierre Drucbert}}
41 \MaintainedByLaTeXTeam{tools}
48 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 % \changes{v5.00}{1993/07/07}
53 % {First DPC version (by agreement with J-PD). New mechanism
54 % (\cmd{\read} instead of \cmd\input).}
56 % \changes{v5.01}{1993/07/20}{Fix bug added by DPC, v5.00 did not import
57 % aux files of \cmd\include'ed files. (Reported by J-PD)}
59 % \changes{v5.02}{1994/05/28}{Update for LaTeX2e}
62 % This package implements a system for eXternal References.
64 % If one document needs to refer to sections of another, say |aaa.tex|,
65 % then this package may be loaded in the main file, and the command\\
66 % |\externaldocument{aaa}|\\
67 % given in the preamble.
69 % Then you may use |\ref| and |\pageref| to refer to anything which has
70 % been given a |\label| in either |aaa.tex| or the main document.
71 % You may declare any number of such external documents.
73 % If any of the external documents, or the main document, use the same
74 % |\label| then an error will occur as the label will be multiply
75 % defined. To overcome this problem |\externaldocument| has an optional
76 % argument. If you declare |\externaldocument[A-]{aaa}| Then all
77 % references from |aaa| are prefixed by |A-|. So for instance, if a
78 % section of |aaa| had |\label{intro}|, then this could be referenced
79 % with |\ref{A-intro}|. The prefix need not be |A-|, it can be any
80 % string chosen to ensure that all the labels imported from external
81 % files are unique. Note however that if your style declares certain
82 % active characters (|:| in French, |"| in German) then these
83 % characters can not usually be used in |\label|, and similarly may not
84 % be used in the optional argument to |\externaldocument|.
88 % \section{The macros}
94 % Check for the optional argument.
96 \def\externaldocument{\@ifnextchar[\XR@{\XR@[]}}
99 % Save the optional prefix. Start processing the first |aux| file.
104 \XR@next#2.aux\relax\\}}
107 % Process the next |aux| file in the list and remove it from the head of
108 % the list of files to process.
110 \def\XR@next#1\relax#2\\{%
115 % Check whether the list of |aux| files is empty.
118 \ifx\XR@list\@empty\else\expandafter\XR@explist\fi}
122 % Expand the list of aux files, and call |\XR@next| to process the first
125 \def\XR@explist{\expandafter\XR@next\XR@list\\}
128 % If the |aux| file exists, loop through line by line, looking for
129 % |\newlabel| and |\@input|. Otherwise process the next file in the
132 \def\XR@loop#1{\openin\@inputcheck#1\relax
134 \PackageWarning{xr}{^^JNo file #1^^JLABELS NOT IMPORTED.^^J}%
137 \PackageInfo{xr}{IMPORTING LABELS FROM #1}%
138 \expandafter\XR@read\fi}
141 % Read the next line of the aux file.
144 \read\@inputcheck to\XR@line
146 % The |...| make sure that |\XR@test| always has sufficient arguments.
148 \expandafter\XR@test\XR@line...\XR@}
151 % Look at the first token of the line.
152 % If it is |\newlabel|, do the |\newlabel|. If it is |\@input|, add the
153 % filename to the list of files to process. Otherwise ignore.
154 % Go around the loop if not at end of file. Finally process the next
157 \long\def\XR@test#1#2#3#4\XR@{%
159 \newlabel{\XR@prefix#2}{#3}%
161 \edef\XR@list{\XR@list#2\relax}%
163 \ifeof\@inputcheck\expandafter\XR@aux
164 \else\expandafter\XR@read\fi}