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 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 % \changes{v5.00}{1993/07/07}
52 % {First DPC version (by agreement with J-PD). New mechanism
53 % (\cmd{\read} instead of \cmd\input).}
55 % \changes{v5.01}{1993/07/20}{Fix bug added by DPC, v5.00 did not import
56 % aux files of \cmd\include'ed files. (Reported by J-PD)}
58 % \changes{v5.02}{1994/05/28}{Update for LaTeX2e}
61 % This package implements a system for eXternal References.
63 % If one document needs to refer to sections of another, say |aaa.tex|,
64 % then this package may be loaded in the main file, and the command\\
65 % |\externaldocument{aaa}|\\
66 % given in the preamble.
68 % Then you may use |\ref| and |\pageref| to refer to anything which has
69 % been given a |\label| in either |aaa.tex| or the main document.
70 % You may declare any number of such external documents.
72 % If any of the external documents, or the main document, use the same
73 % |\label| then an error will occur as the label will be multiply
74 % defined. To overcome this problem |\externaldocument| has an optional
75 % argument. If you declare |\externaldocument[A-]{aaa}| Then all
76 % references from |aaa| are prefixed by |A-|. So for instance, if a
77 % section of |aaa| had |\label{intro}|, then this could be referenced
78 % with |\ref{A-intro}|. The prefix need not be |A-|, it can be any
79 % string chosen to ensure that all the labels imported from external
80 % files are unique. Note however that if your style declares certain
81 % active characters (|:| in French, |"| in German) then these
82 % characters can not usually be used in |\label|, and similarly may not
83 % be used in the optional argument to |\externaldocument|.
87 % \section{The macros}
93 % Check for the optional argument.
95 \def\externaldocument{\@ifnextchar[\XR@{\XR@[]}}
98 % Save the optional prefix. Start processing the first |aux| file.
103 \XR@next#2.aux\relax\\}}
106 % Process the next |aux| file in the list and remove it from the head of
107 % the list of files to process.
109 \def\XR@next#1\relax#2\\{%
114 % Check whether the list of |aux| files is empty.
117 \ifx\XR@list\@empty\else\expandafter\XR@explist\fi}
121 % Expand the list of aux files, and call |\XR@next| to process the first
124 \def\XR@explist{\expandafter\XR@next\XR@list\\}
127 % If the |aux| file exists, loop through line by line, looking for
128 % |\newlabel| and |\@input|. Otherwise process the next file in the
131 \def\XR@loop#1{\openin\@inputcheck#1\relax
133 \PackageWarning{xr}{^^JNo file #1^^JLABELS NOT IMPORTED.^^J}%
136 \PackageInfo{xr}{IMPORTING LABELS FROM #1}%
137 \expandafter\XR@read\fi}
140 % Read the next line of the aux file.
143 \read\@inputcheck to\XR@line
145 % The |...| make sure that |\XR@test| always has sufficient arguments.
147 \expandafter\XR@test\XR@line...\XR@}
150 % Look at the first token of the line.
151 % If it is |\newlabel|, do the |\newlabel|. If it is |\@input|, add the
152 % filename to the list of files to process. Otherwise ignore.
153 % Go around the loop if not at end of file. Finally process the next
156 \long\def\XR@test#1#2#3#4\XR@{%
158 \newlabel{\XR@prefix#2}{#3}%
160 \edef\XR@list{\XR@list#2\relax}%
162 \ifeof\@inputcheck\expandafter\XR@aux
163 \else\expandafter\XR@read\fi}