This site is supported by donations to The OEIS Foundation.

Template:Frac

From OeisWiki
Jump to: navigation, search


Note: the former {{frac}} template is now {{fraction}}. (It displays either mixed fractions or simple fractions, though the presentation style is not suitable for mathematics documents!)


Note: to get a smaller fraction, the {{tfrac}} (tiny fraction) template should be used, e.g. within {{frac}}, {{root}}, {{sqrt}}, etc.


The {{frac}} mathematical formatting template and/or mathematical function template gives an HTML+CSS or a LaTeX formatted rational expression and/or the numerical result of the rational expression.

Usage

{{frac|numerator|denominator}}

or

{{frac|numerator|denominator|format}}

where format is taken from

  • htm: text style HTML+CSS rational expression (default);
  • HTM: display style HTML+CSS rational expression;
  • tex: text style LaTeX rational expression;
  • TEX: display style LaTeX rational expression;
  • #: numerical result.

As an alternative to using LaTeX rendered as PNG images (with either tex or TEX options), the html or HTML options will render the rational expression as HTML+CSS. You must use the {{frac}} template within the {{math}} template, which completes the formatting for mathematical expressions. (Do not use this option inside <math>...</math> tags.)

NOTE: To get rendered LaTeX, you must use the {{math}} template, since you cannot evaluate templates, parser functions or magic words inside <math>...</math> tags.

Minus sign issue

  • Use {{op|-}} for minus sign (instead of -, the hyphen, hyphus or hyphen minus sign {{dash|hyphus}}) in the provided mathematical expression (because the border-top used to make the vinculum of radicals in the {{root}} template turns out to be made out of hyphens -, and we need to convert the {{dash|hyphus}} into proper {{dash|minus}} − signs for the HTML+CSS renderings).
  • The {{op|-}} is replaced by a proper minus sign {{sym|-}} (i.e. {{dash|minus}}) in the {{math}} template for the HTML+CSS renderings (for LaTeX renderings, the {{dash|hyphus}} is properly turned into {{dash|minus}} by the LaTeX software).

Examples

Value of \frac{22}{7}

