Difference between revisions of "Template:Frac/sandbox"

From blackwiki
Jump to navigation Jump to search
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
             -->{{frac/output}}
+
             -->&frasl;
 
             }}
 
             }}
 
         }}
 
         }}

Revision as of 16:30, 7 December 2012

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}}}&#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;
            }}
         }}
      }}
}}

Helper Template

Template:Under construction

<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>

Desired results for unified template

No parameter

<span class="frac nowrap">&frasl;</span>

One parameter

Only repeat

{{{_}}} = 4

<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>

{{{_}}}/{{loop|9|{{sigfig|{{{_}}}}}}}

base (‘9’ is prefix)

Integer

{{{1}}} = 1

<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>

Float

{{{1}}} = 0.1

<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>

String

{{{1}}} = A

<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>

Two parameters

Integer and repeat

{{{1}}} = 1, {{{_}}} = 4

<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>

Float and repeat

{{{1}}} = 0.1, {{{_}}} = 4

<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>

Float and integer

{{{1}}} = 0.1, {{{2}}} = 2 (denominator)

<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>

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&frasl;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&#x0305;</span>
</span>

Strings

{{{1}}} = A, {{{2}}} = B, {{{3}}} = C

<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>
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. BC (integer, numerator and denominator)
{{frac|A|B}}
AB (numerator and denominator)
{{frac|A}}
1A (denominator only)
{{frac}}
(fraction slash only)

Examples

Numbers
121323143415253545165617273747576718385878116316516716916111613161516
Units
mskmhkg·m1sMbits

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