Help:Displaying a formula: Difference between revisions

Content deleted Content added
No edit summary
Tag: 2017 source edit
 
(6 intermediate revisions by the same user not shown)
Line 4:
[[File:Editing a formula using VisualEditor.png|thumb|This screenshot shows the formula {{math|1=''E'' = ''mc''{{smallsup|2}}}} being edited using [[wikipedia:VisualEditor|VisualEditor]]. The visual editor shows a button that allows to choose one of three offered modes to display a formula.]]
 
Math is rendered in EMEA Support Wiki's by TeX using Mathoid. There are three methods for displaying formulas in mediawiki: raw HTML, HTML with math templates (abbreviated here as {{tl|math}}), and a subset of LaTeX implemented with the HTML markup <syntaxhighlight lang="html5" inline><math></math></syntaxhighlight> (referred to as ''LaTeX'' in this article). Each method has some advantages and some disadvantages, which have evolved over the time with improvements of MediaWiki. The manual of style for math has not always evolved accordingly. So the how-to recommendations that appear below may differ from those of the manual of style.<ref>[[mediawikiwiki:Extension:Math/Help:Displaying a formula Formula|Extension:Math/Help:Displaying a formulaFormula (MetaMediawiki-Wiki)]]</ref>
<ref>[[wikisourcemetawikimedia:Help:Fractions_and_functionsDisplaying a formula |Help:Fractions_and_functionsDisplaying a formula (Wiki-Source)]]</ref>
<ref>[[wikipedia:Help:Displaying_a_formula |Help:Displaying_a_formula (Wikipedia) ]]</ref>
<ref>[https://web.archive.org/web/20160305074303/https://www.math.upenn.edu/tex-stuff/cookbook.pdf {{TeX}} Cookbook]{{space}}[[Media:Tex-cookbook.pdf | local copy]]</ref>
Line 1,306:
|}
 
== Color ==
Equations can use color: with the <code>\color</code> command. For example,
 
{| class="wikitable"
|-
! How it looks rendered
! Syntax
! Feature
|-
*:| <math>{\color{Blue}x^2}+{\color{YellowOrangeOrange}2x}-{\color{OliveGreenLimeGreen}1}</math>
| <syntaxhighlight lang="latex" inline>{\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1}</syntaxhighlight>
|
|-
*:| <math>x_{1,2}x=\frac{{\color{Blue}-b}\pm\sqrt{\color{Red}b^2-4ac}}{\color{Green}2a}</math>
| {{nowrap|1=<syntaxhighlight lang="latex" inline>x=\frac{{\color{Blue}-b}\pm\sqrt{\color{Red}b^2-4ac}}{\color{Green}2a}</syntaxhighlight>}}
|
|}
 
The <code>\color</code> command colors all symbols to its right.
*<code>{\color{Blue}x^2}+{\color{YellowOrange}2x}-{\color{OliveGreen}1}</code>
However, if the <code>\color</code> command is enclosed in a pair of braces (e.g. <code>{\color{Red}...}</code>) then no symbols outside of those braces are affected.
*:<math>{\color{Blue}x^2}+{\color{YellowOrange}2x}-{\color{OliveGreen}1}</math>
 
{| class="wikitable"
|-
! How it looks rendered
! Syntax
! Feature
|-
| <math>e^x\color{i red}\pi} + 1neq y= 0\,z</math>
| <syntaxhighlight lang="latex" inline>x\color{red}\neq y=z</syntaxhighlight>
|
Colors <span style="color:red;">red</span> everything to the right of <code><nowiki>\color{red}</nowiki></code>. To only color the <math>\neq</math> symbol red, place braces around <code><nowiki>\color{red}\neq</nowiki></code> or insert <code><nowiki>\color{black}</nowiki></code> to the right of <code><nowiki>\neq</nowiki></code>.
|-
| <math>x{\color{red}\neq} y=z</math>
| <syntaxhighlight lang="latex" inline>x{\color{red}\neq} y=z</syntaxhighlight>
|
|-
| <math>x\color{red}\neq\color{black} y=z</math>
| <syntaxhighlight lang="latex" inline>x\color{red}\neq\color{black} y=z</syntaxhighlight>
|
|-
| <math>\frac{-b\color{Green}\pm\sqrt{b^2\color{Blue}-4{\color{Red}a}c}}{2a}=x</math>
| {{nowrap|1=<syntaxhighlight lang="latex" inline>\frac{-b\color{Green}\pm\sqrt{b^2\color{Blue}-4{\color{Red}a}c}}{2a}=x</syntaxhighlight>}}
| The outermost braces in <code>{\color{Red}a}c</code> limit the affect of <code>\color{Red}</code> to the symbol <code>a</code>. Similarly, <code>\color{Blue}</code> does not affect any symbols outside of the <code>\sqrt{}</code> that encloses it, and <code>\color{Green}</code> does not affect any symbols outside of the numerator.
|}
 