: before {{math|{{frac|22|7|#}}{{...|ldots}}|&}} after yields the text style HTML+CSS

before 
3.1428571428571
after

: before {{math|{{frac|22|7|#}}{{...|ldots|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|22|7|#}}{{...|ldots}}|&&}} yields the display style HTML+CSS

3.1428571428571

: {{math|{{frac|22|7|#}}{{...|ldots|tex}}|$$}} yields the display style LaTeX

\frac{22}{7}

: before {{math|{{tfrac|22|7}}|&}} after yields the text style HTML+CSS

before 
22
7
after

: before {{math|{{tfrac|22|7|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|22|7|HTM}}|&&}} yields the display style HTML+CSS

22
7

: {{math|{{frac|22|7|TEX}}|$$}} yields the display style LaTeX

\frac{22}{7} = value of \frac{22}{7}

: before {{math|{{tfrac|22|7}} {{=}} {{frac|22|7|#}}{{...|ldots}}|&}} after yields the text style HTML+CSS

before 
22
7
= 3.1428571428571
after

: before {{math|{{frac|22|7|tex}} {{=}} {{frac|22|7|#}}{{...|ldots|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|22|7|HTM}} {{=}} {{frac|22|7|#}}{{...|ldots}}|&&}} yields the display style HTML+CSS

22
7
= 3.1428571428571

: {{math|{{frac|22|7|TEX}} {{=}} {{frac|22|7|#}}{{...|ldots|tex}}|$$}} yields the display style LaTeX

\frac{\pi + 1}{ \tfrac{22}{7} + 1 }

: before {{math|{{frac|{{Gr|pi}} + 1|{{tfrac|22|7}} + 1}}|&}} after yields the text style HTML+CSS

before 
π + 1
22
7
+ 1
after

: before {{math|{{frac|{{Gr|pi|tex}} + 1|{{frac|22|7|tex}} + 1|tex}}|$}} after yields the text style LaTeX

before after

: {{math| {{frac|{{Gr|pi}} + 1|{{tfrac|22|7}} + 1|HTM}}|&&}} yields the display style HTML+CSS

π + 1
22
7
+ 1

: {{math| {{frac|{{Gr|pi|TEX}} + 1|{{frac|22|7|tex}} + 1|TEX}}|$$}} yields the display style LaTeX

1 + \frac{22}{60} + \frac{7}{60^2} + \frac{42}{60^3} + \frac{33}{60^4} + \frac{4}{60^5} + \frac{40}{60^6}

: before {{math|1 + {{tfrac|22|60}} + {{tfrac|7|60{{^|2}}}} + {{tfrac|42|60{{^|3}}}} + {{tfrac|33|60{{^|4}}}} + {{tfrac|4|60{{^|5}}}} + {{tfrac|40|60{{^|6}}}}|&}} after yields the text style HTML+CSS

before 
1 +
22
60
+
7
60 2
+
42
60 3
+
33
60 4
+
4
60 5
+
40
60 6
after

: before {{math|1 + {{frac|22|60|tex}} + {{frac|7|60{{^|2|tex}}|tex}} + {{frac|42|60{{^|3|tex}}|tex}} + {{frac|33|60{{^|4|tex}}|tex}} + {{frac|4|60{{^|5|tex}}|tex}} + {{frac|40|60{{^|6|tex}}|tex}}|$}} after yields the text style LaTeX

before after

{{math|1 + {{frac|22|60}} + {{frac|7|60{{^|2}}}} + {{frac|42|60{{^|3}}}} + {{frac|33|60{{^|4}}}} + {{frac|4|60{{^|5}}}} + {{frac|40|60{{^|6}}}}|&&}} yields the display style HTML+CSS

1 +
22
60
+
7
60 2
+
42
60 3
+
33
60 4
+
4
60 5
+
40
60 6

{{math|1 + {{frac|22|60|tex}} + {{frac|7|60{{^|2|tex}}|tex}} + {{frac|42|60{{^|3|tex}}|tex}} + {{frac|33|60{{^|4|tex}}|tex}} + {{frac|4|60{{^|5|tex}}|tex}} + {{frac|40|60{{^|6|tex}}|tex}}|$$}} yields the display style LaTeX

\frac{j_2}{k^2}

: before {{math|{{frac|''j''{{sub|2}}|''k''{{^|2}}}}|&}} after yields the text style HTML+CSS

before 
j2
k 2
after

: before {{math|{{frac|''j''{{sub|2|tex}}|''k''{{^|2|tex}}|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''j''{{sub|2}}|''k''{{^|2}}|HTM}}|&&}} yields the display style HTML+CSS

j2
k 2

: {{math|{{frac|''j''{{sub|2|TEX}}|''k''{{^|2|TEX}}|TEX}}|$$}} yields the display style LaTeX

\frac{p}{q}

: before {{math|{{frac|''p''|''q''}}|&}} after yields the text style HTML+CSS

before 
p
q
after

: before {{math|{{frac|''p''|''q''|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''p''|''q''|HTM}}|&&}} yields the display style HTML+CSS

p
q

: {{math|{{frac|''p''|''q''|TEX}}|$$}} yields the display style LaTeX

\frac{d}{q}

: before {{math|{{frac|''d''|''q''}}|&}} after yields the text style HTML+CSS

before 
d
q
after

: before {{math|{{frac|''d''|''q''|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''d''|''q''|HTM}}|&&}} yields the display style HTML+CSS

d
q

: {{math|{{frac|''d''|''q''|TEX}}|$$}} yields the display style LaTeX

\frac{q}{d}

: before {{math|{{tfrac|''q''|''d''}}|&}} after yields the text style HTML+CSS

before 
q
d
after

: before {{math|{{tfrac|''q''|''d''|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''q''|''d''|HTM}}|&&}} yields the display style HTML+CSS

q
d

: {{math|{{frac|''q''|''d''|TEX}}|$$}} yields the display style LaTeX

\frac{x^2 + 1}{3}

: before {{math|{{tfrac|''x''{{^|2}} {{op|+}} 1|3}}|&}} after yields the text style HTML+CSS

before 
x 2  +  1
3
after

: before {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} 1|3|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''x''{{^|2}} {{op|+}} 1|3|HTM}}|&&}} yields the display style HTML+CSS

x 2 + 1
3

: {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} 1|3|TEX}}|$$}} yields the display style LaTeX

\frac{x^2 + 1}{y^3 - 1}

: before {{math|{{frac|''x''{{^|2}} {{op|+}} 1|''y''{{^|3}} {{op|-}} 1}}|&}} after yields the text style HTML+CSS

before 
x 2  +  1
y 3  −  1
after

: before {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''x''{{^|2}} {{op|+}} 1|''y''{{^|3}} {{op|-}} 1|HTM}}|&&}} yields the display style HTML+CSS

x 2 + 1
y 3 − 1

: {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|TEX}}|$$}} yields the display style LaTeX

\frac{x^2 + xy + 1}{y^3 - 1}

: before {{math|{{tfrac|''x''{{^|2}} {{op|+}} ''x''{{sp|1}}''y'' {{op|+}} 1|''y''{{^|3}} {{op|-}} 1}}|&}} after yields the text style HTML+CSS

before 
x 2  +  xy  +  1
y 3  −  1
after

: before {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} xy {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''x''{{^|2}} {{op|+}} ''x''{{sp|1}}''y'' {{op|+}} 1|''y''{{^|3}} {{op|-}} 1|HTM}}|&&}} yields the display style HTML+CSS

x 2 + xy + 1
y 3 − 1

: {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} xy {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|TEX}}|$$}} yields the display style LaTeX

\frac{x^2 + \sqrt{xy} + 1}{y^3 - 1}

: before {{math|{{frac|''x''{{^|2}} {{op|+}} {{sqrt|''xy''}} {{op|+}} 1|''y''{{^|3}} {{op|-}} 1}}|&}} after yields the text style HTML+CSS

before 
x 2  + 
2  xy
 +  1
y 3  −  1
after

: before {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} {{sqrt|xy|tex}} {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''x''{{^|2}} {{op|+}} {{sqrt|''xy''}} {{op|+}} 1|''y''{{^|3}} {{op|-}} 1|HTM}}|&&}} yields the display style HTML+CSS

x 2 +
2  xy
+ 1
y 3 − 1

: {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} {{sqrt|xy|tex}} {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|TEX}}|$$}} yields the display style LaTeX

