Namespaces
Variants

Template:math/doc: Difference between revisions

From cppreference.com
No edit summary
Space Mission (talk | contribs)
m Helper templates: added {{sub}}, {{sub}} & examples.
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''Math''' template formats HTML- or wikimarkup generated mathematical formulas. The generated formula is displayed using the same-size font as the adjoining text. The template will prevent line-wrapping.
The wikimarkup generated mathematical formulas. The generated formula is displayed using the same-size font as the adjoining text.


=== Usage ===
{{|math|''''}} ''''.
Use this template to wrap an inline formula in wikitext.  Examples:
<pre>
{{math|''x''<sup>2</sup> + ''y''<sup>2</sup> {{=}} ''r''<sup>2</sup>}}
</pre>
: produces: {{math|''x''<sup>2</sup> + ''y''<sup>2</sup> {{=}} ''r''<sup>2</sup>}}
<pre>
{{math|{{mapply|sin <i>π</i>}} {{=}} 0}}
</pre>
: produces: {{math|{{mapply|sin <i>π</i>}} {{=}} 0}}. The coding "&lt;i>" puts italic font, same as "&lt;var>" but doesn't indicate that it's a variable.


<pre>
{{math|{{minteg|0|+∞|{{mexp|−''x''}} d''x''}} {{=}} 1}}
'''' {{math}}
</pre>
: produces: {{math|{{minteg|0|+∞|{{mexp|−''x''}} d''x''}} {{=}} 1}}


<pre>
{{||''''}} {{||}} {{|}}
'''{{math|{{frac|1|2}} − {{frac|1|3}} {{=}} {{frac|1|6}}}}'''
</pre>
: produces: '''{{math|{{frac|1|2}} {{frac|1|3}} {{=}} {{frac|1|6}}}}'''.  Note the triple-apostrophes have set the whole formula as bold.


<pre>
{{||}} {{||}} {{}}
{{math|({{mrad|2}})<sup>2</sup> {{=}} 2}}
</pre>
: produces: {{math|({{mrad|2}})<sup>2</sup> {{=}} 2}}.


===Use of equals-sign===
===-
If a single equals-sign ("=") is used, it will fail to render, instead showing "<nowiki>{{{1}}}</nowiki>". For example, the following template-coding would be invalid:
===
={
{{} }}


<pre>{{math|1 + 2 = 3}}</pre>
{{|}} produces {{|}}
: produces: {{math|1 + 2 = 3}}, which is invalid code


To resolve this, either: (a) Start the formula with "<code>1=</code>" as in:
{{|2=}}
<pre>{{math|1=1 + 2 = 3}}</pre>
{{|}} in {{}}
: produces: {{math|1=1 + 2 = 3}}, or else, (b) include the equals-sign in double-braces <nowiki>"{{=}}"</nowiki> as in:
{{|1+}} {{|1+}}
<pre>{{math|1 + 2 {{=}} 3}}</pre>
: produces: {{math|1 + 2 {{=}} 3}}.


=== Parameters ===
The following parameters are optional:
 
* <code>big=1</code> – This wil render the formula in a bigger fontsize, increased to 165%.
* <code>size=''font-size''</code> – Use this to specify your own fontsize.
<pre>
<nowiki>{{math|big=1|1 + 2 {{=}} 3}}</nowiki>
 
</pre>
: produces: {{math|big=1|1 + 2 {{=}} 3}}
 
======
<>=</>
<>
=
''''</>
<><nowiki>{{math|1|1{{=}} }}</nowiki></>
{{math|=1|
{{=}}
3}
}

Latest revision as of 13:50, 4 December 2024

The following templates are used to create wikimarkup generated mathematical formulas. The generated formula is displayed using the same-size font as the adjoining text.

{{math|source}} - creates a formula from the specified source.

Helper templates

The following templates can be in the source parameter of the {{math}} template to create advanced formatting.

  • {{sub|arg}} - creates subscript, e.g. {{sub|n}} results in n
  • {{sup|arg}} - creates superscript, e.g. {{sup|n}} results in n
  • {{su|p=superscript (optional)|b=subscript (optional)}} - creates superscript and/or subscript, e.g.:
    • {{su|p=superscript|b=subscript}} results in superscript
      subscript
    • {{su|p=superscript}} results in superscript
    • {{su|b=subscript}} results in subscript
  • {{mrad|arg}} - produces radicals, e.g. {{mrad|69}} results in 69
  • {{minteg|min |max |body }} - creates an integral, e.g.:
    • {{minteg|min|max|body}} results in max
      min
      body
    • {{minteg|-1|+1|asin(x)}} results in +1
      -1
      asin(x)
  • {{mexp|power}} - creates an exponent raised to power, e.g. {{mexp|power}} results in epower
  • {{mfrac|integer |numerator |denominator }} - creates a fraction, e.g.:
    • {{mfrac|integer|numerator|denominator}} results in integer
      numerator
      denominator
    • {{mfrac|3|1|4}} results in 3
      1
      4
  • {{mparen|left_paren |right_paren |row1 |row2 |... |style=style (optional)|rows=row_number_override (optional)}} -
    creates inline table with invisible borders and parentheses on the sides. E.g.

    line1
    line2
    line3


    left_paren and right_paren can be one of (){}[]. rows forces parentheses to span row_number_override rows. Currently 4 rows are supported. style denotes additional style for the content (row# elements).

Examples

Source Result
{{math|({{mrad|2}}){{su|p=2}} {{=}} 2}} (2)2
= 2
{{math|A{{su|p=12|b=3}}}} A12
3
{{math|{{minteg|0|+∞|{{mexp|−''x''}} d''x''}} {{=}} 1}} +∞
0
ex dx = 1
{{math|{{mfrac|1|2}} − {{mfrac|1|3}} {{=}} {{mfrac|1|6}}}}
1
2
1
3
=
1
6
{{mparen|(|}|line1|line2|line3}}

line1
line2
line3


{{mparen|{|]|line1|line2|style=font-style: italic;|rows=3}}

line1
line2