Template:Math/doc: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>TheFrz
mNo edit summary
No edit summary
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{documentation subpage}}
{{Documentation subpage}}


The {{tlx|math}} template is a wrapper for {{code|<math>}} tag which is a part of the [[mediawikiwiki:Extension:Math|Extension:Math]]. The template is mainly used to change the default rendering colors (black text on white background) to custom ones that fit the color scheme of the wiki, but also brings additional functionality such as possibility of using another templates inside of {{code|<math>}} tags and support for [[#Numbered equations|numbered equations]].
This template is a wrapper for the <code><nowiki><math></nowiki></code> tag, which is implemented by the [[mw:Extension:Math|Math extension]]. It is generally preferable to use this template to display formulas as opposed to using <code><nowiki><math></nowiki></code> tags directly in wikitext. The primary purpose of this template is to change the default text rendering color so that formulas are legible on the wiki's dark background. This template provides some useful options for displaying formulas, such as indented and numbered blocks. Additionally, it allows parser functions and templates to be used inside of formulas.


For a detailed guide to LaTeX markup see [[wikipedia:Help:Displaying a formula|Help:Displaying a formula]].
__TOC__


==Usage==
==Usage==
Code <code><nowiki>{{math|2+3}}</nowiki></code> renders as: {{math|2+3}}
Use this template anywhere you wish to display formulas, equations, mathematical symbols, etc., as you would normally do using <code><nowiki><math></nowiki></code> tags. It is preferable to use this template instead of using <code><nowiki><math></nowiki></code> tags directly in wikitext.


===Parameters===
===Parameters===
The following parameters are available
{| class="wikitable"
{| class="wikitable"
! Parameter !! Description
! Parameter !! Optional !! Description
|-  
|-  
| <code><nowiki>|formula=</nowiki></code> || Use it if formula contains <code>=</code> sign.
| <code>1</code>, <code>formula</code>
| {{no}}
| LaTeX syntax used to designate the [[#Formula|formula]]
|-
|-
| <code><nowiki>|display=</nowiki></code> || [[wikipedia:Help:Displaying a formula#Display attribute|Display attribute]] with possible values:
| <code>display</code>
* {{code|block}}: equation is rendered in its own paragraph and has indent
| {{yes}}
* {{code|inline}}: there will be no new paragraph and the operators will be rendered to consume only a small amount of vertical space
| [[#Display options|Display option]] – Possible values are:
* not specified: no new paragraph and renders similar to {{code|block}}
* <code>block</code>: Renders formula display-style and displays it in its own paragraph
* <code>inline</code>: Displays formula inline with surrounding text. Renders text-style, for a smaller vertical footprint
* Default: Displays formula inline with surrounding text. Renders display-style
|-  
|-  
| <code><nowiki>|nr=</nowiki></code> || Activates numbered equations. Don't forget to use unique numbers. Use {{tlx|EquationNote}} to reference the numbered equation.
| <code>indent</code>
| {{yes}}
| How many times to indent the formula display. Used only if <code>display = block</code>
|-
| <code>ref</code>
| {{yes}}
| Label to reference the formula by. Typically used with {{tl|EquationRef}}. Requires <code>display = block</code>
|}
|}


===Basic usage===
===Formula===
{{for|more examples|Template:Math/testcases}}
The formula is written by providing [[wikipedia:Help:Displaying a formula#LaTeX basics|LaTeX syntax]] with <code>|formula=</code> or <code>|1=</code>.
====Display====
 
{| class="wikitable"
<pre>{{math|formula=E=mc^2}}</pre>
|
 
'''default'''
{{math|formula=E=mc^2}}
<pre>The sum {{math
 
|formula=\sum_{i=0}^\infty 2^{-i}
===Display options===
}} converges to 2.</pre>
====Default====
|
The default display option has <code>|display=</code> omitted or left blank. This option displays the formula inline with the surrounding text. The formula is rendered display-style.
 
<pre>The sum {{math|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.</pre>
 
The sum {{math|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
The sum {{math|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
|-
 
|
====Block====
'''block'''
With <code>|display=</code> set to <code>block</code>, the formula is always displayed in its own paragraph. The formula is rendered display-style.
<pre>The sum {{math
 
|display=block
<pre>The sum {{math|display=block|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.</pre>
|formula=\sum_{i=0}^\infty 2^{-i}
 
}} converges to 2.</pre>
|
The sum {{math|display=block|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
The sum {{math|display=block|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
|-
|
'''inline'''
<pre>The sum {{math
|display=inline
|formula=\sum_{i=0}^\infty 2^{-i}
}} converges to 2.</pre>
|
The sum {{math|display=inline|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
|}


===Advanced usage===
Use <code>|indent=</code> to specify the number of times to indent the formula display.
====Numbered equations====
 
The equations can be numbered using the <code>nr</code> parameter. The equation can then be referenced with {{tlx|EquationNote}}. For example:
<pre>{{math
|display = block
|indent = 1
|formula = u = \dfrac{1}{\sqrt{2} }(x+y)
}}</pre>


<pre>{{math|nr=1|formula=
{{math
x^2 + y^2 + z^2 = 1
|display = block
|indent = 1
|formula = u = \dfrac{1}{\sqrt{2} }(x+y)
}}
}}
Equation {{EquationNote|1}} shows the equation for an sphere centered around origo.</pre>
{{math|nr=1|formula=x^2 + y^2 + z^2 = 1}}
Equation {{EquationNote|1}} shows the equation for a [[wikipedia:Sphere|sphere]] centered around origo.


====Semantic queries====
Use <code>|ref=</code> to provide a label to reference the formula by. {{tl|EquationRef}} is typically used for this purpose in conjunction with {{tl|EquationNote}}.
With this template it is possible to use [[smw:Help:Inline queries|inline queries]] such as the parser functions <code>#ask</code>, <code>#show</code> and other [[mediawikiwiki:Help:Extension:ParserFunctions|parser functions]] such as <code>#expr</code>. For example:


<pre>
<pre>{{math
{{math|formula=
|display = block
Enfeeble Base Radius - Maximum Leech Rate Per Second + Maximum Endurance Charges
|ref = {{EquationRef|1|Eq. 1}}
  =          {{#show: Enfeeble |?Has primary radius=}} - {{#expr:{{#ask: [[-Has subobject::Character]] [[Has stat id::maximum_life_leech_rate_%_per_minute]] |?Has stat value#= |mainlabel=- |limit=1}} /60}} + {{SMW character query|stat=max_endurance_charges}}  
|formula = x^2 + y^2 + z^2 = 1
  = {{#expr: {{#show: Enfeeble |?Has primary radius=}} - {{#expr:{{#ask: [[-Has subobject::Character]] [[Has stat id::maximum_life_leech_rate_%_per_minute]] |?Has stat value#= |mainlabel=- |limit=1}} /60}} + {{SMW character query|stat=max_endurance_charges}} }}
}}
}}
</pre>


yields:
{{EquationNote|1|Equation 1}} shows the equation for a sphere centered on the origin.</pre>
{{math|formula=
 
Enfeeble Radius - Maximum Leech Rate Per Second + Maximum Endurance Charges
{{math
  =          {{#show: Enfeeble |?Has primary radius=}} - {{#expr:{{#ask: [[-Has subobject::Character]] [[Has stat id::maximum_life_leech_rate_%_per_minute]] |?Has stat value#= |mainlabel=- |limit=1}} /60}} + {{SMW character query|stat=max_endurance_charges}}
|display = block
  = {{#expr: {{#show: Enfeeble |?Has primary radius=}} - {{#expr:{{#ask: [[-Has subobject::Character]] [[Has stat id::maximum_life_leech_rate_%_per_minute]] |?Has stat value#= |mainlabel=- |limit=1}} /60}} + {{SMW character query|stat=max_endurance_charges}} }}
|ref = {{EquationRef|1|Eq. 1}}
|formula = x^2 + y^2 + z^2 = 1
}}
}}


==Limitations==
{{EquationNote|1|Equation 1}} shows the equation for a sphere centered on the origin.
===Error with multiple braces===
 
====Problem====
====Inline====
Placing multiple opening/closing braces together (e.g. <code>{{</code> or <code>}}</code>) if there are no closing/opening brackets, causes error. This happens because interpreter thinks they are a part of a template when in fact they are a part of a math markup. For example, the following code:
With <code>|display=</code> set to <code>inline</code>, the formula is displayed inline with the surrounding text. The formula is also rendered text-style, which takes up less vertical space.
{|
 
|
<pre>The sum {{math|display=inline|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.</pre>
<pre>{{math|formula=
 
DR(A, D_{raw}) = {A \over A + 10 \times D_{raw}}
The sum {{math|display=inline|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.
}}</pre>
 
|}
===Using queried data in formulas===
:{{math|formula=
Formulas may contain [[mw:Help:Extension:ParserFunctions|parser functions]] and templates. It is possible to query [[Special:CargoTables|certain game data]] with [[mw:Extension:Cargo/Querying_data|Cargo]] then display it inside of a formula. Doing so can help ensure that articles stay up to date.
DR(A, D_{raw}) = {A \over A + 10 \times D_{raw}}
 
}}
In the following example, the base value of the character stat <var>maximum_life_leech_rate_%_per_minute</var> is queried using {{tl|character query}} and defined as a variable called <var>life_leech_rate</var> with the <code>#vardefine</code> parser function. The value of <var>life_leech_rate</var> is used in an expression with <code>#var</code>. The expression is evaluated using <code>#expr</code>.
 
<pre>{{#vardefine:life_leech_rate| {{Character query|maximum_life_leech_rate_%_per_minute}} }}{{math|formula=
\begin{align}
M & = Maximum Leech Rate Per Minute / 60 \\
& = {{#var:life_leech_rate}} / 60 \\
& = {{#expr: {{#var:life_leech_rate}} / 60 }}
\end{align} }}</pre>
 
{{#vardefine:life_leech_rate| {{Character query|maximum_life_leech_rate_%_per_minute}} }}{{math|formula=
\begin{align}
M & = Maximum Leech Rate Per Minute / 60 \\
& = {{#var:life_leech_rate}} / 60 \\
& = {{#expr: {{#var:life_leech_rate}} / 60 }}
\end{align} }}
 
==Troubleshooting common problems==
There are several common problems that arise because LaTeX uses characters that are also used for transcluding templates in wikitext.
 
===Equals signs===
If the formula contains an equals sign (<code>=</code>), it is imperative to give the name of the formula parameter explicitly. Write <code>|1=</code> or <code>|formula=</code>.


====Solution====
{| class="wikitable"
In order to prevent this either space braces:
! Incorrect !! Correct
{|
|-
|
|
<pre>{{math|formula=
<pre>{{math|E=mc^2}}</pre>
DR(A, D_{raw}) = {A \over A + 10 \times D_{raw} }
}}</pre>
|
|
&nbsp;&nbsp;{{math|formula=DR(A, D_{raw}) = {A \over A + 10 \times D_{raw} } }}
<pre>{{math|1=E=mc^2}}</pre>
|-
| {{math|E=mc^2}}
| {{math|1=E=mc^2}}
|}
|}


or use the following templates:
===Consecutive closing braces===
* {{tlx|(}} - {{tlx|)}}
Multiple closing braces placed together (<code>}}</code>) are interpreted by the wikitext parser as being part of the syntax for template transclusion. If the formula syntax needs consecutive closing braces, they should be separated with a space.
* {{tlx|((}} - {{tlx|))}}
* {{tlx|(((}} - {{tlx|)))}}


{|
{| class="wikitable"
! Incorrect !! Correct
|-
|
|
<pre>{{math|formula=
<pre>{{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw}}}}</pre>
DR(A, D_{raw}) = {A \over A + 10 \times D_{raw{{))}}  
}}</pre>
|
|
&nbsp;&nbsp;{{math|formula=DR(A, D_{raw}) = {A \over A + 10 \times D_{raw{{))}} }}
<pre>{{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw} } }}</pre>
|-
| {{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw}}}}
| {{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw} } }}
|}
|}


===Absolute value denotation===
===Absolute value denotation===
====Problem====
The [[wikipedia:Absolute value|absolute value]] of {{math|x}} is denoted as {{math|\vert x \vert}}. The pipe character (<code>|</code>) is interpreted by the wikitext parser as being part of the syntax for template transclusion. Use <code>\vert</code> instead.
[[wikipedia:Absolute value|Absolute values]] are usually denoted |x|. However using <code>|</code> in templates will result in the following issue.
{|
|
<pre>{{math|formula=
|x|
}}</pre>
|
&nbsp;&nbsp;{{math|formula=|x|}}
|}


====Solution====
{| class="wikitable"
Use <code>\vert</code> or {{code|<nowiki>{{!}}</nowiki>}}:
! Incorrect !! Correct
{|
|-
|
|
<pre>{{math|formula=
<pre>{{math|formula=|x|}}</pre>
\vert x\vert
}}</pre>
|
|
&nbsp;&nbsp;{{math|formula=\vert x\vert}}
<pre>{{math|formula=\vert x \vert}}</pre>
|-
|-
|
| {{math|formula=|x|}}
<pre>{{math|formula=
| {{math|formula=\vert x \vert}}
{{!}}x{{!}}
}}</pre>
|
&nbsp;&nbsp;{{math|formula={{!}}x{{!}}}}
|}
|}


<includeonly>
==See also==
* [[wikipedia:Help:Displaying a formula|Help:Displaying a formula]] (A detailed guide to LaTeX markup)
 
{{Documentation categories|
<!-- Categories and interwikis go here. -->
[[Category:Formatting templates]]
[[Category:Formatting templates]]
</includeonly>
}}

Latest revision as of 10:15, 12 January 2022

This subpage provides documentation for Template:Math.

This template is a wrapper for the <math> tag, which is implemented by the Math extension. It is generally preferable to use this template to display formulas as opposed to using <math> tags directly in wikitext. The primary purpose of this template is to change the default text rendering color so that formulas are legible on the wiki's dark background. This template provides some useful options for displaying formulas, such as indented and numbered blocks. Additionally, it allows parser functions and templates to be used inside of formulas.

Usage

Use this template anywhere you wish to display formulas, equations, mathematical symbols, etc., as you would normally do using <math> tags. It is preferable to use this template instead of using <math> tags directly in wikitext.

Parameters

Parameter Optional Description
1, formula
LaTeX syntax used to designate the formula
display
Display option – Possible values are:
  • block: Renders formula display-style and displays it in its own paragraph
  • inline: Displays formula inline with surrounding text. Renders text-style, for a smaller vertical footprint
  • Default: Displays formula inline with surrounding text. Renders display-style
indent
How many times to indent the formula display. Used only if display = block
ref
Label to reference the formula by. Typically used with {{EquationRef}}. Requires display = block

Formula

The formula is written by providing LaTeX syntax with |formula= or |1=.

{{math|formula=E=mc^2}}

Display options

Default

The default display option has |display= omitted or left blank. This option displays the formula inline with the surrounding text. The formula is rendered display-style.

The sum {{math|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.

The sum converges to 2.

Block

With |display= set to block, the formula is always displayed in its own paragraph. The formula is rendered display-style.

The sum {{math|display=block|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.

The sum

converges to 2.

Use |indent= to specify the number of times to indent the formula display.

{{math
|display = block
|indent = 1
|formula = u = \dfrac{1}{\sqrt{2} }(x+y)
}}

Use |ref= to provide a label to reference the formula by. {{EquationRef}} is typically used for this purpose in conjunction with {{EquationNote}}.

{{math
|display = block
|ref = {{EquationRef|1|Eq. 1}}
|formula = x^2 + y^2 + z^2 = 1
}}

{{EquationNote|1|Equation 1}} shows the equation for a sphere centered on the origin.
(Eq. 1)

Equation 1 shows the equation for a sphere centered on the origin.

Inline

With |display= set to inline, the formula is displayed inline with the surrounding text. The formula is also rendered text-style, which takes up less vertical space.

The sum {{math|display=inline|formula=\sum_{i=0}^\infty 2^{-i} }} converges to 2.

The sum converges to 2.

Using queried data in formulas

Formulas may contain parser functions and templates. It is possible to query certain game data with Cargo then display it inside of a formula. Doing so can help ensure that articles stay up to date.

In the following example, the base value of the character stat maximum_life_leech_rate_%_per_minute is queried using {{character query}} and defined as a variable called life_leech_rate with the #vardefine parser function. The value of life_leech_rate is used in an expression with #var. The expression is evaluated using #expr.

{{#vardefine:life_leech_rate| {{Character query|maximum_life_leech_rate_%_per_minute}} }}{{math|formula=
\begin{align}
M & = Maximum Leech Rate Per Minute / 60 \\
& = {{#var:life_leech_rate}} / 60 \\
& = {{#expr: {{#var:life_leech_rate}} / 60 }}
\end{align} }}

Troubleshooting common problems

There are several common problems that arise because LaTeX uses characters that are also used for transcluding templates in wikitext.

Equals signs

If the formula contains an equals sign (=), it is imperative to give the name of the formula parameter explicitly. Write |1= or |formula=.

Incorrect Correct
{{math|E=mc^2}}
{{math|1=E=mc^2}}
No formula given.

Consecutive closing braces

Multiple closing braces placed together (}}) are interpreted by the wikitext parser as being part of the syntax for template transclusion. If the formula syntax needs consecutive closing braces, they should be separated with a space.

Incorrect Correct
{{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw}}}}
{{math|formula=DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw} } }}
Failed to parse (syntax error): \color[RGB]{163,141,109} DR(A, D_{raw}) = \frac{A}{A + 10 \times D_{raw }}

Absolute value denotation

The absolute value of is denoted as . The pipe character (|) is interpreted by the wikitext parser as being part of the syntax for template transclusion. Use \vert instead.

Incorrect Correct
{{math|formula=|x|}}
{{math|formula=\vert x \vert}}

See also