ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* index page range bug
@ 2006-09-06  0:12 Jason Grout
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Grout @ 2006-09-06  0:12 UTC (permalink / raw)


Hans (or whoever could change this),

When using startregister/stopregister commands, if the range is only one 
one page, then while both a [f] and a [t] are written to the tui file, 
only one \registerfrom command is put in the tuo file.  If there is only 
one range, it seems like the software deals with it nicely.  However, if 
there are two ranges (like in the example below), then the index 
incorrectly assumes that the first \registerfrom command in the tuo file 
corresponds to the \registerto command.

Here's an example

test.tex:

\setuppapersize [letter][letter]
\starttext
\input knuth

KNUTH START\startregister[index][knuthrange1]{Knuth}

\input knuth

KNUTH END\stopregister[index][knuthrange1]

\dorecurse{10}{\input zapf }

KNUTH START\startregister[index][knuthrange2]{Knuth}

\dorecurse{10}{\input knuth }

KNUTH END\stopregister[index][knuthrange2]

\completeindex
\stoptext

test.tui:

r f {index} {1} {} {Knuth} {2--0-0-0-0-0-0-0--1} {1}
r t {index} {2} {} {Knuth} {2--0-0-0-0-0-0-0--1} {1}
r f {index} {3} {} {Knuth} {2--0-0-0-0-0-0-0--3} {3}
r t {index} {4} {} {Knuth} {2--0-0-0-0-0-0-0--5} {5}

test.tuo:

\registerentrya{index}{Knuth}
\registerfrom{index}{,}{1}{2--0-0-0-0-0-0-0--1}{1}
\registerfrom{index}{,}{3}{2--0-0-0-0-0-0-0--3}{3}
\registerto{index}{,}{4}{2--0-0-0-0-0-0-0--5}{5}


and the index reads "Knuth 1--5", but it should read "Knuth 1, 3--5"


My guess is the problem lies in the line in texutil.rb:

if copied || ! ((lastpage == entry.page) && \
(lastrealpage == entry.realpage)) then

(sorry, that was one line before my mail program wrapped it).

Since the ending [t] reference for the first \stopregister command is on 
the same page as the first one, the whole section outputting a 
\registerto command to the tuo file is skipped.  Instead, how about 
making the code check to see if we have a range that ends on the same 
page as it started?  If it does, then just insert a \registerpage 
command instead of a \registerfrom command.

I've corrected this in the perl version (I had an old version of ConTEXt 
before today, otherwise I would have worked on the ruby version).  I 
also added support for nesting ranges, which I then discovered weren't 
supported anyway.  (I also had to change the sort order on 
@RegisterEntries so that [f] and [t] entries would be consecutive, 
instead of all the [f] entries preceding the [t] entries, but it looks 
like that was fixed already). Here's my code from the perl texutil (with 
a bunch of comments from me):



           { # print "$LastPage / $Page // $LastRealPage / $RealPage\n" ;
             $NextEntry = 
"{$Class}{$PreviousA}{$PreviousB}{$PreviousC}{$PageHow,$TextHow}" ;
             $SavedLine = 
"{$Class}{$PageHow,$TextHow}{$Location}{$Page}{$RealPage}\n" ;
              # If we are starting a new level, start our nesting over.
              # This will completely ignore the last non-properly
              # nested result in the previous heading.
             if($Copied)
               { $NestingLevel=0;
                 $TopLevelFromPage="";
                 $TopLevelFromRealPage="";
                 $TopLevelFromLine="";
               }
             if ($RegisterState eq $RegStat{"f"}) # If we are starting a 
range
               { FlushSavedLine ;
                 if($NestingLevel eq 0)
                   { $TopLevelFromLine=$SavedLine;
                     $TopLevelFromPage=$Page;
                     $TopLevelFromRealPage=$RealPage;
                   }
                 $NestingLevel++;
               }
             elsif ($RegisterState eq $RegStat{"t"}) # If we are ending 
a range
               { FlushSavedLine ;
                 $NestingLevel--;
                 if($NestingLevel <= 0)
                   { if((($Page eq $TopLevelFromPage) and ($RealPage eq 
$TopLevelFromRealPage))
                        or $NestingLevel < 0)
                       { print TUO "\\registerpage$SavedLine" ;
                       }
                     else
                       { print TUO "\\registerfrom$TopLevelFromLine" ;
                         print TUO "\\registerto$SavedLine" ;
                       }
                     $NestingLevel = 0 ;
                     $TopLevelFromPage="";
                     $TopLevelFromRealPage="";
                     $TopLevelFromLine="";
                   }
               }
             else # If we have a normal single entry
               { if ($CollapseEntries)
                   { if ($SavedEntry ne $NextEntry)
                       { $SavedFrom = $SavedLine }
                     else
                       { $SavedTo = $SavedLine }
                     $SavedEntry = $NextEntry }
                 else
                  { print TUO "\\registerpage$SavedLine" }
               }


Of course, if I've missed something, please let me know.  I've only 
started using ConTEXt in the last few weeks.  I needed grid typesetting 
for a book I was working on and I was getting tired of LaTeX not helping 
me there.  I've absolutely loved working with ConTEXt!  (well, other 
than sometimes a frustrating lack of documentation, but there have been 
lots of good posts on the mailing list that have helped me).


Thanks,

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: index page range bug
       [not found] <mailman.680.1157523489.2039.ntg-context@ntg.nl>
@ 2006-09-07  9:18 ` Duncan Hothersall
  0 siblings, 0 replies; 2+ messages in thread
From: Duncan Hothersall @ 2006-09-07  9:18 UTC (permalink / raw)


Jason wrote:

> When using startregister/stopregister commands, if the range is only one 
> one page, then while both a [f] and a [t] are written to the tui file, 
> only one \registerfrom command is put in the tuo file.  If there is only 
> one range, it seems like the software deals with it nicely.  However, if 
> there are two ranges (like in the example below), then the index 
> incorrectly assumes that the first \registerfrom command in the tuo file 
> corresponds to the \registerto command.

Aha! Great work tracking this down Jason, I have been bitten by this bug
many times in the past but not been able to isolate it. It would be
really great if this could be fixed in the ruby script.

Duncan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-07  9:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-06  0:12 index page range bug Jason Grout
     [not found] <mailman.680.1157523489.2039.ntg-context@ntg.nl>
2006-09-07  9:18 ` Duncan Hothersall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).