ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] mtx-synctex.lua question
@ 2023-12-07 18:23 Jim
  2023-12-08 14:03 ` [NTG-context] " Hans Hagen via ntg-context
  0 siblings, 1 reply; 6+ messages in thread
From: Jim @ 2023-12-07 18:23 UTC (permalink / raw)
  To: ntg-context

Hi,

In mtx-synctex.lua, inside
        local function findlocation(filename,page,xpos,ypos,tolerance)
there is the following code:
                for s=1,tolerance,max(tolerance//10,1) do
                    locate( s, 0) if fi ~= 0 then tl = s ; goto done end
                    locate(-s, 0) if fi ~= 0 then tl = s ; goto done end
                    locate( s, s) if fi ~= 0 then tl = s ; goto done end
                    locate( s,-s) if fi ~= 0 then tl = s ; goto done end
                    locate(-s, s) if fi ~= 0 then tl = s ; goto done end
                    locate(-s,-s) if fi ~= 0 then tl = s ; goto done end
                end

Is the omission of the
        locate(0, s) ...
and
        locate(0, -s) ...
cases intentional, or is that an oversight?

If intentional, can someone explain the rationale to me?

Thanks.

                        Jim
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: mtx-synctex.lua question
  2023-12-07 18:23 [NTG-context] mtx-synctex.lua question Jim
@ 2023-12-08 14:03 ` Hans Hagen via ntg-context
  2023-12-08 15:38   ` Jim
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen via ntg-context @ 2023-12-08 14:03 UTC (permalink / raw)
  To: Jim, mailing list for ConTeXt users; +Cc: Hans Hagen

On 12/7/2023 7:23 PM, Jim wrote:
> Hi,
> 
> In mtx-synctex.lua, inside
>          local function findlocation(filename,page,xpos,ypos,tolerance)
> there is the following code:
>                  for s=1,tolerance,max(tolerance//10,1) do
>                      locate( s, 0) if fi ~= 0 then tl = s ; goto done end
>                      locate(-s, 0) if fi ~= 0 then tl = s ; goto done end
>                      locate( s, s) if fi ~= 0 then tl = s ; goto done end
>                      locate( s,-s) if fi ~= 0 then tl = s ; goto done end
>                      locate(-s, s) if fi ~= 0 then tl = s ; goto done end
>                      locate(-s,-s) if fi ~= 0 then tl = s ; goto done end
>                  end
> 
> Is the omission of the
>          locate(0, s) ...
> and
>          locate(0, -s) ...
> cases intentional, or is that an oversight?
> 
> If intentional, can someone explain the rationale to me?
it's too long ago to remember the reason ... did you test with and without?

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: mtx-synctex.lua question
  2023-12-08 14:03 ` [NTG-context] " Hans Hagen via ntg-context
@ 2023-12-08 15:38   ` Jim
  2023-12-08 18:51     ` Jim
  0 siblings, 1 reply; 6+ messages in thread
From: Jim @ 2023-12-08 15:38 UTC (permalink / raw)
  To: Hans Hagen; +Cc: ntg-context

Hi Hans,

On Fri, Dec  8, 2023 at 15:03 (+0100), Hans Hagen wrote:

> On 12/7/2023 7:23 PM, Jim wrote:
>> Hi,

