Chapter 4
Cross References

   4.1 The Commands
      Ref
      LikeRef
      Tag
   4.2 Internal References
      Loading
   4.3 External References
      Scanning the Preamble
      Incorporating the Preamble
   4.4 Interpretation for Entries
   4.5 Link
   4.6 Utilities
      Empty Anchors
      Latex Anomalies
      Other

Should be consistent with the corresponding features in ProTeX.

<..cross references..>
 <.common cross references.>
 \ifHtml  <.html cross references.>
 \fi
 -_-_-

4.1 The Commands

Ref

The implementations of \Ref and \Tag view the crosswords α as pointers to macros that carry the names ‘\cw:α’.

<..common cross references..>
 \def\Ref#1{\expandafter\ifx
                  \csname <.tag of Tag.>#1\endcsname \relax \:NoTag{#1}%
            \else \csname <.tag of Tag.>#1\endcsname    \fi}
 -_-_-

<..general utilities..>+
 \def\ifTag#1#2#3{\expandafter\ifx
    \csname <.tag of Tag.>#1\endcsname \relax #3\else #2\fi}
 -_-_-

LikeRef

The \:LikeRef command is a stripped down version of \Ref; it doesn’t check whether the tag is defined.

The space in \space is needed for carrying MAME tags in (mosaic) html files.

<..common cross references..>+
 \def\LikeRef#1{\expandafter\ifx
                  \csname <.tag of Tag.>#1\endcsname \relax \space%
           \else  \csname <.tag of Tag.>#1\endcsname    \fi}
 \def\:LikeRef#1{\csname  <.tag of Tag.>#1\endcsname}
 -_-_-

Read file from previous compilation.

Tag

A command \Tag{α}{β} introduces into the reference file a record of the form \:CrossWord{α}{ˆβ }{i}.

