ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* m-graph.mkiv format bug
@ 2012-10-15  9:19 Alan BRASLAU
  2012-10-15 10:08 ` Sietse Brouwer
  0 siblings, 1 reply; 6+ messages in thread
From: Alan BRASLAU @ 2012-10-15  9:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users

There is a bug with format() as redefined in m-graph.mkiv
1e10 and 1e-10 truncate the tailing 0.
(I have not been able to fix the code...)

Alan

Minimal example:

\usemodule [graph]

\starttext
\startMPpage
label(format("@g","1e-10"),(0,      0)) ;
label(format("@g","1e+10"),(2cm,    0)) ;
label(format("@g","1e-12"),(0,  -.5cm)) ;
label(format("@g","1e+12"),(2cm,-.5cm)) ;
\stopMPpage
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: m-graph.mkiv format bug
  2012-10-15  9:19 m-graph.mkiv format bug Alan BRASLAU
@ 2012-10-15 10:08 ` Sietse Brouwer
  2012-10-15 10:27   ` Alan BRASLAU
  0 siblings, 1 reply; 6+ messages in thread
From: Sietse Brouwer @ 2012-10-15 10:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users

> There is a bug with format() as redefined in m-graph.mkiv
> 1e10 and 1e-10 truncate the tailing 0.

The function strip() is removing 0 throughout the exponent, and I
don't know what purpose that might serve. If we never want to remove
zeroes, this works:

    local function strip(s)
-        return "\\times10^{"..(s:gsub("%+*0*","")).."}"
+        return "\\times10^{"..(s:gsub("%+*","")).."}"
    end

Note that if the exponent is zero the "× 10^0" will be left out
completely, in both the old and the new strip() function. This seems
to be by design. Illustration of this behaviour:

\usemodule[graph]
\starttext
\startMPpage
        label(format("@g","1e+0"),(2cm,-1cm)) ;
\stopMPpage
\stoptext

Cheers,
Sietse


On Mon, Oct 15, 2012 at 11:19 AM, Alan BRASLAU <alan.braslau@cea.fr> wrote:
> There is a bug with format() as redefined in m-graph.mkiv
> 1e10 and 1e-10 truncate the tailing 0.
> (I have not been able to fix the code...)
>
> Alan
>
> Minimal example:
>
> \usemodule [graph]
>
> \starttext
> \startMPpage
> label(format("@g","1e-10"),(0,      0)) ;
> label(format("@g","1e+10"),(2cm,    0)) ;
> label(format("@g","1e-12"),(0,  -.5cm)) ;
> label(format("@g","1e+12"),(2cm,-.5cm)) ;
> \stopMPpage
> \stoptext
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: m-graph.mkiv format bug
  2012-10-15 10:08 ` Sietse Brouwer
@ 2012-10-15 10:27   ` Alan BRASLAU
  2012-10-15 10:45     ` Alan BRASLAU
  0 siblings, 1 reply; 6+ messages in thread
From: Alan BRASLAU @ 2012-10-15 10:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 15 Oct 2012 12:08:30 +0200
Sietse Brouwer <sbbrouwer@gmail.com> wrote:

> > There is a bug with format() as redefined in m-graph.mkiv
> > 1e10 and 1e-10 truncate the tailing 0.
> 
> The function strip() is removing 0 throughout the exponent, and I
> don't know what purpose that might serve. If we never want to remove
> zeroes, this works:
> 
>     local function strip(s)
> -        return "\\times10^{"..(s:gsub("%+*0*","")).."}"
> +        return "\\times10^{"..(s:gsub("%+*","")).."}"
>     end
> 
> Note that if the exponent is zero the "× 10^0" will be left out
> completely, in both the old and the new strip() function. This seems
> to be by design. Illustration of this behaviour:
> 
> \usemodule[graph]
> \starttext
> \startMPpage
>         label(format("@g","1e+0"),(2cm,-1cm)) ;
> \stopMPpage
> \stoptext


Thanks, this "fixes" it for now,
but I believe that the strip is intended to remove leading zeros, as in
  label(format("@g","1e+08"),(2cm,-1cm)) ;

I suppose that the correct syntax must be something like the regex
  s/[+-]*0*\([1-9]\)/\1/
(not sure how to state this in lua gsub()...)

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: m-graph.mkiv format bug
  2012-10-15 10:27   ` Alan BRASLAU
@ 2012-10-15 10:45     ` Alan BRASLAU
  2012-10-15 11:03       ` Sietse Brouwer
  0 siblings, 1 reply; 6+ messages in thread
From: Alan BRASLAU @ 2012-10-15 10:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 15 Oct 2012 12:27:27 +0200
Alan BRASLAU <alan.braslau@cea.fr> wrote:

> On Mon, 15 Oct 2012 12:08:30 +0200
> Sietse Brouwer <sbbrouwer@gmail.com> wrote:
> 
> > > There is a bug with format() as redefined in m-graph.mkiv
> > > 1e10 and 1e-10 truncate the tailing 0.
> > 
> > The function strip() is removing 0 throughout the exponent, and I
> > don't know what purpose that might serve. If we never want to remove
> > zeroes, this works:
> > 
> >     local function strip(s)
> > -        return "\\times10^{"..(s:gsub("%+*0*","")).."}"
> > +        return "\\times10^{"..(s:gsub("%+*","")).."}"
> >     end
> > 
> > Note that if the exponent is zero the "× 10^0" will be left out
> > completely, in both the old and the new strip() function. This seems
> > to be by design. Illustration of this behaviour:
> > 
> > \usemodule[graph]
> > \starttext
> > \startMPpage
> >         label(format("@g","1e+0"),(2cm,-1cm)) ;
> > \stopMPpage
> > \stoptext
> 
> 
> Thanks, this "fixes" it for now,
> but I believe that the strip is intended to remove leading zeros, as
> in label(format("@g","1e+08"),(2cm,-1cm)) ;
> 
> I suppose that the correct syntax must be something like the regex
>   s/[+-]*0*\([1-9]\)/\1/
> (not sure how to state this in lua gsub()...)


Figured it out (and we don't want to strip a leading minus sign):

    local function strip(s)
        return "\\times10^{"..(s:gsub("%+*0*([1-9])","%1")).."}"
    end


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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: m-graph.mkiv format bug
  2012-10-15 10:45     ` Alan BRASLAU