>> In mtx-synctex.lua, inside
>> local function findlocation(filename,page,xpos,ypos,tolerance)
>> there is the following code:
>> for s=1,tolerance,max(tolerance//10,1) do
>> locate( s, 0) if fi ~= 0 then tl = s ; goto done end
>> locate(-s, 0) if fi ~= 0 then tl = s ; goto done end
>> locate( s, s) if fi ~= 0 then tl = s ; goto done end
>> locate( s,-s) if fi ~= 0 then tl = s ; goto done end
>> locate(-s, s) if fi ~= 0 then tl = s ; goto done end
>> locate(-s,-s) if fi ~= 0 then tl = s ; goto done end
>> end

>> Is the omission of the
>> locate(0, s) ...
>> and
>> locate(0, -s) ...
>> cases intentional, or is that an oversight?

>> If intentional, can someone explain the rationale to me?

> it's too long ago to remember the reason ... did you test with and without?

I did not.  Yet.

But on your suggestion, I will give it a try and get back to you.

                                Jim
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: mtx-synctex.lua question
  2023-12-08 15:38   ` Jim
@ 2023-12-08 18:51     ` Jim
  2023-12-08 20:18       ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Jim @ 2023-12-08 18:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Hans (and anyone else interested in synctex),

On Fri, Dec  8, 2023 at 11:38 (-0400), Jim wrote:

> Hi Hans,

> On Fri, Dec  8, 2023 at 15:03 (+0100), Hans Hagen wrote:

>> On 12/7/2023 7:23 PM, Jim wrote:
>>> Hi,

>>> In mtx-synctex.lua, inside
>>> local function findlocation(filename,page,xpos,ypos,tolerance)
>>> there is the following code:
>>> for s=1,tolerance,max(tolerance//10,1) do
>>> locate( s, 0) if fi ~= 0 then tl = s ; goto done end
>>> locate(-s, 0) if fi ~= 0 then tl = s ; goto done end
>>> locate( s, s) if fi ~= 0 then tl = s ; goto done end
>>> locate( s,-s) if fi ~= 0 then tl = s ; goto done end
>>> locate(-s, s) if fi ~= 0 then tl = s ; goto done end
>>> locate(-s,-s) if fi ~= 0 then tl = s ; goto done end
>>> end

>>> Is the omission of the
>>> locate(0, s) ...
>>> and
>>> locate(0, -s) ...
>>> cases intentional, or is that an oversight?

>>> If intentional, can someone explain the rationale to me?

>> it's too long ago to remember the reason ... did you test with and without?

> I did not.  Yet.

> But on your suggestion, I will give it a try and get back to you.

I modified mtx-synctex.lua as follows:
% diff /usr/local/context/tex/texmf-context/scripts/context/lua/mtx-synctex.lua mtx-synctex-jd.lua 
279a280
>                 -- JD added (0, +/-s) cases for testing
282a284,285
>                     locate( 0, s) if fi ~= 0 then tl = s ; goto done end
>                     locate( 0,-s) if fi ~= 0 then tl = s ; goto done end

and then wrote the following quick and dirty shell script to create log
files for comparison:

---------------------------------------------------------------------
#! /bin/zsh

# File:		    compare-my-synctex-version
# Author:	    Jim Diamond
# Created:	    2023/12/08 13:27:23
#
# Purpose:	    Run some tests to compare ConTeXt's mtx-synctex-lua to
#		    my own version, vis-a-vis the backward-search
#		    functionality.
#
# Notes:	    Assumes $1 is a valid ConTeXt synctex file,
#		    $2 is a valid page within that file, and
#		    $3, if present, is a valid 

DEFAULT_TOLERANCE=300

if [[ $# < 2 || $# > 3 || ! -r $1 ]]
then
    echo >&2 "Usage: $0 <synctex file> <page> [tolerance]"
    echo >&2 "       tolerance default is $DEFAULT_TOLERANCE."
    exit 1
fi

st_file=$1
page=$2
if [[ $3 != "" ]]
then
    tolerance=$3
else
    tolerance=$DEFAULT_TOLERANCE
fi

x_vals=`seq 100 50 550`
y_vals=`seq 100 50 700`

old_results=${st_file}_page_${page}_tol_${tolerance}_using_current.out
new_results=${st_file}_page_${page}_tol_${tolerance}_using_new.out

if [[ -e $old_results || -e $new_results ]]
then
    printf >&2 "$0: at least one of\n\t%s\nor\n\t%s\nexists; quitting.\n" \
	$old_results $new_results
    exit 1
fi

# Get rid of the extra newline from mtxrun as done below.
for x in $=x_vals
do
    for y in $=y_vals
    do
	printf "%3d, %3d: " $x $y
	out=`mtxrun --script synctex --goto --direct \
	    --page=$page --x=$x --y=$y --tolerance=$tolerance $st_file`
	echo $out
    done
done | tee $old_results

echo

for x in $=x_vals
do
    for y in $=y_vals
    do
	printf "%3d, %3d: " $x $y
	out=`mtxrun --script mtx-synctex-jd.lua --goto --direct \
	    --page=$page --x=$x --y=$y --tolerance=$tolerance $st_file`
	echo $out
    done
done | tee $new_results
---------------------------------------------------------------------

and ran it on one page of one synctex file for a few different values of
tolerance (300, 200, 100 and 50).  To briefly summarize, the modified
script found a small number of matches that the original script didn't,
occasionally the line number was different (almost always by 1, but a few
times more), and the tolerance returned by this test version was also <= the
tolerance returned by the current version.

Admittedly, with the other two directions added in, a more extensive test
(a total of a bit under 14 minutes CPU time on a Ryzen 4700U) showed the
new version is about 0.5% slower, so there is a very minor downside.  (I'd
happily spend the extra matches for the minuscule amount of CPU time, but
others may not.)

Cheers.
                                Jim
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: mtx-synctex.lua question
  2023-12-08 18:51     ` Jim
@ 2023-12-08 20:18       ` Hans Hagen
  2023-12-08 21:36         ` Jim
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2023-12-08 20:18 UTC (permalink / raw)
  To: ntg-context

On 12/8/2023 7:51 PM, Jim wrote:

> Hi Hans (and anyone else interested in synctex),
> 282a284,285
>>                      locate( 0, s) if fi ~= 0 then tl = s ; goto done end
>>                      locate( 0,-s) if fi ~= 0 then tl = s ; goto done end
> 
> and then wrote the following quick and dirty shell script to create log
> files for comparison:

ok

> Admittedly, with the other two directions added in, a more extensive test
> (a total of a bit under 14 minutes CPU time on a Ryzen 4700U) showed the
> new version is about 0.5% slower, so there is a very minor downside.  (I'd
> happily spend the extra matches for the minuscule amount of CPU time, but
> others may not.)
the .5% precen tis no big deal, also because this script is not that 
time critical (the code could be made a bit faster anyway) so i'll add 
the few lines

so those 14 minutes, was that N times a file or 1 time a huge file?

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: mtx-synctex.lua question
  2023-12-08 20:18       ` Hans Hagen
@ 2023-12-08 21:36         ` Jim
  0 siblings, 0 replies; 6+ messages in thread
From: Jim @ 2023-12-08 21:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Fri, Dec  8, 2023 at 21:18 (+0100), Hans Hagen wrote:

> On 12/8/2023 7:51 PM, Jim wrote:

>> Hi Hans (and anyone else interested in synctex),
>> 282a284,285
>>> locate( 0, s) if fi ~= 0 then tl = s ; goto done end
>>> locate( 0,-s) if fi ~= 0 then tl = s ; goto done end

>> and then wrote the following quick and dirty shell script to create log
>> files for comparison:

> ok

>> Admittedly, with the other two directions added in, a more extensive test
>> (a total of a bit under 14 minutes CPU time on a Ryzen 4700U) showed the
>> new version is about 0.5% slower, so there is a very minor downside.  (I'd
>> happily spend the extra matches for the minuscule amount of CPU time, but
>> others may not.)
> the .5% precen tis no big deal, also because this script is not that time
> critical (the code could be made a bit faster anyway) so i'll add the few
> lines

Great.  If nothing else, it will keep other people from asking the same
question in the future. :-)

> so those 14 minutes, was that N times a file or 1 time a huge file?

N times a file:

I swiped the code from the program and defined two functions, one
(test_old) one for the current code and one for the new code:

test_new ()                           
{
    for x in $=x_vals
    do
        for y in $=y_vals
        do
            printf "%3d, %3d: " $x $y
            out=`mtxrun --script mtx-synctex-jd.lua --goto --direct \
                --page=$page --x=$x --y=$y --tolerance=$tolerance $st_file`
            echo $out
        done
    done
}

(The test_old was the same except for the argument to --script, which is
'synctext'.)

I defined $page=15, $tolerance=300 and $st_file to be a file with 3441
lines (there are 19 pages in total, so I was skipping a lot of stuff) and
changed x_vals and y_vals to create a lot of iterations:

x_vals=`seq 100 5 550`
y_vals=`seq 100 5 700`

and finally I ran

time (test_new > /dev/null)

and

time (test_old > /dev/null)

So mtxrun was called for each of these 11,011 times.

Not the best possible benchmark, but probably good enough to show that
adding the other two cases isn't hurtful.

Cheers.
                                Jim
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2023-12-08 21:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 18:23 [NTG-context] mtx-synctex.lua question Jim
2023-12-08 14:03 ` [NTG-context] " Hans Hagen via ntg-context
2023-12-08 15:38   ` Jim
2023-12-08 18:51     ` Jim
2023-12-08 20:18       ` Hans Hagen
2023-12-08 21:36         ` Jim

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).