imported>Crissov |
|
| Line 1: |
Line 1: |
| − | <noinclude> | + | <span class="frac nowrap">{{#if:{{{3|}}} |
| − | == Code and default output == | + | |{{{1}}}<sup> {{{2}}}</sup>⁄<sub>{{{3}}}</sub> |
| − | </noinclude>{{#if:{{{3|}}}
| + | |{{#if:{{{2|}}} |
| − | |<!--3 anonymous parameters | + | |<sup>{{{1}}}</sup>⁄<sub>{{{2}}}</sub> |
| − | -->{{frac/output | int = {{{1|0}}} | num = {{{2|0}}} | den = {{{3}}}
| + | |{{#if:{{{1|}}} |
| − | | dec = {{#expr: ({{{2|0}}}) / ({{{3}}}) }} }}
| + | |<sup>1</sup>⁄<sub>{{{1}}}</sub> |
| − | |<!--less than 3 anonymous parameters
| + | |⁄ |
| − | -->{{#if:{{{2|}}}
| + | }} |
| − | |<!--2 anonymous parameters
| + | }} |
| − | --> {{iffloat|{{{2}}}
| + | }}</span><noinclude> |
| − | |<!--integer (or float) and float
| |
| − | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}}
| |
| − | | dec = {{#expr: ({{{1|0}}}) / ({{{2}}}) }} }}
| |
| − | |{{iffloat|{{{1}}}
| |
| − | |<!--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}}-->
| |
| − | |<!--integer and integer (or strings)
| |
| − | -->{{frac/output | int = 0 | num = {{{1|0}}} | den = {{{2}}}
| |
| − | | dec = {{#expr: ({{{1|0}}})/({{{2}}}) }} }}
| |
| − | }}
| |
| − | }}
| |
| − | |<!--less than 2 anonymous parameters
| |
| − | -->{{#if:{{{1|}}}
| |
| − | |<!--1 anonymous parameter
| |
| − | -->{{#if:{{{_|}}}
| |
| − | |<!--with repeating part
| |
| − | -->{{iffloat|{{{1}}}
| |
| − | |<!--float including valid expression
| |
| − | -->{{frac/output | int = {{#expr: floor ({{{1}}}) }} | num = {{#expr:}} | den = {{#expr:}}
| |
| − | | dec = .{{#expr: (({{{1}}}) - (floor ({{{1}}}))) * 10^{{sigfig|{{{1}}}}} }}{{overline|{{{_}}}}} }}
| |
| − | |<!--integer or string
| |
| − | -->{{frac/output | int = {{{1}}} | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}}
| |
| − | | dec = .{{overline|{{{_}}}}} }}
| |
| − | }}
| |
| − | |<!--no repeating part
| |
| − | -->{{frac/output | int = 0 | num = 1 | den = {{{1}}}
| |
| − | | dec = {{#iferror: {{#expr: 1/({{{1}}}) }} | 1/{{{1}}} }} }}
| |
| − | }}
| |
| − | |<!--no anonymous parameter
| |
| − | -->{{#if:{{{_|}}}
| |
| − | |<!--repeating part
| |
| − | -->{{frac/output | int = 0 | num = {{{_}}} | den = {{loop|9|{{sigfig|{{{_}}}}}}}
| |
| − | | dec = .{{overline|{{{_}}}}} }}
| |
| − | |<!--no repeating part
| |
| − | -->⁄
| |
| − | }}
| |
| − | }}
| |
| − | }}
| |
| − | }}<noinclude>
| |
| − | | |
| − | == Proposed code for unified template ==
| |
| − | === [[MediaWiki:Common.css|Stylesheet]] ===
| |
| − | <source lang=css> | |
| − | /* {{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*/
| |
| − | </source> | |
| − | | |
| − | === [[Template:Frac|Main Template]] ===
| |
| − | <source lang=html5>
| |
| − | {{#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
| |
| − | -->⁄
| |
| − | }}
| |
| − | }}
| |
| − | }}
| |
| − | }}
| |
| − | </source> | |
| − | | |
| − | === [[Template:Frac/output|Helper Template]] ===
| |
| − | {{under construction}}
| |
| − | <source lang=html5>
| |
| − | <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>
| |
| − | </source>
| |
| − | | |
| − | == Desired results for unified template ==
| |
| − | === No parameter ===
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap">⁄</span>
| |
| − | </source>
| |
| − | | |
| − | === One parameter ===
| |
| − | | |
| − | ==== Only repeat ====
| |
| − | <nowiki>{{{_}}}</nowiki> = 4
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="4⁄9" data-int="0">
| |
| − | 0<span class="tion" data-num="4" data-den="9">.4̅</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | <nowiki>{{{_}}}/{{loop|9|{{sigfig|{{{_}}}}}}}</nowiki>
| |
| − | | |
| − | {{padleft:base|total length|9}} (‘9’ is prefix)
| |
| − | | |
| − | ==== Integer ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 1
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="1⁄1" data-int="0">
| |
| − | 1<span class="tion" data-num="1" data-den="1">.0</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== Float ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 0.1 | |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="1⁄10" data-int="0">
| |
| − | 0<span class="tion" data-num="1" data-den="10">.1</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== String ====
| |
| − | <nowiki>{{{1}}}</nowiki> = A
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="1⁄A" data-int="0">
| |
| − | <span class="tion" data-num="1" data-den="A">1/A</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | === Two parameters ===
| |
| − | | |
| − | ==== Integer and repeat ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 1, <nowiki>{{{_}}}</nowiki> = 4
| |
| − | <source lang=html5>
| |
| − | <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>
| |
| − | </source>
| |
| − | | |
| − | ==== Float and repeat ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 0.1, <nowiki>{{{_}}}</nowiki> = 4
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="13⁄90" data-int="0">
| |
| − | <span class="tion" data-num="13" data-den="90">0.14̅</span> | |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== Float and integer ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 0.1, <nowiki>{{{2}}}</nowiki> = 2 (denominator)
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="0⁄2" data-int="0">0
| |
| − | <span class="tion" data-num="0" data-den="2">.1</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== Integer and float ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 1, <nowiki>{{{2}}}</nowiki> = 0.2
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="1⅕" data-int="1">1
| |
| − | <span class="tion" data-num="1" data-den="5">.2</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== Integers ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 1, <nowiki>{{{2}}}</nowiki> = 2
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="½" data-int="0">
| |
| − | <span class="tion" data-num="1" data-den="2">0.5</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | <nowiki>{{{_}}}</nowiki> is ignored.
| |
| − | | |
| − | ==== Strings ====
| |
| − | <nowiki>{{{1}}}</nowiki> = A, <nowiki>{{{2}}}</nowiki> = B
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="A⁄B" data-int="0">
| |
| − | <span class="tion" data-num="A" data-den="B">A/B</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | === Three anonymous parameters ===
| |
| − | <nowiki>{{{_}}}</nowiki> is ignored.
| |
| − | ==== Integers ====
| |
| − | <nowiki>{{{1}}}</nowiki> = 1, <nowiki>{{{2}}}</nowiki> = 2, <nowiki>{{{3}}}</nowiki> = 3
| |
| − | <source lang=html5>
| |
| − | <span class="frac nowrap" data-sym="1⅔" data-int="1">
| |
| − | 1<span class="tion" data-num="2" data-den="3">.6̅</span>
| |
| − | </span>
| |
| − | </source>
| |
| − | | |
| − | ==== Strings ====
| |
| − | <nowiki>{{{1}}}</nowiki> = A, <nowiki>{{{2}}}</nowiki> = B, <nowiki>{{{3}}}</nowiki> = C
| |
| − | <source lang=html5>
| |
| − | <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>
| |
| − | </source>
| |
| − | | |
| | {{documentation}} | | {{documentation}} |
| | </noinclude> | | </noinclude> |