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