Difference between revisions of "Template:Frac/sandbox"

From blackwiki
Jump to navigation Jump to search
imported>Crissov
(←Replaced content with '<span class="frac nowrap">{{#if:{{{3|}}} |{{{1}}}<sup> {{{2}}}</sup>⁄<sub>{{{3}}}</sub> |{{#if:{{{2|}}} |<sup>{{{1}}}</sup>⁄<sub>{{{2}}}...')
Line 1: Line 1:
−
<noinclude>
+
<span class="frac nowrap">{{#if:{{{3|}}}
−
== Code and default output ==
+
|{{{1}}}<sup>&#32;{{{2}}}</sup>&frasl;<sub>{{{3}}}</sub>
−
</noinclude>{{#if:{{{3|}}}
+
|{{#if:{{{2|}}}
−
|<!--3 anonymous parameters
+
  |<sup>{{{1}}}</sup>&frasl;<sub>{{{2}}}</sub>
−
  -->{{frac/output | int = {{{1|0}}} | num = {{{2|0}}} | den = {{{3}}}
+
   |{{#if:{{{1|}}}
−
                                      | dec = {{#expr: ({{{2|0}}}) / ({{{3}}}) }} }}
+
  |<sup>1</sup>&frasl;<sub>{{{1}}}</sub>
−
|<!--less than 3 anonymous parameters
+
  |&frasl;
−
  -->{{#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
 
−
            -->&frasl;
 
−
            }}
 
−
        }}
 
−
      }}
 
−
}}<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}}}&#x2064;{{{2}}}&frasl;{{{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}}}&frasl;{{{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
 
−
            -->&frasl;
 
−
            }}
 
−
        }}
 
−
      }}
 
−
}}
 
−
</source>
 
−
 
 
−
=== [[Template:Frac/output|Helper Template]] ===
 
−
{{under construction}}
 
−
<source lang=html5>
 
−
<span class="frac nowrap"
 
−
data-sym="{{{sym|{{#ifeq: {{{int|0}}} | 0 || {{{int}}}&thinsp; }}{{#switch:
 
−
  {{#iferror: {{#expr: {{{num|1}}}/{{{den|1}}} }} | string}}
 
−
   |{{#expr:1/1}} = &#x2007;
 
−
  |{{#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">&frasl;</span>
 
−
</source>
 
−
 
 
−
=== One parameter ===
 
−
 
 
−
==== Only repeat ====
 
−
<nowiki>{{{_}}}</nowiki> = 4
 
−
<source lang=html5>
 
−
<span class="frac nowrap" data-sym="4&frasl;9" data-int="0">
 
−
0<span class="tion" data-num="4" data-den="9">.4&#x0305;</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&frasl;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&frasl;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&frasl;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&#x2064;4&frasl;9" data-int="1">
 
−
1<span class="tion" data-num="4" data-den="9">.4&#x0305;</span>
 
−
</span>
 
−
</source>
 
−
 
 
−
==== Float and repeat ====
 
−
<nowiki>{{{1}}}</nowiki> = 0.1, <nowiki>{{{_}}}</nowiki> = 4
 
−
<source lang=html5>
 
−
<span class="frac nowrap" data-sym="13&frasl;90" data-int="0">
 
−
<span class="tion" data-num="13" data-den="90">0.14&#x0305;</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&frasl;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&frasl;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&#x0305;</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&#x2064;B&frasl;C" data-int="A">
 
−
A<span class="tion" data-num="B" data-den="C"> B/C</span>
 
−
</span>
 
−
</source>
 
−
 
 
 
{{documentation}}
 
{{documentation}}
 
</noinclude>
 
</noinclude>

Revision as of 19:12, 13 January 2013

⁄

Template documentation[view] [edit] [history] [purge]

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 &frasl; may be used to print out the fraction slash glyph " ⁄ ".

Parameters

This is the TemplateData documentation for this template used by VisualEditor and other tools; see the monthly parameter usage report for this template.

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.

Template parameters

ParameterDescriptionTypeStatus
leftmost part1

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.

Lineoptional
middle-right part2

Denominator if 2 parameters supplied. Numerator if 3 parameters supplied.

Lineoptional
rightmost part3

Denominator, always.

Lineoptional

See also


Template:Subpage other