Xeverything11 (talk | contribs)
m 132 revisions imported from mhdev:Template:Fraction/doc
 
(44 intermediate revisions by 25 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
<!--PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE-->
{{Uses TemplateStyles|Template:Fraction/styles.css}}
This template builds an alternative form of [[common fraction]]s. The template takes one, two, or three parameters: the optional integer (may be signed), the optional numerator and the required denominator; in this order.  
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''' <code>subst:</code>itute it. This template should '''not''' be used in science or mathematical articles, per [[MOS:FRAC]] and [[MOS:MATH#Fractions]]; use {{tl|sfrac}} instead. To allow numerical sorting of a column containing fractions, use {{tl|sortfrac}} instead. It is a combination of this template and {{tl|sort}}.
Please '''do not''' <code>subst:</code>itute it.
;<code><nowiki>{{frac|A|B|C}}</nowiki></code>: {{frac|A|B|C}} (integer, numerator and denominator)
;<code><nowiki>{{frac|A|B}}</nowiki></code>: {{frac|A|B}} (numerator and denominator)
;<code><nowiki>{{frac|A}}</nowiki></code>: {{frac|A}} (denominator only)
;<code><nowiki>{{frac}}</nowiki></code>: {{frac}} (fraction slash only)


==Examples==
; <code><nowiki>{{fraction|A|B|C}}</nowiki></code> : {{fraction|A|B|C}} (integer, numerator and denominator)
;Numbers: {{frac|2}} {{frac|3}} {{frac|2|3}} {{frac|4}} {{frac|3|4}} {{frac|5}} {{frac|2|5}} {{frac|3|5}} {{frac|4|5}} {{frac|6}} {{frac|5|6}} {{frac|7}} {{frac|2|7}} {{frac|3|7}} {{frac|4|7}} {{frac|5|7}} {{frac|6|7}} {{frac|8}} {{frac|3|8}} {{frac|5|8}} {{frac|7|8}} {{frac|16}} {{frac|3|16}} {{frac|5|16}} {{frac|7|16}} {{frac|9|16}} {{frac|11|16}} {{frac|13|16}} {{frac|15|16}}
; <code><nowiki>{{fraction|B|C}}</nowiki></code> : {{fraction|B|C}} (numerator and denominator)
;Units: {{frac|m|s}} {{frac|km|h}} {{frac|kg·m|s²}} {{frac|s}} {{frac|Mbit|s}}
; <code><nowiki>{{fraction|C}}</nowiki></code> : {{fraction|C}} (denominator only)
; <code><nowiki>{{fraction}}</nowiki></code> : {{fraction}} (fraction slash only)


==Deactivation and customization==
== Examples ==
Users who prefer to see fractions inline, e.g. "1&nbsp;2⁄3" instead of "{{frac|1|2|3}}", can turn off the effects of this template by adding the following code to [[Help:User style|their user stylesheet]]:
<!--the fractions are separated by commas that are only visible to screen readers because they do not read out the space separators here-->
<source lang="css">.frac > sup /* numerator */,
; Numbers : {{fraction|2}} {{fraction|3}} {{fraction|2|3}} {{fraction|4}} {{fraction|3|4}} {{fraction|5}} {{fraction|2|5}} {{fraction|3|5}} {{fraction|4|5}} {{fraction|6}} {{fraction|5|6}} {{fraction|7}} {{fraction|2|7}} {{fraction|3|7}} {{fraction|4|7}} {{fraction|5|7}} {{fraction|6|7}} {{fraction|8}} {{fraction|3|8}} {{fraction|5|8}} {{fraction|7|8}} {{fraction|16}} {{fraction|3|16}} {{fraction|5|16}} {{fraction|7|16}} {{fraction|9|16}} {{fraction|11|16}} {{fraction|13|16}} {{fraction|15|16}}
.frac > sub /* denominator */
; Units : {{fraction|m|s}} {{fraction|km|h}} {{fraction|kg·m|s<sup>2</sup>}} {{fraction|s}} {{fraction|Mbit|s}}
{
  vertical-align: inherit /* or baseline */;
  font-size: inherit /* or 1em */;
  line-height: inherit /* or 1 */;
  position: inherit /* or static */;
}</source><!--untested-->
<!-- The following would work if the fraction slash was enclosed in a <code>span</code>
These selectors and properties can also be used as a base for custom rendering of vulgar fractions:
<source lang="css">/* Stacked Fractions */
.frac {
  display: inline-block;
  vertical-align: -0.6em;
  font-size: 85%;
  text-align: center;
}
.frac > span /* fraction slash */ {
  display: none;
}


.frac > sup /* numerator */,
== Notes ==
.frac > sub /* denominator */ {
* <code><nowiki>{{fraction}}</nowiki></code> or <code>&amp;frasl;</code> may be used to print out the fraction slash glyph " &frasl; ".
  vertical-align: baseline;
* For mixed fractions, in some contexts (like link targets) a "+" is generated between the whole number part and fraction part. If this is not desirable, put the whole number part outside the template, and put a [[w:non-breaking space|non-breaking space]] between when the spacing is desirable. For example: "<nowiki>33&amp;nbsp;{{frac|1|3}}</nowiki>".
  line-height: 1.2em;
  font-size: 1em;
  position: static;
  display: block;
  padding: 0 0.1em;
}
.frac > sub {
  border-top: 1px solid;
}
</source>-->
 
== Code ==
<source lang=html5>
<span class="frac nowrap">{{#if:{{{3|}}}
|{{{1}}}<span class="visualhide">&nbsp;</span><sup>{{{2}}}</sup>&frasl;<sub>{{{3}}}</sub>
|{{#if:{{{2|}}}
  |<sup>{{{1}}}</sup>&frasl;<sub>{{{2}}}</sub>
  |{{#if:{{{1|}}}
  |<sup>1</sup>&frasl;<sub>{{{1}}}</sub>
  |&frasl;
  }}
}}
}}</span>
</source>
 
==Notes==
*<code><nowiki>{{frac}}</nowiki></code> or <code>&amp;frasl;</code> may be used to print out the fraction slash glyph " &frasl; ".


== Parameters ==
== Parameters ==
Line 89: Line 41:
}}</templatedata>
}}</templatedata>


==See also==
== See also ==
*[[Wikipedia:«math»]]
* {{tl|sfrac}} ({{sfrac|2}}) – displays common fractions using a [[w:vinculum (symbol)|vinculum]] (horizontal line), for scientific and mathematical text
*{{tl|1/2}} ({{1/2}}), {{tl|1/3}}, {{tl|2/3}}, {{tl|1/4}}, {{tl|3/4}} – shorthands that use this template
*{{tl|sfrac}} ({{sfrac|2}}) – displays common fractions using a [[vinculum (symbol)|vinculum]] (horizontal line), for scientific and mathematical text
* {{tl|su}} ({{su|p=superscript|b=subscript}} text) – to align both b=subscript & p=[[superscript]]
* {{tl|sub}} ({{sub|subscript}} text) – to show a [[subscript]]
* {{tl|sup sub}} (text{{sup sub|sup|sub}}) – for both 1=superscript & 2=subscript
*[[Help:Displaying a formula#Fractions, matrices, multilines]]
*[[Help:Convert#Fractions]]
{{Math templates|notation}}
{{Fractions and ratios}}
 


<includeonly>
<includeonly>
{{#ifeq:{{PAGENAME}}|Frac|
[[Category:Formatting templates]]
<!--CATEGORIES HERE, THANKS-->
</includeonly>
[[Category:Wikipedia formatting and function templates]]
[[Category:Mathematical formatting templates]]
}}</includeonly>

Latest revision as of 08:13, 8 April 2025

Template:Documentation subpage Template:Uses TemplateStyles 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.

{{fraction|A|B|C}}
A+BC (integer, numerator and denominator)
{{fraction|B|C}}
BC (numerator and denominator)
{{fraction|C}}
1C (denominator only)
{{fraction}}
(fraction slash only)

Examples

Numbers
12 13 23 14 34 15 25 35 45 16 56 17 27 37 47 57 67 18 38 58 78 116 316 516 716 916 1116 1316 1516
Units
ms kmh kg·ms2 1s Mbits

Notes

  • {{fraction}} or &frasl; may be used to print out the fraction slash glyph " ⁄ ".
  • For mixed fractions, in some contexts (like link targets) a "+" is generated between the whole number part and fraction part. If this is not desirable, put the whole number part outside the template, and put a non-breaking space between when the spacing is desirable. For example: "33&nbsp;{{frac|1|3}}".

Parameters

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