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
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
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 ___________________________________________________________________________________
On Mon, 15 Oct 2012 12:08:30 +0200
Sietse Brouwer
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
On Mon, 15 Oct 2012 12:27:27 +0200
Alan BRASLAU
On Mon, 15 Oct 2012 12:08:30 +0200 Sietse Brouwer
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
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
On Mon, 15 Oct 2012 12:27:27 +0200 Alan BRASLAU
wrote: On Mon, 15 Oct 2012 12:08:30 +0200 Sietse Brouwer
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
On Mon, 15 Oct 2012 13:03:40 +0200
Sietse Brouwer
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
participants (2)
-
Alan BRASLAU
-
Sietse Brouwer