Chapter 7
Coauthoring

   7.1 The Commands
      Links
   7.2 Values in Variables
      Overide Previous Files
      Contain Changes
      Cross-Reference Screening
   7.3 Tables of Content
   7.4 Load File and Link Xref of Relative
      Local Utilities

<..imports..>
 <.import-export interface.>
 \:CheckOption{family} \if:Option
    <.import-export commands.>
    <.imports utilities.>
 \else
    <.no import-export.>
 \fi
 -_-_-

<..general utilities..>+
 \def\BI:gbl{\ifx [\:temp \expandafter\bi:gbl\else
                         \expand:after{\bi:gbl[]}\fi}
 \def\bi:gbl[#1]#2{}
 -_-_-

<..html utilities..>+
 \def\ro:nd#1#2{%
    \gHAdvance#1 by #2
    \gHDivide#1 by #2
    \gHMultiply#1 by #2 }
 -_-_-

7.1 The Commands

The extension for the name should refer to the xref file, and if omitted an .xref is aasumed.

<..import-export interface..>
 \def\ParentOf{\gHAdvance\TitleCount  1
    \global\let\mu:span=\TitleCount \futurelet\:temp\:mprt}
 -_-_-

<..no import-export..>
 \let\:mprt=\BI:gbl
 -_-_-

<..import-export commands..>
 \def\:mprt{\fm:call\:Imprt}
 
 \def\:Imprt[#1]#2#3{%
    \def\:temp{#2}\ifx \:temp\Jobname
                     \:warning{#2 \string\ParentOf\space#2?}\fi
    \Needs-{child ‘#2’}%
    \LoadRef[<.screen ref from child @2.>]{#3}{##1}%
    \imp:var{#2}fstf:id,#1<.par del.>%
    <.send links from parent to child.>%
    \the\:tokwrite{\string\doTocEntry
                           \string\tocParentOf{#2}{}{}\relax}}
 
 \HAssign\fstf:id=0
 -_-_-

<..import-export interface..>+
 \def\ChildOf{\futurelet\:temp\:xprt}
 -_-_-

<..no import-export..>+
 \Odef\ChildOf[#1]#2{\:warning{\string\ChildOf{#2}
    without \string\Preamble{...,family,...}}}
 \let\:xprt=\BI:gbl
 -_-_-

<..import-export commands..>+
 \def\:xprt{\fm:call\:Exprt}
 
 \def\:Exprt[#1]#2#3{%
    \ifnum \maxfile:id>1
        \:warning{\string\ChildOf{#2} not at root file}\fi
    \Needs-{parent ‘#2’}%
    \ld:flxrf{#3}{<.toc tag.>}%
    \LoadRef[<.screen ref from parent @2.>]{#3}{##1}%
    \xp:var{#2}fstf:id,#1<.par del.>%
    <.adjust file ids info up.>%
    \def\export:hook{\exprt:tag{#2}fstf:id,#1<.par del.>}%
    <.send links from child to parent.>%
    \gdef\:Export[##1]##2{\:warning{\string\ChildOf
                \string{##2\string}\space ignored (not 1st)}}%
 }
 -_-_-

<..import-export commands..>+
 \def\rmv:ext#1.#2<.par del.>{#1}
 
 \def\fm:call#1{\ifx [\:temp \expand:after{\fm:cll#1}\else
                             \expand:after{\fm:cll#1[]}\fi}
 \def\fm:cll#1[#2]#3{\edef\:temp{\noexpand\noexpand\noexpand
    #1[#2]{\noexpand\rmv:ext#3.<.par del.>}{#3}}%
    \edef\:temp{\:temp}\:temp}
 -_-_-

Links

<..send links from parent to child..>
 \Tag{<.screen tag to child @2.>-up}{\RefFileNumber\FileNumber}%
 \Tag{<.screen tag to child @2.>-prev}{\childFile}%
 \xdef\childFile{\LikeRef{<.screen ref from child @2.>-down}}%
 \ifx \cld:n\:UnDef  \else  \Tag{\cld:n}{\childFile}\fi
 \xdef\cld:n{<.screen tag to child @2.>-next}%
 -_-_-

<..send links from child to parent..>
 \Tag{<.screen tag to parent @2.>-down}{\RefFileNumber\FileNumber}%
 \ch:lnk\parentFile{#2}{up}%
 \ch:lnk\prevChildFile{#2}{prev}%
 \ch:lnk\nextChildFile{#2}{next}%
 \global\let\nsrt:chlnks=\nsrt:cldnks
 \nsrt:chlnks{<.front.>}{<.tail.>}{FrontChild}%
 -_-_-

We need in \childFile initially a space and not empty, because otherwise Ref will produce the page number.

<..import-export commands..>+
 \let\childFile=\space
 \def\ch:lnk#1#2#3{%
    \xdef#1{\LikeRef{<.screen ref from parent @2.>-#3}}%
    \ifx #1\space \let#1=\empty\fi}
 -_-_-

Note that the following might be a problem for when HPage is nested in regular file.

<..import-export commands..>+
 \def\nsrt:cldnks#1#2#3{{%
    \let\prevCutAt=\prevChildFile
    \let\nextCutAt=\nextChildFile
    \def\ExitHPage##1{\Link[\parentFile]{}{}##1\EndLink}
    \:hookI{#3}{\default:bts{#1}{#2}}{}}}
 -_-_-

<..buttons at end of child..>
 \root:next
 \ifx \nsrt:chlnks\:UnDef
 \else \nsrt:chlnks{<.tail.>}{<.front.>}{BackChild}\fi
 -_-_-

7.2 Values in Variables

<..import-export commands..>+
 \def\imp:var#1#2,#3<.par del.>{%
    \gt:ops{#2}%
    \Tag{<.screen tag to child @1.>-#2}{<.the.>\csname #2\endcsname}%
    \edef<.temp.>{0\LikeRef{<.screen ref from child @1.>-#2}}%
    \expand:after{\expandafter<.advance.>\csname
                                        #2\endcsname by }<.temp.>%
    \if:notempty{#3}{\imp:var{#1}#3,<.par del.>}}
 -_-_-

A child transfers up the changes made to a counter, not an absolute value. The entry value is recorded in \csname :#2:\endcsname.

<..import-export commands..>+
 \def\xp:var#1#2,#3<.par del.>{%
    \gt:ops{#2}%
    \edef<.temp.>{0\LikeRef{<.screen ref from parent @1.>-#2}}%
    \expandafter<.assign.>\csname #2\endcsname=<.temp.>
    \expandafter\HAssign\csname :#2:\endcsname=<.temp.>
    \if:notempty{#3}{\xp:var{#1}#3,<.par del.>}}
 -_-_-

<..import-export commands..>+
 \def\exprt:tag#1#2,#3<.par del.>{%
    \tmp:cnt = \csname #2\endcsname
    \advance\tmp:cnt by -\csname :#2:\endcsname
    \Tag{<.screen tag to parent @1.>-#2}{\the\tmp:cnt}%
    \if:notempty{#3}{\exprt:tag{#1}#3,<.par del.>}}
 -_-_-

Overide Previous Files

The \:clearpage is needed below to clear the old tags and xref files, before new ones start to come. The \Tag few lines below can be lost.

<..adjust file ids info up..>
 \closeout\:refout
 \openout\:refout=\jobname.xref     \:clearpage
 <.fix point for file ids at child.>%
 \gHAssign\maxfile:id = \fstf:id
 \gHAssign\bs:fileid = \maxfile:id
 \global\let\file:id=\maxfile:id
 \Tag{<.auto file tag.>\file:id <.Tag/Ref: file-id -> file-name.>}%
                                                 {\jobname.\:html}%
 \expandafter\xdef\csname
    <.csname: file name -> file id.>\jobname.\:html\endcsname{\file:id}%
 \xdef:cs{<.live.>\file:id}{}%
 -_-_-

<..file not overided by /ChildOf..>
 \csname  FN #1\endcsname > \bs:fileid
 -_-_-

Contain Changes

We want to reduce the number of compilations due to changes. We can’t do much with sectioning numbers, but we can do quite a lot with labels of links. Note that the addresses are made up of file numbers + label numbers.

We make the children ‘fix-points’ with respect to file numbers, by allocating them addresses that are equal to ‘child-id * 10000’. We make here an assumption that a compilation will not generate more than 9999 files.

<..fix point for file ids at child..>
 \gHAdvance\fstf:id by 10000
 -_-_-

It would be nice to have also fix-points for file ids within children, but this will cause holes. The holes will result in fake names \csname filei-d\endcsname which unneccesariliy consume ids and can overflow the memory quite quickly. This names are inspected at points that files are closed, and checking is performed for opened subfiles.

We can also ask that large files will provide fixed-points. We do so with the following command, which so far is used only at cut points. It requests distinguished automatically generated file names for the class that is identified by the two leading characters of the given parameter (i.e., sectioning type in case of the cut points). These are really not fixed point, because they don’t fix unique file names (e.g., by rounding up file ids).

<..large file name for @2..>
 \fx:pt #1xxx<.par del.>%
 -_-_-

Do we want \ro:nd\html:lbl{100000}% below?

<..html utilities..>+
 \def\fx:pt#1#2#3<.par del.>{%
    \expandafter\ifx \csname big:#1:#2\endcsname\relax
          \expandafter\gHAssign\csname big:#1:#2\endcsname = 0  \fi
    \expandafter\gHAdvance\csname big:#1:#2\endcsname by 1
    \edef\big:fn{#1#2\csname big:#1:#2\endcsname}}
 -_-_-

On the other hands, we try to make sectioning commands fixed points for labels. Hence, we try to reduce sensitivity of tocs to changes. See \<round ids between sections\>

The validity of the above fixed points carries on as far as the specified points are really fixed. If they become fluid, then everything becomes fluid.

To get evrything working, we need 4 compilations (in modifications less might be sufficient).

  1. A compilation to create the starting file number for each node (child/ parent). That is, fix file numbers for children.

  2. A compilation for using the right file numbers, and to create the correct tags within the tocs. That is, to collect moveable information like tables of contents and relationships between files.

  3. A compilation to use the right tags, and to create the right xref for the tags in the tocs That is, to collect cross-references from moveable info.

  4. A compilation to incorporate the cross refs

Cross-Reference Screening

\Jobname has been introduced for \LoadRef[..]

<..screen ref from child @2..>
 #2-\Jobname-_-_-

<..screen ref from child @1..>
 #1-\Jobname-_-_-

<..screen ref from parent @2..>
 #2-\Jobname-_-_-

<..screen ref from parent @1..>
 #1-\Jobname-_-_-

<..screen tag to child @1..>
 \Jobname-#1-_-_-

<..screen tag to child @2..>
 \Jobname-#2-_-_-

<..screen tag to parent @1..>
 \Jobname-#1-_-_-

<..screen tag to parent @2..>
 \Jobname-#2-_-_-

7.3 Tables of Content

The are needed because some variables are of TeX and others are of TeX4ht.

<..imports..>+
 \def\tocParentOf#1{{%
    \def\:temp{#1}\ifx \:temp\Jobname
       \:warning{#1 \string\ParentOf\space#1?}
    \else  \expand:after{\ld:flxrf{#1}{<.toc tag.>}\get:input{#1.4tc}}\fi}}
 -_-_-

7.4 Load File and Link Xref of Relative

<..imports..>+
 \def\ld:flxrf#1#2{%
    \let\:CrsWd=\Cross:Word
    \def\Cross:Word##1##2{%
       \expandafter\let\csname <.tag of Tag.>##2\endcsname=\:UnDef
       \:CrsWd{##1}{##2}}%
    \LoadRef[<.auto file tag.>]{#1}{##1}%
    \LoadRef[<.HTag tag.>#2]{#1}{##1}%
    \let\Cross:Word=\:CrsWd
 }
 -_-_-

Local Utilities

The following are needed because some variables are of TeX and others are of TeX4ht.

<..imports utilities..>
 \def\gt:vi#1#2#3#4#5#6#7<.par del.>{#1#2#3#4#5#6}
 \def\gt:vr#1#2{\edef#1{\expandafter
    \gt:vi\meaning#2 .......<.par del.>}}
 \gt:vr\c:unt\tmp:cnt
 \def\chk:vr#1#2{\expand:after{\gt:vr\:temp#2 #1\:temp\c:unt}}
 
 \def\gt:ops#1{%
    \expand:after{\chk:vr\ifx}\csname#1\endcsname  \let<.the.>=\the
             \let<.assign.>=\empty   \let<.advance.>=\advance
   \else                             \let<.the.>=\empty
             \let<.assign.>=\HAssign  \let<.advance.>=\Advance:
   \fi }
 -_-_-

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

<..advance..>
 \:tempb-_-_-

<..temp..>
 \:tempc-_-_-

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