@ 2012-10-15 11:03       ` Sietse Brouwer
  2012-10-15 12:21         ` Alan BRASLAU
  0 siblings, 1 reply; 6+ messages in thread
From: Sietse Brouwer @ 2012-10-15 11:03 UTC (permalink / raw)
  To: Alan BRASLAU, mailing list for ConTeXt users, Hans Hagen

Alan wrote:
> Figured it out (and we don't want to strip a leading minus sign):
>
>     local function strip(s)
>         return "\\times10^{"..(s:gsub("%+*0*([1-9])","%1")).."}"
>     end

Better to anchor the pattern to the start of the string with `^` (and
then the nonzerodigitmatching is no longer needed):
gsub("^%+*0*", "")
Otherwise, you'll get 805 --> 85.

--Sietse

On Mon, Oct 15, 2012 at 12:45 PM, Alan BRASLAU <alan.braslau@cea.fr> wrote:
> On Mon, 15 Oct 2012 12:27:27 +0200
> Alan BRASLAU <alan.braslau@cea.fr> wrote:
>
>> On Mon, 15 Oct 2012 12:08:30 +0200
>> Sietse Brouwer <sbbrouwer@gmail.com> wrote:
>>
>> > > There is a bug with format() as redefined in m-graph.mkiv
>> > > 1e10 and 1e-10 truncate the tailing 0.
>> >
>> > The function strip() is removing 0 throughout the exponent, and I
>> > don't know what purpose that might serve. If we never want to remove
>> > zeroes, this works:
>> >
>> >     local function strip(s)
>> > -        return "\\times10^{"..(s:gsub("%+*0*","")).."}"
>> > +        return "\\times10^{"..(s:gsub("%+*","")).."}"
>> >     end
>> >
>> > Note that if the exponent is zero the "× 10^0" will be left out
>> > completely, in both the old and the new strip() function. This seems
>> > to be by design. Illustration of this behaviour:
>> >
>> > \usemodule[graph]
>> > \starttext
>> > \startMPpage
>> >         label(format("@g","1e+0"),(2cm,-1cm)) ;
>> > \stopMPpage
>> > \stoptext
>>
>>
>> Thanks, this "fixes" it for now,
>> but I believe that the strip is intended to remove leading zeros, as
>> in label(format("@g","1e+08"),(2cm,-1cm)) ;
>>
>> I suppose that the correct syntax must be something like the regex
>>   s/[+-]*0*\([1-9]\)/\1/
>> (not sure how to state this in lua gsub()...)
>
>
> Figured it out (and we don't want to strip a leading minus sign):
>
>     local function strip(s)
>         return "\\times10^{"..(s:gsub("%+*0*([1-9])","%1")).."}"
>     end
>
>
> Alan
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: m-graph.mkiv format bug
  2012-10-15 11:03       ` Sietse Brouwer
@ 2012-10-15 12:21         ` Alan BRASLAU
  0 siblings, 0 replies; 6+ messages in thread
From: Alan BRASLAU @ 2012-10-15 12:21 UTC (permalink / raw)
  To: Sietse Brouwer; +Cc: mailing list for ConTeXt users, Hans Hagen

On Mon, 15 Oct 2012 13:03:40 +0200
Sietse Brouwer <sbbrouwer@gmail.com> wrote:

> Alan wrote:
> > Figured it out (and we don't want to strip a leading minus sign):
> >
> >     local function strip(s)
> >         return "\\times10^{"..(s:gsub("%+*0*([1-9])","%1")).."}"
> >     end
> 
> Better to anchor the pattern to the start of the string with `^` (and
> then the nonzerodigitmatching is no longer needed):
> gsub("^%+*0*", "")
> Otherwise, you'll get 805 --> 85.

Thank you for the suggestion. Tried it, but this
doesn't work, so I must be missing something...

Of course, with MetaPost 2.0 we will certainly come across such a case
with numbers like 1e805. :)

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2012-10-15 12:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-15  9:19 m-graph.mkiv format bug Alan BRASLAU
2012-10-15 10:08 ` Sietse Brouwer
2012-10-15 10:27   ` Alan BRASLAU
2012-10-15 10:45     ` Alan BRASLAU
2012-10-15 11:03       ` Sietse Brouwer
2012-10-15 12:21         ` Alan BRASLAU

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