\frac{x^2 + \sqrt{xy} + 1}{ \sqrt[3]{y^3 - 1} }

: before {{math|{{frac|''x''{{^|2}} {{op|+}} {{sqrt|''x''{{sp|1}}''y''}} {{op|+}} 1|{{root|''y''{{^|3}} {{op|-}} 1|3}}}}|&}} after yields the text style HTML+CSS

before 
x 2  + 
2  xy
 +  1
3  y 3  −  1
after

: before {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} {{sqrt|xy|tex}} {{op|+|tex}} 1|{{root|''y''{{^|3|tex}} {{op|-|tex}} 1|3|tex}}|tex}}|$}} after yields the text style LaTeX

before after

: {{math|{{frac|''x''{{^|2}} {{op|+}} {{sqrt|''x''{{sp|1}}''y''}} {{op|+}} 1|{{root|''y''{{^|3}} {{op|-}} 1|3}}|HTM}}|&&}} yields the display style HTML+CSS

x 2 +
2  xy
+ 1
3  y 3 − 1

: {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} {{sqrt|xy|tex}} {{op|+|tex}} 1|{{root|''y''{{^|3|tex}} {{op|-|tex}} 1|3|tex}}|TEX}}|$$}} yields the display style LaTeX

HTML compared with rendered LaTeX

: {{math|{{tfrac|''x''{{^|2}} {{op|+}} ''x''{{sp|1}}''y'' {{op|+}} 1|''y''{{^|3}} {{op|-}} 1}}|&}}, {{math|{{frac|''x''{{^|2|tex}} {{op|+|tex}} xy {{op|+|tex}} 1|''y''{{^|3|tex}} {{op|-|tex}} 1|tex}}|$}}

yields the text style HTML+CSS, the text style LaTeX

x 2  +  xy  +  1
y 3  −  1
,

: {{math|{{frac|''x''{{^|2}} {{op|+}} ''x''{{sp|1}}''y'' {{op|+}} 1|''y''{{^|3}} {{op|-}} 1|HTM}}|&&}}, {{math|{{frac|''x''{{^|2|tex}} + xy + 1|''y''{{^|3|tex}} {{op|-|tex}} 1|TEX}}|$$}}

yields the display style HTML+CSS, the display style LaTeX

x 2 + xy + 1
y 3 − 1
,

Euler’s number

The code

: {{math|''e'' {{=|sp}} {{lim|''n''->infty|HTM}} {{(|{{sp|-1}}{{frac|''n''{{^|''n''}}|''n''!|HTM}}|)|Big}}{{^|{{^|{{^|1{{op|/}}''n''|100%}}|100%}}}} {{=|sp}} <!--
-->{{lim|''n''->infty|HTM}} {{frac|''n''|{{root|''n''!|<big>''n''</big>{{sp|1}}}}|HTM}}{{sp|1}},
|tex = e = \lim_{n \to \infty} { \left( \frac{n^n}{n!} \right) }^{1/n} = \lim_{n \to \infty} \frac{n}{ \sqrt[n]{n!} },|&&}}

yields the display style HTML+CSS

e  = 
  
nn
n!
  
 1 / n  = 
n
n  n!
 ,

and with the $$ option, yields the display style LaTeX

Examples (improper usage)

These rational expressions cannot be [numerically] evaluated:

{{frac|1|x^2 + 1|#}} yields Expression error: Unrecognized word "x".
{{frac|x|x^2 + 1|#}} yields Expression error: Unrecognized word "x".

LaTeX cannot render HTML+CSS formatted expressions:

{{frac|1|''x''{{^|2}} + 1|TEX}} yields \frac{ 1 }{ x 2 + 1 }

whereas

{{frac|1|''x''{{^|2|tex}} + 1|TEX}} yields \frac{ 1 }{ x^{ 2 } + 1 }

and thus {{math|{{frac|1|''x''{{^|2}} + 1|TEX}}|$$}} yields Error: Failed to parse!

See also

  • {{frac}} (normal fraction)
  • {{tfrac}} (tiny fraction)
  • {{fraction}} (Displays either mixed fractions or simple fractions, though the presentation style is not suitable for mathematics documents!)