Difference between revisions of "User:TW466/MathJaxTest"

From CUGC Wiki
(Fix both formula and sample.)
(Apparently the MediaWiki:Common.js hack works now!)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
\(\LaTeX\) can be included in wiki articles by using <tt><nowiki><math>...</math></nowiki></tt> tags.
+
\(\LaTeX\) can be included in wiki articles by using <code><nowiki><math>...</math></nowiki></code> tags, <code>\<span></span>( ... \<span></span>)</code> or <code>\<span></span>[ ... \<span></span>]</code>.
  
For instance, the following line results in:
+
== <nowiki><math></nowiki> tags ==
<nowiki><math>x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}</math></nowiki>
 
<math>x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}</math>
 
  
<tt>\<span></span>( ... \<span></span>)</tt> can also be used as maths delimiters, for instance:
+
For instance, the following line...
<tt>\<span></span>( \nabla B = \nabla \cdot \vec Q \<span></span>)</tt>
+
 
becomes \( \nabla B = \nabla \cdot \vec Q \).
+
Quadratic equations of the form <nowiki><math>0 = ax^2 + bx + c</math></nowiki> can be solved by using <nowiki><math>x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}</math></nowiki>.
<nowiki><nowiki></nowiki> tags don't escape them unfortunately (but do escape <nowiki><math></nowiki> tags).
+
 
 +
...results in:
 +
 
 +
: Quadratic equations of the form <math>0 = ax^2 + bx + c</math> can be solved by using <math>x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}</math>.
 +
 
 +
== Brackets and display formulas ==
 +
 
 +
<code>\<span></span>[ ... \<span></span>]</code> results in a "display" formula instead of an "inline" one. This is best if the equation is meant to stand on its own, without surrounding flow text:
 +
\<span></span>[ x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a} \<span></span>]
 +
\[ x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a} \]
 +
 
 +
<code>\<span></span>( ... \<span></span>)</code> can also be used as delimiters for inline maths, for instance:
 +
<code>\<span></span>( \nabla B = \nabla \times \vec Q \<span></span>)</code>
 +
becomes \( \nabla B = \nabla \times \vec Q \).
 +
 
 +
== Escaping ==
 +
 
 +
<nowiki><nowiki></nowiki> tags don't escape the bracket delimiters unfortunately (but do escape <nowiki><math></nowiki> tags).
 +
 
 +
Brackets can be escaped by including a <code><nowiki><span></span></nowiki></code> between the <code>\</code> and the opening/closing bracket, like so:
 +
 
 +
<nowiki>\<span></span>( \nabla B = \nabla \times \vec Q \<span></span>)</nowiki>
 +
 
 +
== Chemical formulas ==
  
 
[https://www.mediawiki.org/wiki/Extension:SimpleMathJax SimpleMathJax] also supports [https://mhchem.github.io/MathJax-mhchem/ <nowiki><chem></nowiki> tags], like so:
 
[https://www.mediawiki.org/wiki/Extension:SimpleMathJax SimpleMathJax] also supports [https://mhchem.github.io/MathJax-mhchem/ <nowiki><chem></nowiki> tags], like so:
Line 14: Line 35:
 
<chem>CO2 + C -> 2 CO</chem>
 
<chem>CO2 + C -> 2 CO</chem>
  
Unfortunately, maths don't show up in editing previews. <nowiki><math></nowiki>-enclosed maths show up in grey, but \<span></span>(-enclosed maths aren't converted at all until the page is saved.
+
== Edit previews ==
 +
 
 +
Thanks to a hack in [[MediaWiki:Common.js]], maths now show up in edit previews.

Latest revision as of 17:08, 12 March 2019

\(\LaTeX\) can be included in wiki articles by using <math>...</math> tags, \( ... \) or \[ ... \].

<math> tags

For instance, the following line...

Quadratic equations of the form <math>0 = ax^2 + bx + c</math> can be solved by using <math>x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}</math>.

...results in:

Quadratic equations of the form [math]0 = ax^2 + bx + c[/math] can be solved by using [math]x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}[/math].

Brackets and display formulas

\[ ... \] results in a "display" formula instead of an "inline" one. This is best if the equation is meant to stand on its own, without surrounding flow text:

\[ x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a} \]

\[ x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a} \]

\( ... \) can also be used as delimiters for inline maths, for instance: \( \nabla B = \nabla \times \vec Q \) becomes \( \nabla B = \nabla \times \vec Q \).

Escaping

<nowiki> tags don't escape the bracket delimiters unfortunately (but do escape <math> tags).

Brackets can be escaped by including a <span></span> between the \ and the opening/closing bracket, like so:

\<span></span>( \nabla B = \nabla \times \vec Q \<span></span>)

Chemical formulas

SimpleMathJax also supports <chem> tags, like so:

<chem>CO2 + C -> 2 CO</chem>

[math]\ce{CO2 + C -> 2 CO}[/math]

Edit previews

Thanks to a hack in MediaWiki:Common.js, maths now show up in edit previews.