Here are a number of repaired functions (and one repaired variable)
which together fix the problem of footnote references getting out
of step between phases resulting in bogus results from \somewhere.

The repairs were made in ConTeXt 2007-01-12.  Each repaired function
is preceded by a comment explaining the reason for the repair.

The repaired functions are followed by a test which generates three
pages of output covering many test cases.

Additionally, I have tested these repairs on a 50 page document with
185 footnotes.  All of the \somewhere's were fixed by these repairs.

The only downside that I have noticed is that two column footnotes
are now less well balanced.  If anyone has any thoughts as to why
this might be happening or how to fix it please let me know.  I'm
just a few days from deadline!

Thanks,

--Mike Bird
\unprotect

% \footnotereferenceto in core-not.tex
% Remove the decrement which hides the problem within a page but breaks
% references in subsequent pages.

\def\footnotereferenceto
  {%\global\advance\crossreferencenumber\minusone\relax % else problem, needs further testing
   \rawreference\s!fnt{\s!fnt:t:\internalfootreference}{}}

% \dostartnote in core-note.tex
% The first thing after \startpushnote is expanded twice, which is not
% good when it generates two calls to \footnotereferenceto.

\def\dostartnote% nog gobble als in pagebody
  {\bgroup
   \settrue\processingnote
  %\restorecatcodes % to be tested first
   \iftypesettinglines % otherwise problems with \type <crlf> {xxx}
     \ignorelines % makes footnotes work in \startlines ... \stoplines
   \fi
   \ifnotesymbol
     \dolastnotesymbol
   \else
     \unskip\unskip
     \globallet\lastnotesymbol\dolastnotesymbol
   \fi
   \startlocalnoteinsert
     \doif{\noteparameter\c!scope}\v!page{\floatingpenalty\maxdimen}% experiment     \penalty\notepenalty
     \forgetall
     \setnotebodyfont
     \redoconvertfont % to undo \undo calls in in headings etc
     \splittopskip\strutht  % not actually needed here
     \splitmaxdepth\strutdp % not actually needed here
     \leftmargindistance\noteparameter\c!margindistance
     \rightmargindistance\leftmargindistance
     \ifnum\noteparameter\c!n=\zerocount % no ifcase new 31-07-99 ; always ?
       \doifnotinset{\noteparameter\c!width}{\v!fit,\v!broad}\setnotehsize
     \fi
     \startpushnote
       {\ifx\lastnotenumber\empty \else
          \preparefullnumber{\??vn\currentnote}\lastnotenumber\preparednumber
          \doifelse{\noteparameter\c!interaction}\v!no
            {\noteparameter\c!numbercommand
               {\preparednumber\domovednote\v!nextpage\v!previouspage}}%
            {\gotobox{\noteparameter\c!command % was \c!numbercommand, but compatible
               {\preparednumber\domovednote\v!nextpage\v!previouspage}}%
               [\s!fnt:f:\internalfootreference]}%
        \fi}%
     \doifelse{\noteparameter\c!interaction}\v!no
       {\ifconditional\pagewisenotes
          \footnotereferenceto
        \fi}%
       {\footnotereferenceto}%
     \bgroup
     \postponenotes
     \aftergroup\dostopnote
     \begstrut
     \let\next}

% \dodowritereference in core-ref.tex
% Needs immediate write to prevent refs getting out of order

\def\dodowritereference#1#2#3\end#4#5#6%
  {\bgroup
   \global\advance\crossreferencenumber \plusone\relax
   \if#1-\if#2:%
     \let\referenceprefix\empty
     \xdef\lastreference{#3}%
   \else
     % \xdef\lastreference{#1#2#3}% here we loose the space
   \fi\else
     % \xdef\lastreference{#1#2#3}% here we loose the space
   \fi
   \ifx\lastreference\empty \else
     \doiffirstreferenceoccurance\lastreference
       {\thisisdestination{\referenceprefix\lastreference}}%
     \referenceinfo>\lastreference
%      \edef\dododowritereference
%        {\writeutilitycommand
%           {\mainreference{\referenceprefix}{\lastreference}{#4}{#5}{#6}}}%
%      \dododowritereference
     \expanded{\immediatewriteutilitycommand{\noexpand\mainreference{\referenceprefix}{\lastreference}{#4}{#5}{#6}}}%
   \fi
   \egroup}

% \crossreferencenumber in core-ref.tex
% Should be initalised to zero, not one.

\newcount\crossreferencenumber \crossreferencenumber=0

% \dogetreferenceelements in core-ref.tex
% Fix the case where we reference the current reference

\def\dogetreferenceelements#1#2#3#4#5%
  {\chardef\currentreferencetype=\ifx#1\relax0\else#1\fi\relax
   \ifnum\currentreferencetype<\plustwo
     \edef\currentpagereference{#2}%
     \let \currentdatareference\empty
     \edef\currentlocationreference{#2}%
     \ifx\currentpagereference   \empty
       \let\currentfolioreference\folio
     \else
       \def \currentpagereference {\referencepagenumber[#2]}%
       \edef\currentfolioreference{\dosplitofffoliopart[#2]}%
     \fi
     \edef\currentrealreference{#3}%
     \settextreferences#4\end
     \ifnum0#5>\crossreferencenumber
       \forwardreferencefalse
     \else
       \forwardreferencetrue
     \fi
   \else
     \let \currentlocationreference\empty
     \edef\currentrealreference {#3}%
     \def \currentdatareference {#2}%
     \let \currentfolioreference\folio
     \settextreferences#4\end
     \forwardreferencefalse
   \fi
   \ifodd\currentreferencetype
     \realreferencepagefalse
   \else
     \docheckrealreferencepage\currentrealreference
     \ifrealreferencepage \else
       \docheckrealreferencepage\currentdatareference
     \fi
   \fi}

\protect


\setuphead[chapter][page=no]

\def\Test#1{%
  \DoTest#1\par
  \backslash somewhere test case - pairs of +/- (expected/actual) should match.\footnote{\DoTest#1}\par
  \DoTest#1\par
}

\def\DoTest#1#2#3#4#5#6#7#8{%
  \the\crossreferencenumber\hskip2em%
  #1\somewhere{+}{-}[A]\hskip2em%
  #2\somewhere{+}{-}[B]\hskip2em%
  #3\somewhere{+}{-}[C]\hskip2em%
  #4\somewhere{+}{-}[D]\hskip2em%
  #5\somewhere{+}{-}[E]\hskip2em%
  #6\somewhere{+}{-}[F]\hskip2em%
  #7\somewhere{+}{-}[G]\hskip2em%
  #8\somewhere{+}{-}[H]%
}

\starttext
\Test{--------}
\chapter[A]{A}
\Test{+-------}
\section[B]{B}
\Test{++------}
\page
\chapter[C]{C}
\Test{+++-----}
\section[D]{D}
\Test{++++----}
% For better test coverage, no \page here
\chapter[E]{E}
\Test{+++++---}
\section[F]{F}
\Test{++++++--}
\page
\chapter[G]{G}
\Test{+++++++-}
\section[H]{H}
\Test{++++++++}
\stoptext


_______________________________________________
dev-context mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-context

Reply via email to