<..common cross references..>+
 \let\:SUPOff=\empty \let\:SUBOff=\empty
 \def\Tag#1#2{\begingroup   \:SUPOff  \:SUBOff \a:xref \escapechar=‘\\%
    \edef\:head{\string\:CrossWord{#1}{#2}}%
    \expandafter \expandafter \expandafter
    \:writeref\expandafter{\:head{\folio}\prcnt:ch}%
 \endgroup}
 \NewConfigure{xref}{1}
 -_-_-

The \:SUBSUPOff will be redefined latter with subscripts and superscripts. The current definition is sufficient for the tags that in the meantime are created by the system.

<..common cross references..>+
 \def\:writeref{\write\:refout}%
 -_-_-

<..general utilities..>+
 \catcode‘\%=12 \def\prcnt:ch{%} \catcode‘\%=14
 -_-_-

<..html utilities..>+
 \catcode‘\%=12 \def\%{%} \catcode‘\%=14
 -_-_-

4.2 Internal References

Loading

<..common cross references..>+
 \def\load:ref#1{%
    <.set catcodes for info in ref file.>%
    \get:input{#1}%
    \re:call   \let\:CrossWord=\sv:crs  }
 <.interpretation for entries in ref file.>
 \ifx \:refout\:UnDef
    <.check the existence of jobname.xref.>
    \load:ref{\jobname.xref}
    \csname newwrite\endcsname\:refout
    <.if latex then latex/write sol.>\openout\:refout=\jobname.xref
 \fi
 -_-_-

<..check the existence of jobname.xref..>
 \openin15=\jobname.xref
 \ifeof15  \def\:NoTag#1{\hbox{$???$}}
 \else     \def\:NoTag#1{\hbox{$???$}
               \:warning{\string\Ref\string{\string#1\string}?}}
   <.warnings for missing /Link.>
 \fi
 \closein15
 -_-_-

<..set catcodes for info in ref file..>
 \edef\re:call{\catcode‘\noexpand\:=\the\catcode‘\: }%
 \catcode‘\:=11
 \let\sv:crs=\:CrossWord
 \def\:CrossWord{\bgroup
    \no:catcodes{128}{255}{12}%
    \catcode‘\:=12  \catcode‘\@=11
    \catcode‘\^^M=11    \:CrsWrd}%
 \def\:CrsWrd##1##2##3{\egroup \sv:crs{##1}{##2}{##3}}%
 -_-_-

Aborted compilations tend to leave incimplete :CrossWord commands in the xref file, missing the last page-number parameter. The \catcode‘\^^M=11 allows such commands to be loaded without terminating the compilation.

4.3 External References

References to information in other files can be achieved with the following file-loading command \LoadRef-[prefix]+{filename.ext}{...}.

The .ext, +, -, and [...] components are optional. A missing .ext stands for .xref. When -[prefix]+ is empty the component {...} should also be omitted (and the comamnd assume the form \LoadRef{filename.ext}).

A + asks that \Ref and LikeRef commands will refer to expanded tags of the form filename::tag instead of just tag. A [prefix] asks that only tags which start with the given prefix will be loaded. When [prefix] is omitted, an empty prefix is assumed and all the tags are loaded. A - asks that \Ref and LikeRef commands will refer to truncated tags in which the specified prefixes are omitted.

Intuitively, a tag can be viewed as a triplet <from>:<to><tag> which encodes information together with source and destination addresses. The {...} specifies how the information should be included, where #1 represents the information being loaded.

Scanning the Preamble

<..common cross references..>+
 \def\LoadRef{\futurelet<.-?.>\:LoadRef}
 \def\:LoadRef{{%
    \if \bgroup<.-?.>
       \aftergroup\loadr:ef
    \else
       \aftergroup\Load:Ref    \if -<.-?.> \else
                                   \aftergroup-\fi
    \fi
 }}
 \def\Load:Ref#1{\futurelet<.[?.>\LoadRef:}
 \def\LoadRef:{{%
    \aftergroup\:loadref    \ifx [<.[?.> \else
                               \aftergroup[\aftergroup]\fi}}
 -_-_-

<..common cross references..>+
 \def\:loadref[#1]{%
    \let\sv:cros=\:CrossWord
    \edef<.prefix.>{#1}\ifx <.prefix.>\empty \let<.[?.>= N\fi
    \futurelet<.+?.>\l:oadref }
 \def\l:oadref{%
    {\aftergroup\lo:adref \if +<.+?.> \else \aftergroup+\fi  }}
 \def\lo:adref#1#2#3{%
    \def\cw:format##1{#3}%
    \edef\:temp{#2}\expandafter \get:ext\:temp .<.par del.>%
    \ifx \:temp\empty
          \set:CrossWord#2.<.par del.>{<.prefix.>}\load:ref{#2.xref}%
    \else \set:CrossWord#2<.par del.>{<.prefix.>}\load:ref{#2}\fi
    \let\:CrossWord=\sv:cros }
 \def\get:ext#1.#2<.par del.>{\def\:temp{#2}}
 \def\loadr:ef#1{\let<.+?.>=x \let<.prefix.>=\empty \lo:adref{}{#1}{##1}}
 -_-_-

<..cs?..>
 \:tempa-_-_-

<..-?..>
 \:tempa-_-_-

<..[?..>
 \:tempb-_-_-

<..+?..>
 \:tempc-_-_-

<..prefix..>
 \:tempd-_-_-

Incorporating the Preamble

<..common cross references..>+
 \def\set:CrossWord#1<.par del.>#2{%
    \edef\:temp{\noexpand\:setCrossWord#1<.par del.>{#2}}\:temp}
 \def\:setCrossWord<.ref filename par.>.#2<.par del.><.substr par.>{%
    \ifx [<.[?.>
       \def\:CrossWord##1##2##3{%
          \cond:CrossWord##1<.substr par.><.par del.>{##1}{##2}{##3}}%
       \def\:tail<.substr par.>##1<.substr par.>{##1}%
       \if +<.+?.>   <.:CrossWord := extend selected words.>%
       \else         <.:CrossWord := selected words.>\fi
    \else
       \if +<.+?.>   <.:CrossWord := extend all words.>\fi
    \fi              else :CrossWord := all words
 }
 -_-_-

<..:CrossWord := extend all words..>
 \def\:CrossWord{\Cross:Word{<.ref filename par.>::}}%
 -_-_-

<..:CrossWord := extend selected words..>
 \if -<.-?.>
    \def\cond:CrossWord##1<.substr par.>##2<.par del.>##3##4##5{%
       \def\:temp{##1}\ifx \:temp\empty
          \Cross:Word{<.ref filename par.>::}%
                     {\:tail##3<.substr par.>}{##4}{##5}\fi   }%
 \else
    \def\cond:CrossWord##1<.substr par.>##2<.par del.>##3##4##5{%
       \def\:temp{##1}\ifx \:temp\empty
          \Cross:Word{<.ref filename par.>::}{##3}{##4}{##5}\fi   }%
 \fi
 -_-_-

<..:CrossWord := selected words..>
 \if -<.-?.>
    \def\cond:CrossWord##1<.substr par.>##2<.par del.>##3##4##5{%
       \def\:temp{##1}\ifx \:temp\empty
          \Cross:Word{}{\:tail##3<.substr par.>}{##4}{##5}\fi  }%
 \else
    \def\cond:CrossWord##1<.substr par.>##2<.par del.>##3##4##5{%
       \def\:temp{##1}\ifx \:temp\empty
          \Cross:Word{}{##3}{##4}{##5}\fi  }%
 \fi
 -_-_-

4.4 Interpretation for Entries

For each crossword α the imported file contains a record of the form \:CrossWord{α}{ˆβ }{i}. In such a record, βˆ and i stand for the expanded token list and HPage number that correspond to α, respectively.

A command \:CrossWord{α}{ˆβ }{i} introduces the macro \def\cw:α{ˆβ }, if the label is not empty. Otherwise, it introduces the macro \def\cw:α{i} that holds the page number.

<..interpretation for entries in ref file..>
 \def\:CrossWord#1#2#3{\Cross:Word{}{#1}{#2}{#3}}
 \def\Cross:Word#1#2#3#4{%
    \def\:temp{#3}\tmp:toks{#3}%
    \expandafter\edef\csname <.tag of Tag.>\cw:format{#1#2}\endcsname{%
       \expandafter\ifx\csname <.tag of Tag.>\cw:format{#1#2}\endcsname\relax
       \else \csname <.tag of Tag.>\cw:format{#1#2}\endcsname ,  \fi
       \ifx \:temp\empty #4\else  \the\tmp:toks\fi}}
 \def\cw:format#1{#1}%
 -_-_-

<..par del..>
 !*?: -_-_-

<..substr par..>
 #3-_-_-

<..ref filename par..>
 #1-_-_-

4.5 Link

Good for \Link{...}{...} across files when we have \LoadRef+{...}{#1}.

<..html cross references..>
 \catcode‘\:=12
 
 \def\get@hfile#1{\get@hfil@ #1:::://}
 
 \def\get@hfil@#1::#2::#3//{%
    \expandafter\ifx \csname
       <.tag of Tag.>#1::<.HTag tag.>#2\endcsname \relax \else
       \expandafter\expandafter\expandafter\get@@hfile
           \csname <.tag of Tag.>#1::<.HTag tag.>#2\endcsname,//{#1}%
    \fi}
 \def\get@@hfile#1,#2//#3{%
     \expandafter\ifx
        \csname <.tag of Tag.>#3::<.auto file tag.>#1%
                <.Tag/Ref: file-id -> file-name.>\endcsname \relax
     \else
        \csname <.tag of Tag.>#3::<.auto file tag.>#1%
                <.Tag/Ref: file-id -> file-name.>\endcsname
        \expandafter  \expandafter  \expandafter  \expandafter
        \expandafter  \expandafter  \expandafter  \remove@fn
     \fi }
 
 \def\remove@fn#1#2::{#1}
 
 \catcode‘\:=11
 -_-_-

4.6 Utilities

Empty Anchors

Change the following to standard space character when microsoft explorer will let it. Currently it wiil go only for ubreakable space. The last null anchor is obviously the most desirable one.

<..html utilities..>+
 \def\hidden:anchor{}
 -_-_-

Latex Anomalies

<..if latex then latex/write sol..>
 \if:latex \expandafter\immediate\fi
 -_-_-

Try to understand betetr what goes here, because I got the following not workin in latex. It pushed the output to the log file instead of the toc file.

\<latex/write sol\><<< 
\immediate 
>>> 

Inserted for the differences in the output routines between TeX and LaTeX.

 -------ok----------------faulty------------------ok----------------- 
|                 |                      |                           | 
|                 | \documentstyle{book} | \documentstyle{book}      | 
|                 | \begin{document}     | \begin{document}          | 
| \newwrite\y     | \newwrite\y          | \newwrite\y               | 
| \openout\y=f.xx | \openout\y=f.xx      | \immediate\openout\y=f.xx | 
| \write\y{....}  | \write\y{....}       | \immediate\write\y{....}  | 
| \closeout\y     | \closeout\y          | \immediate\closeout\y     | 
| \end            | \end{document}       | \end{document}            | 
 -------------------------------------------------------------------- 

LaTEXhas a \clearpage and \cleardoublepage.

<..latex /special sol..>
 \ifx \clearpage\:UnDef  \def\:clearpage{\vfil\penalty-20000}
 \else
   \let\real:par=\par  \def\eq:par{\par\real:par}
   \def\:clearpage{\expandafter\ifx\eq:par\clearpage\fi}
 \fi
 -_-_-

In LaTeX, \clearpage embeds a \newpage, which in turns embeds a \par. The \EndPage, in turn, embeddes a \:clearpage which may cause a problem in places that \par might be a problem. Such is the case, for instance, within \halign, where \par has a different meaning and may cause an infinite loop. The \footnote produces this bad situation.

<..general utilities..>+
 <.latex /special sol.>
 -_-_-

 ---------ok------------------faulty--------------------ok----------- 
|                      |                      |                      | 
|                      | \documentstyle{book} | \documentstyle{book} | 
|                      | \begin{document}     | \begin{document}     | 
| aaaaa                | aaaaa                | aaaaa                | 
| \special{t4ht>bbbbb} | \special{t4ht>bbbbb} | \special{t4ht>bbbbb} | 
| ccccc                | ccccc                | ccccc                | 
| \vfil\penalty-20000  | \vfil\penalty-20000  | \vfil\penalty-10000  | 
| ddddd                | ddddd                | ddddd                | 
| \end                 | \end{document}       | \end{document}       | 
|                      |                      |                      | 
 -------------------------------------------------------------------- 
 --------------------ok-------------------------------faulty------------------ 
|                                      |\documentstyle{book}                  | 
|                                      |\begin{document}                      | 
|\leavevmode x\vfil   \penalty-10000   |\leavevmode x\vfil   \penalty-10000   | 
|\leavevmode y\mark{\gdef\noexpand\z{}}|\leavevmode y\mark{\gdef\noexpand\z{}}| 
|\end                                  |\end{document}                        | 
 ----------------------------------------------------------------------------- 
 
 -------------ok-----------------------faulty-------------- 
|                            |  \documentstyle{book}       | 
|                            |  \begin{document}           | 
| y                          |  y                          | 
| \mark{\gdef\noexpand\zz{}} |  \mark{\gdef\noexpand\zz{}} | 
| \end                       |  \end{document}             | 
 ---------------------------------------------------------- 

Other

<..general utilities..>+
 \ifx \folio\:UnDef
    \def\folio{\ifx \pageno\:UnDef \z@ \else
       \ifnum \pageno <0 \romannumeral -\pageno
       \else             \the           \pageno \fi\fi}
 \fi
 -_-_-