There are several alternate notations styles
*<code>x_{1,2}=\frac{-b\pm\sqrt{\color{Red}b^2-4ac}}{2a}</code>
*:<math>x_{1,2}=\frac{-b\pm\sqrt{\color{Red}b^2-4ac}}{2a}</math>
 
{| class="wikitable"
 
It is also possible to change the background color (since [[rev:59550|r59550]]), as in the following example:
{| class=wikitable
|-
! How it looks rendered
! Background
! Syntax
! Wikicode
! Feature
! Rendering (in PNG)
|-
*| <codemath>{\color{Blue}x^2}+{\color{YellowOrangeOrange}2x}-{\color{OliveGreenLimeGreen}1}</codemath>
! rowspan=2 | White
| <syntaxhighlight lang="latex" inline>{\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1}</syntaxhighlight>
| <code>e^{i \pi} + 1 = 0</code>
| works with both texvc and MathJax
| <math>e^{i \pi} + 1 = 0\,</math>
|-
| <math>\color{Blue}x^2\color{Black}+\color{Orange}2x\color{Black}-\color{LimeGreen}1</math>
| <code>'''\definecolor{orange}{RGB}{255,165,0}\pagecolor{orange}'''e^{i \pi} + 1 = 0</code>
| {{nowrap|1=<syntaxhighlight lang="latex" inline>\color{Blue}x^2\color{Black}+\color{Orange}2x\color{Black}-\color{LimeGreen}1</syntaxhighlight>}}
| <math>\definecolor{orange}{RGB}{255,165,0}\pagecolor{orange}e^{i \pi} + 1 = 0\,</math></span>
| works with both texvc and MathJax
|-
| <math>\color{Blue}{x^2}+\color{Orange}{2x}-\color{LimeGreen}{1}</math>
! rowspan=2 | Orange
| <syntaxhighlight lang="latex" inline>\color{Blue}{x^2}+\color{Orange}{2x}-\color{LimeGreen}{1}</syntaxhighlight>
| <code>e^{i \pi} + 1 = 0</code>
| only works with MathJax
| style="background-color:orange;" | <math>e^{i \pi} + 1 = 0\,</math>
|-}
 
| <code>'''\definecolor{orange}{RGB}{255,165,0}\pagecolor{orange}'''e^{i \pi} + 1 = 0</code>
Some color names are predeclared according to the following table, you can use them directly for the rendering of formulas (or for declaring the intended color of the page background).
| style="background-color:orange;" | <math>\definecolor{orange}{RGB}{255,165,0}\pagecolor{orange}e^{i \pi} + 1 = 0\,</math>
 
Note that colorColor should not be used as the ''only'' way to identify something, because it will become meaningless on black-and-white media or for color-blind people. See [[Wikipedia:Manual of Style#Color coding]].
 
Latex does not have a command for setting the background color. The most effective way of setting a background color is by setting a CSS styling rule for a table cell:
<pre style="display: inline-block;">
{| class="wikitable" align="center"
| style="background-color: gray;" | <math>x^2</math>
| style="background-color:orange Goldenrod;" | <math>ey^{i \pi} + 1 = 0\,3</math>
|}
</pre>
 
Rendered as:
{| class="wikitable" align="center"
| style="background-color: gray;" | <math>x^2</math>
| style="background-color: Goldenrod;" | <math>y^3</math>
|}
 
Custom colors can be defined using:
<!--T:73-->
<syntaxhighlight lang="latex">\definecolor{myorange}{rgb}{1,0.65,0.4}\color{myorange}e^{i \pi}\color{Black} + 1 = 0</syntaxhighlight>
See here for [http://oregonstate.edu/%7Epeterseb/tex/samples/docs/color-package-demo.pdf all named colors] supported by LaTeX.
 
| :<codemath>'''\definecolor{orangemyorange}{RGBrgb}{2551,1650.65,0.4}\pagecolorcolor{orangemyorange}'''e^{i \pi}\color{Black} + 1 = 0</codemath>
<!--T:74-->
Note that color should not be used as the ''only'' way to identify something, because it will become meaningless on black-and-white media or for color-blind people. See [[Wikipedia:Manual of Style#Color coding]].
 
== Formatting issues == <!--T:75-->
Line 1,698 ⟶ 1,747:
\end{align}</math></syntaxhighlight>
}}
 
== References ==
{{Reflist}}