Content deleted Content added
add spell=in, spell=In (inputs only, and English only) using Module:ConvertNumeric |
kludge to allow different fraction styles ("1+2/3" or "1+2//3" or "1+2///3") to try suggestions at Template talk:Convert |
||
Line 863:
end
-- Fraction output format
-- 2013-07-20 Trying new styles proposed at [[Template talk:Convert]].
-- frac1: sign, numerator, denominator▼
local fracfmt = {
-- frac2: wholenumber, sign, numerator, denominator▼
{ -- Like {{frac}} (fraction slash).
local frac1 = '<span style="white-space:nowrap">%s<sup>%s</sup>⁄<sub>%s</sub></span>'▼
local frac2 = '<span class="frac nowrap">%s<s style="display:none">%s</s><sup>%s</sup>⁄<sub>%s</sub></span>'▼
-- 1+2/3 : signed_wholenumber, numerator, denominator
'<span class="frac nowrap">%s<sup>%s</sup>⁄<sub>%s</sub></span>',
'<span class="frac nowrap">%s<sup> %s</sup>⁄<sub>%s</sub></span>',
},
{ -- Like {{sfrac}} (fraction horizontal bar).
-- 1//2 : sign, numerator, denominator (sign should probably be before the fraction, but then it can wrap, and html is already too long)
-- 1+2//3 : signed_wholenumber, numerator, denominator
'<span class="sfrac nowrap" style="display:inline-block; vertical-align:-0.5em; font-size:85%%; text-align:center;"><span style="display:block; line-height:1em; padding:0 0.1em;">%s%s</span><span style="display:none;">/</span><span style="display:block; line-height:1em; padding:0 0.1em; border-top:1px solid;">%s</span></span>',
'<span class="sfrac nowrap">%s<span style="display:none;"> </span><span style="display:inline-block; vertical-align:-0.5em; font-size:85%%; text-align:center;"><span style="display:block; line-height:1em; padding:0 0.1em;">%s</span><span style="display:none;">/</span><span style="display:block; line-height:1em; padding:0 0.1em; border-top:1px solid;">%s</span></span></span>',
},
{ -- Like old {{convert}} template.
-- 1+2///3: signed_wholenumber, sign, numerator, denominator
▲
},
}
local function extract_fraction(parms, text, negative)
Line 892 ⟶ 909:
-- (which may be negative) are also accepted (like old template).
-- Template interprets '1.23e+2+12/24' as '123(12/24)' = 123.5!
local
local lhs, slash, denstr = text:match('^%s*([^/]-)%s*(/+)%s*(.-)%s*$')
local denominator = tonumber(denstr)
if denominator == nil then return nil end
local wholestr, negfrac, rhs = lhs:match('^%s*(.-[^eE])%s*([+-])%s*(.-)%s*$')
if wholestr == nil or wholestr == '' then
wholestr = nil
Line 907 ⟶ 924:
end
negfrac = (negfrac == '-')
local numerator = tonumber(numstr)
if numerator == nil then return nil end
-- Spelling of silly inputs like "-2+3/8" or "2+3/+8" (mixed or excess signs) is not supported.
Line 929 ⟶ 946:
numstr = use_minus(numstr)
denstr = use_minus(denstr)
local style = #slash -- kludge: 1, 2, or 3 slashes can be used to select style
if style > 3 then style = 3 end
local wikitext
if wholestr then
local sign = negative and MINUS or '+'▼
if negative then
wholestr = change_sign(wholestr)
end
local fmt = fracfmt[style][2]
wikitext = format(frac2, use_minus(from_en(wholestr)), sign, from_en(numstr), from_en(denstr))▼
if style < 3 then
wikitext = format(fmt, use_minus(from_en(wholestr)), from_en(numstr), from_en(denstr))
else
▲ local sign = negative and MINUS or '+'
end
else
local sign = negative and MINUS or ''
wikitext = format(
end
if do_spell then
|