Difference between revisions of "Template:Frac/sandbox"
imported>Crissov m |
imported>Crissov |
||
| Line 1: | Line 1: | ||
{{#if:{{{3|}}} | {{#if:{{{3|}}} | ||
|<!--3 anonymous parameters | |<!--3 anonymous parameters | ||
| − | -->{{frac/output | int = {{{1|0}}} | num = {{{2|0}}} | den = {{{3}}} | dec = {{#expr: ({{{2|0}}}) / ({{{3}}}) }} }} | + | -->{{frac/output | int = {{{1|0}}} | num = {{{2|0}}} | den = {{{3}}} |
| + | | dec = {{#expr: ({{{2|0}}}) / ({{{3}}}) }} }} | ||
|<!--less than 3 anonymous parameters | |<!--less than 3 anonymous parameters | ||
-->{{#if:{{{2|}}} | -->{{#if:{{{2|}}} | ||
|<!--2 anonymous parameters | |<!--2 anonymous parameters | ||
--> {{iffloat|{{{2}}} | --> {{iffloat|{{{2}}} | ||
| − | |<!--integer and float | + | |<!--integer (or float) and float |
| − | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}} | dec = {{#expr: ({{{1|0}}}) / ({{{2}}}) }} }} | + | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}} |
| + | |||
| + | | dec = {{#expr: ({{{1|0}}}) / ({{{2}}}) }} }} | ||
|{{iffloat|{{{1}}} | |{{iffloat|{{{1}}} | ||
|<!--float and integer (denominator) | |<!--float and integer (denominator) | ||
| − | -->{{frac/output | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr: ( ({{{1}}} - (floor ({{{1}}}))) * {{{2}}} ) round 0 }} | den = {{{2}}} | dec = {{#expr: ( ({{{1}}}) - (floor ({{{1}}}) ) }} }} <!--{{dec to frac}}--> | + | -->{{frac/output | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr: ( ({{{1}}} - (floor ({{{1}}}))) * {{{2}}} ) round 0 }} | den = {{{2}}} |
| + | |||
| + | | dec = {{#expr: ( ({{{1}}}) - (floor ({{{1}}}) ) }} }} <!--{{dec to frac}}--> | ||
|<!--integer and integer (or strings) | |<!--integer and integer (or strings) | ||
| − | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}} | dec = {{#expr: ({{{1|0}}})/({{{2}}}) }} }} | + | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}} |
| + | |||
| + | | dec = {{#expr: ({{{1|0}}})/({{{2}}}) }} }} | ||
}} | }} | ||
}} | }} | ||
| Line 22: | Line 29: | ||
-->{{iffloat|{{{1}}} | -->{{iffloat|{{{1}}} | ||
|<!--float including valid expression | |<!--float including valid expression | ||
| − | -->{{frac/output | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr:}} | den = {{#expr:}} | dec = .{{#expr: (({{{1}}}) - (floor ({{{1}}}))) * 10^{{sigfig|{{{1}}}}} }}{{overline|{{{_}}}}} }} | + | -->{{frac/output | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr:}} | den = {{#expr:}} |
| + | |||
| + | | dec = .{{#expr: (({{{1}}}) - (floor ({{{1}}}))) * 10^{{sigfig|{{{1}}}}} }}{{overline|{{{_}}}}} }} | ||
|<!--integer or string | |<!--integer or string | ||
| − | -->{{frac/output | int = {{{1}}} | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}} | dec = .{{overline|{{{_}}}}} }} | + | -->{{frac/output | int = {{{1}}} | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}} |
| + | |||
| + | | dec = .{{overline|{{{_}}}}} }} | ||
}} | }} | ||
|<!--no repeating part | |<!--no repeating part | ||
| − | -->{{frac/output | int = 0 | num = 1 | den = {{{1}}} | dec = {{#iferror: {{#expr: 1/({{{1}}}) }} | 1/{{{1}}} }} }} | + | -->{{frac/output | int = 0 | num = 1 | den = {{{1}}} |
| + | |||
| + | | dec = {{#iferror: {{#expr: 1/({{{1}}}) }} | 1/{{{1}}} }} }} | ||
}} | }} | ||
|<!--no anonymous parameter | |<!--no anonymous parameter | ||
-->{{#if:{{{_|}}} | -->{{#if:{{{_|}}} | ||
|<!--repeating part | |<!--repeating part | ||
| − | -->{{frac/output | int = 0 | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}} | dec = .{{overline|{{{_}}}}} }} | + | -->{{frac/output | int = 0 | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}} |
| + | |||
| + | | dec = .{{overline|{{{_}}}}} }} | ||
|<!--no repeating part | |<!--no repeating part | ||
| − | --> | + | -->⁄ |
}} | }} | ||
}} | }} | ||
Revision as of 16:30, 7 December 2012
⁄
Contents
Proposed code for unified template
Stylesheet
/* {{frac}} */
.frac[data-int], .frac
{content: attr(data-int) "\2064" attr(data-num) "\2044" attr(data-den);
white-space: nowrap;
}
.tion
{content: "\2064" attr(data-num) "\2044" attr(data-den);}
/* {{fraction}} */
.frac[data-sym], table .frac
{content: attr(data-sym);}
/* {{sfrac}} */
.texhtml .frac, .math .frac
{content: contents;}
.texhtml .tion, .math .tion
{content: ""; display: inline-block; vertical-align: -0.5em; font-size: 85%; text-align: center;}
.texhtml .tion::before, .math .tion::before,
.texhtml .tion::after, .math .tion::after
{display: block; line-height: 1em; padding: 0 0.1em;}
.texhtml .tion::before, .math .tion::before
{content: attr(data-num);}
.texhtml .tion::after, .math .tion::after
{content: attr(data-den); border-top: 1px solid;}
/* {{sortfrac}} */
/* functionality automatically included due to decimal fraction non-CSS fallback*/
Main Template
{{#if:{{{3|}}}
|<!--3 anonymous parameters
-->{{frac/output | sym = {{{1}}}⁤{{{2}}}⁄{{{3}}} | int = {{{1}}} | num = {{{2}}} | den = {{{3}}} | dec = {{{2}}}/{{{3}}} }}
|<!--less than 3 anonymous parameters
-->{{#if:{{{2|}}}
|<!--2 anonymous parameters
--> {{iffloat|{{{2}}}
|<!--integer and float
-->{{frac/output | sym = | int = 0 | num = {{{1}}} | den = {{{2}}} | dec = {{{1}}}/{{{2}}} }}
|{{iffloat|{{{1}}}
|<!--float and integer (denominator)
-->{{frac/output | sym = | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr: …}} | den = {{{2}}} | dec = {{dec to frac | {{#expr: ( ({{{1}}}) -(floor ({{{1}}})) … }} | {{{2}}} }}}}
|<!--integer and integer (or strings)
-->{{frac/output | sym = {{{1}}}⁄{{{2}}} | int = 0 | num = {{{1}}} | den = {{{2}}} | dec = {{#expr: ({{{1}}})/({{{2}}}) }} }}
}}
}}
|<!--less than 2 anonymous parameters
-->{{#if:{{{1|}}}
|<!--1 anonymous parameter
-->{{#if:{{{_|}}}
|<!--with repeating part
-->{{iffloat|{{{1}}}
|<!--float including valid expression
-->{{frac/output | sym = | int = {{#expr: floor ({{{1}}}) }} | num = | den = | dec = .{{#expr: (({{{1}}}) - (floor ({{{1}}}))) * 10^xxx}}{{overline|{{{_}}}}} }}
|<!--integer or string
-->{{frac/output | sym = | int = {{{1}}} | num = | den = | dec = {{{2}}} }}
}}
|<!--no repeating part
-->{{frac/output | sym = | int = 0 | num = 1 | den = {{{1}}} | dec = {{#iferror: {{#expr: 1/({{{1}}}) }} | 1/{{{1}}} }} }}
}}
|<!--no anonymous parameter
-->{{#if:{{{_|}}}
|<!--repeating part
-->{{frac/output | sym = | int = 0 | num = {{{_}}} | den = {{loop|9|}} | dec = 0.{{overline|{{{_}}}}} }}
|<!--no repeating part
-->⁄
}}
}}
}}
}}
Helper Template
<span class="frac nowrap"
data-sym="{{{sym|{{#ifeq: {{{int|0}}} | 0 || {{{int}}}  }}{{#switch:
{{#iferror: {{#expr: {{{num|1}}}/{{{den|1}}} }} | string}}
|{{#expr:1/1}} =  
|{{#expr:1/2}} = ½
|{{#expr:1/3}} = ⅓
|{{#expr:2/3}} = ⅔
|{{#expr:1/4}} = ¼
|{{#expr:3/4}} = ¾
|{{#expr:1/5}} = ⅕
|{{#expr:2/5}} = ⅖
|{{#expr:3/5}} = ⅗
|{{#expr:4/5}} = ⅘
|{{#expr:1/6}} = ⅙
|{{#expr:1/7}} = ⅐
|{{#expr:5/6}} = ⅚
|{{#expr:1/8}} = ⅛
|{{#expr:3/8}} = ⅜
|{{#expr:5/8}} = ⅝
|{{#expr:7/8}} = ⅞
|{{#expr:1/9}} = ⅑
|{{#expr:1/10}} = ⅒
|string
|#default = {{{num|1}}}⁄{{{den}}}
}}}}}"
data-int="{{{int|0}}}">{{{int|}}}<span class="tion"
data-num="{{{num|1}}}"
data-den="{{{den|1}}}">{{{dec|}}}</span></span>
Desired results for unified template
No parameter
<span class="frac nowrap">⁄</span>
One parameter
Only repeat
{{{_}}} = 4
<span class="frac nowrap" data-sym="4⁄9" data-int="0">
0<span class="tion" data-num="4" data-den="9">.4̅</span>
</span>
{{{_}}}/{{loop|9|{{sigfig|{{{_}}}}}}}
base (‘9’ is prefix)
Integer
{{{1}}} = 1
<span class="frac nowrap" data-sym="1⁄1" data-int="0">
1<span class="tion" data-num="1" data-den="1">.0</span>
</span>
Float
{{{1}}} = 0.1
<span class="frac nowrap" data-sym="1⁄10" data-int="0">
0<span class="tion" data-num="1" data-den="10">.1</span>
</span>
String
{{{1}}} = A
<span class="frac nowrap" data-sym="1⁄A" data-int="0">
<span class="tion" data-num="1" data-den="A">1/A</span>
</span>
Two parameters
Integer and repeat
{{{1}}} = 1, {{{_}}} = 4
<span class="frac nowrap" data-sym="1⁤4⁄9" data-int="1">
1<span class="tion" data-num="4" data-den="9">.4̅</span>
</span>
Float and repeat
{{{1}}} = 0.1, {{{_}}} = 4
<span class="frac nowrap" data-sym="13⁄90" data-int="0">
<span class="tion" data-num="13" data-den="90">0.14̅</span>
</span>
Float and integer
{{{1}}} = 0.1, {{{2}}} = 2 (denominator)
<span class="frac nowrap" data-sym="0⁄2" data-int="0">0
<span class="tion" data-num="0" data-den="2">.1</span>
</span>
Integer and float
{{{1}}} = 1, {{{2}}} = 0.2
<span class="frac nowrap" data-sym="1⅕" data-int="1">1
<span class="tion" data-num="1" data-den="5">.2</span>
</span>
Integers
{{{1}}} = 1, {{{2}}} = 2
<span class="frac nowrap" data-sym="½" data-int="0">
<span class="tion" data-num="1" data-den="2">0.5</span>
</span>
{{{_}}} is ignored.
Strings
{{{1}}} = A, {{{2}}} = B
<span class="frac nowrap" data-sym="A⁄B" data-int="0">
<span class="tion" data-num="A" data-den="B">A/B</span>
</span>
Three anonymous parameters
{{{_}}} is ignored.
Integers
{{{1}}} = 1, {{{2}}} = 2, {{{3}}} = 3
<span class="frac nowrap" data-sym="1⅔" data-int="1">
1<span class="tion" data-num="2" data-den="3">.6̅</span>
</span>
Strings
{{{1}}} = A, {{{2}}} = B, {{{3}}} = C
<span class="frac nowrap" data-sym="A⁤B⁄C" data-int="A">
A<span class="tion" data-num="B" data-den="C"> B/C</span>
</span>
| This is the template sandbox page for Template:Frac (diff). See also the companion subpage for test cases. |
Template:No subst This template builds an alternative form of common fractions. The template takes one, two, or three parameters: the optional integer (may be signed), the optional numerator and the required denominator; in this order.
Please do not subst:itute it. This template should not be used in science or mathematical articles, per MOS:FRAC and MOS:MATH#Fractions; use {{sfrac}} instead. To allow numerical sorting of a column containing fractions, use data-sort-value="X.YYY" where X.YYY is a rounded decimal equivalent. See Help:Sorting for more information and options.
{{frac|A|B|C}}- APage Template:Screen reader-only/styles.css has no content. B⁄C (integer, numerator and denominator)
{{frac|A|B}}- A⁄B (numerator and denominator)
{{frac|A}}- 1⁄A (denominator only)
{{frac}}- ⁄ (fraction slash only)
Examples
- Numbers
- 1⁄2 1⁄3 2⁄3 1⁄4 3⁄4 1⁄5 2⁄5 3⁄5 4⁄5 1⁄6 5⁄6 1⁄7 2⁄7 3⁄7 4⁄7 5⁄7 6⁄7 1⁄8 3⁄8 5⁄8 7⁄8 1⁄16 3⁄16 5⁄16 7⁄16 9⁄16 11⁄16 13⁄16 15⁄16
- Units
- m⁄s km⁄h kg·m⁄s² 1⁄s Mbit⁄s
Notes
{{frac}}or⁄may be used to print out the fraction slash glyph " ⁄ ".
Parameters
TemplateData for Frac
A template for displaying common fractions of the form int+num/den nicely. It supports 0–3 anonymous parameters with positional meaning.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| leftmost part | 1 | Denominator if only parameter supplied. Numerator if 2 parameters supplied. Integer if 3 parameters supplied. If no parameter is specified the template will render a fraction slash only. | Line | optional |
| middle-right part | 2 | Denominator if 2 parameters supplied. Numerator if 3 parameters supplied. | Line | optional |
| rightmost part | 3 | Denominator, always. | Line | optional |
See also
- Wikipedia:Rendering math
- {{1/2}} (1⁄2), {{1/3}}, {{2/3}}, {{1/4}}, {{3/4}} – shorthands that use this template
- {{sfrac}} (Template:Sfrac) – displays common fractions using a vinculum (horizontal line), for scientific and mathematical text
- {{su}} (superscript
subscript text) – to align both b=subscript & p=superscript - {{sub}} (subscript text) – to show a subscript
- {{sup}} (superscript text) – to show a superscript
- Help:Displaying a formula#Fractions, matrices, multilines
- Help:Convert#Fractions
- Number Forms, a Unicode block consisting primarily of vulgar fractions
- OpenType fonts feature frac, CSS
font-variant-numeric:diagonal-fractions - Template:Unichar
| The above documentation is transcluded from Template:Frac/doc. (edit | history) Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages. Please add categories to the /doc subpage. Subpages of this template. |