fix write 18 skipping in luatex as reported by Bruno
[latex2e.git] / latex2e-20160201 / required / tools / xr.dtx
blobe48c5d3e48382e30d54f68e6a631276a2f583990
1 % \iffalse meta-comment
3 % Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
4 % 2006 2008 2009
5 % The LaTeX3 Project and any individual authors listed elsewhere
6 % in this file.
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'.
22 % \fi
23 % \iffalse
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)]
30 %<*driver>
31 \documentclass{ltxdoc}
32 \usepackage{xr}
33 \GetFileInfo{xr.sty}
34 \begin{document}
35 \title{The \textsf{xr} package\thanks{This file
36         has version number \fileversion, last
37         revised \filedate.}}
38 \author{David Carlisle\thanks{%
39   The Author of Versions 1--4 was Jean-Pierre Drucbert}}
40 \date{\filedate}
41 \MaintainedByLaTeXTeam{tools}
42 \maketitle
43 \DocInput{xr.dtx}
44 \end{document}
45 %</driver>
46 % \fi
48 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 % \CheckSum{87}
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|.
86 % \StopEventually{}
88 % \section{The macros}
90 %    \begin{macrocode}
91 %<*package>
92 %    \end{macrocode}
94 % Check for the optional argument.
95 %    \begin{macrocode}
96 \def\externaldocument{\@ifnextchar[\XR@{\XR@[]}}
97 %    \end{macrocode}
99 % Save the optional prefix. Start processing the first |aux| file.
100 %    \begin{macrocode}
101 \def\XR@[#1]#2{{%
102   \makeatletter
103   \def\XR@prefix{#1}%
104   \XR@next#2.aux\relax\\}}
105 %    \end{macrocode}
107 % Process the next |aux| file in the list and remove it from the head of
108 % the list of files to process.
109 %    \begin{macrocode}
110 \def\XR@next#1\relax#2\\{%
111   \edef\XR@list{#2}%
112   \XR@loop{#1}}
113 %    \end{macrocode}
115 % Check whether the list of |aux| files is empty.
116 %    \begin{macrocode}
117 \def\XR@aux{%
118   \ifx\XR@list\@empty\else\expandafter\XR@explist\fi}
119 %    \end{macrocode}
122 % Expand the list of aux files, and call |\XR@next| to process the first
123 % one.
124 %    \begin{macrocode}
125 \def\XR@explist{\expandafter\XR@next\XR@list\\}
126 %    \end{macrocode}
128 % If the |aux| file exists, loop through line by line, looking for
129 % |\newlabel| and |\@input|. Otherwise process the next file in the
130 % list.
131 %    \begin{macrocode}
132 \def\XR@loop#1{\openin\@inputcheck#1\relax
133   \ifeof\@inputcheck
134     \PackageWarning{xr}{^^JNo file #1^^JLABELS NOT IMPORTED.^^J}%
135     \expandafter\XR@aux
136   \else
137     \PackageInfo{xr}{IMPORTING LABELS FROM #1}%
138     \expandafter\XR@read\fi}
139 %    \end{macrocode}
141 % Read the next line of the aux file.
142 %    \begin{macrocode}
143 \def\XR@read{%
144   \read\@inputcheck to\XR@line
145 %    \end{macrocode}
146 % The |...| make sure that |\XR@test| always has sufficient arguments.
147 %    \begin{macrocode}
148   \expandafter\XR@test\XR@line...\XR@}
149 %    \end{macrocode}
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
155 % file in the list.
156 %    \begin{macrocode}
157 \long\def\XR@test#1#2#3#4\XR@{%
158   \ifx#1\newlabel
159     \newlabel{\XR@prefix#2}{#3}%
160   \else\ifx#1\@input
161      \edef\XR@list{\XR@list#2\relax}%
162   \fi\fi
163   \ifeof\@inputcheck\expandafter\XR@aux
164   \else\expandafter\XR@read\fi}
165 %    \end{macrocode}
167 %    \begin{macrocode}
168 %</package>
169 %    \end{macrocode}
171 % \Finale