Wikipedia:TeX markup
From Wikipedia
- This page is deprecated but will be updated periodically.
- Please direct edits and discussion to the Meta-Wikimedia version of this page
- If you edit this page, please also add the edit to the MediaWiki version.
<< Wikipedia:Multimedia
As of January 2003, we have TeX markup for mathematical formulas on Wikipedia. It generates either PNG images or simple HTML markup, depending on user prefs and the complexity of the expression. In the future, as more browsers are smarter, it will be able to generate enhanced HTML or even MathML in many cases.
Math markup goes inside <math> ... </math>. Line breaks within these tags are fine, and aren't rendered. They're a good idea to keep the raw markup clear (for instance, a line break after each term or row of a matrix).
Discussion, bug reports and feature requests should go to the Wikitech-l mailing list or to Wikipedia:TeX requests.
For style issues regarding the typesetting of math, see Wikipedia:WikiProject Mathematics. In particular, please avoid using this feature as part of a line of regular text, as the formulas don't align properly and the font is too large.
Regarding color, notice that this page is a special page (its name begins with "Wikipedia:") and therefore when using some skins it has a blue or yellow background. Normal Wikipedia pages are white, just like the formulas, so don't worry.
Contents |
[խմբագրել] Special characters
(see also Wikipedia:Special characters)
Feature | Syntax | How it looks rendered |
---|---|---|
Accents/Diacritics | \acute{a} \quad \grave{a} \quad \breve{a} \quad \check{a} \quad \tilde{a} | |
Std. functions (good) |
\sin x + \ln y +\operatorname{sgn} z |
|
Std. functions (wrong) | sin x + ln y + sgn z | |
Modular arithmetic |
s_k \equiv 0 \pmod{m} |
|
Derivatives | \nabla \; \partial x \; dx \; \dot x \; \ddot y | |
Sets (Square symbols may not work for some wikis) |
\forall \; \exists \; \empty \; \emptyset \; \varnothing \in \ni \not\in \notin \subset \subseteq \supset \supseteq \cap \bigcap \cup \bigcup \biguplus |
|
\sqsubset \sqsubseteq \sqsupset \sqsupseteq \sqcap \sqcup \bigsqcup | ||
Logic | p \land \wedge \; \bigwedge \; \bar{q} \to p\lor \vee \; \bigvee \; \lnot \; \neg q \; \setminus \; \smallsetminus | |
Root | \sqrt{2}\approx 1.4 | |
\sqrt[n]{x} | ||
Relations | \sim \; \approx \; \simeq \; \cong \; \le \; \ge \; \equiv \; \not\equiv \; \ne \; \propto \; \pm \; \mp | |
Geometric | \Diamond \Box \triangle \angle \perp \mid \; \nmid \| \; 45^\circ | |
Arrows (Harpoons may not work for some wikis) |
\leftarrow \; \gets \; \rightarrow \; \to \; \leftrightarrow |
|
\rightharpoonup \; \rightharpoondown \; \leftharpoonup \; \leftharpoondown \; \upharpoonleft \; \upharpoonright \; \downharpoonleft \; \downharpoonright |
||
\Leftarrow \; \Rightarrow \; \Leftrightarrow |
|
|
Special |
\eth \; \S \; \P \; \% \; \dagger \; \ddagger \; \star \; * \; \ldots |
|
Lowercase \mathcal has some extras | \mathcal {45abcdenpqstuvwx} |
[խմբագրել] Subscripts, superscripts
Feature | Syntax | How it looks rendered | |
---|---|---|---|
Superscript | a^2 | a2 | |
Subscript | a_2 | a2 | |
Grouping | a^{2+2} | a2 + 2 | |
a_{i,j} | ai,j | ||
Combining sub & super | x_2^3 | ||
Preceding sub & super | {}_1^2\!X_3^4 | ||
Derivative (good) | x', y'' | x',y'' | |
Derivative (wrong in HTML) | x^\prime, y^{\prime\prime} | ||
Derivative (wrong in PNG) | x\prime, y\prime\prime | ||
Derivative dots | \dot{x}, \ddot{x} | ||
Underlines, overlines, vectors | \hat a \ \bar b \ \vec c \ \overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f} \ \overline{g h i} \ \underline{j k l} | ||
Overbraces |
\begin{matrix} 5050 \\ \overbrace{ 1+2+\cdots+100 } \end{matrix} |
||
Underbraces |
\begin{matrix} \underbrace{ a+b+\cdots+z } \\ 26 \end{matrix} |
||
Sum | \sum_{k=1}^N k^2 | ||
Product | \prod_{i=1}^N x_i | ||
Coproduct | \coprod_{i=1}^N x_i | ||
Limit | \lim_{n \to \infty}x_n | ||
Integral | \int_{-N}^{N} e^x\, dx | ||
Double integral | \iint_{D}^{W} \, dx\,dy | ||
Triple integral | \iiint_{E}^{V} \, dx\,dy\,dz | ||
Quadruple integral | \iiiint_{F}^{U} \, dx\,dy\,dz\,dt | ||
Path Integral | \oint_{C} x^3\, dx + 4y^2\, dy | ||
Intersections | \bigcap_1^{n} p | ||
Unions | \bigcup_1^{k} p |
[խմբագրել] Fractions, matrices, multilines
Feature | Syntax | How it looks rendered | ||||
---|---|---|---|---|---|---|
Fractions | \frac{2}{4} or {2 \over 4} | |||||
Binomial coefficients | {n \choose k} | |||||
Small Fractions | \begin{matrix} \frac{2}{4} \end{matrix} | |||||
Matrices | \begin{matrix} x & y \\ z & v \end{matrix} | |||||
\begin{vmatrix} x & y \\ z & v \end{vmatrix} | ||||||
\begin{Vmatrix} x & y \\ z & v \end{Vmatrix} | ||||||
\begin{bmatrix} 0 & \cdots & 0 \\ \vdots &
\ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} |
||||||
\begin{Bmatrix} x & y \\ z & v \end{Bmatrix} | ||||||
\begin{pmatrix} x & y \\ z & v \end{pmatrix} | ||||||
Case distinctions | f(n) = \left \{ \begin{matrix} n/2, & \mbox{if }n\mbox{ is
even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{matrix} \right. |
|||||
Multiline equations | \begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix} | |||||
Alternative multiline equations (using tables) |
{| |- |<math>f(n+1)</math> |<math>=(n+1)^2</math> |- | |<math>=n^2 + 2n + 1</math> |} |
|
[խմբագրել] Fonts
Feature | Syntax | How it looks rendered | |
---|---|---|---|
Greek alphabet (Note the lack of omicron; note also that several upper case Greek letters are rendered identically to the corresponding Roman ones) |
\Alpha\ \Beta\ \Gamma\ \Delta\ \Epsilon\ \Zeta\ \Eta\ \Theta\ \Iota\ \Kappa\ \Lambda\ \Mu\ \Nu\ \Xi\ \Pi\ \Rho\ \Sigma\ \Tau\ \Upsilon\ \Phi\ \Chi\ \Psi\ \Omega |
|
|
Blackboard bold | x\in\mathbb{R}\sub\mathbb{C} | ||
boldface (vectors) | \mathbf{x}\cdot\mathbf{y} = 0 | ||
boldface (greek) | \boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma} | ||
underline | \underline{xyz} | ||
italics | \mathit{ABCDE abcde 1234} | ||
Roman typeface | \mathrm{ABCDE abcde 1234} | ||
Fraktur typeface | \mathfrak{ABCDE abcde 1234} | ||
Calligraphy/Script | \mathcal{ABCDE abcde 1234} | ||
Hebrew alphabet | \aleph \beth \gimel \daleth | ||
non-italicised characters | \mbox{abc} | abc | |
mixed italics (bad) | \mbox{if} n \mbox{is even} | ifnis even | |
mixed italics (good) | \mbox{if }n\mbox{ is even} | if n is even |
[խմբագրել] Parenthesizing big expressions
Feature | Syntax | How it looks rendered |
---|---|---|
Not good | ( \frac{1}{2} ) | |
Better | \left ( \frac{1}{2} \right ) |
You can use various delimiters with \left and \right:
Feature | Syntax | How it looks rendered | |
---|---|---|---|
Parentheses | \left ( \frac{a}{b} \right ) | ||
Brackets | \left [ \frac{a}{b} \right ] \quad \left \lbrack \frac{a}{b} \right \rbrack | ||
Braces | \left \{ \frac{a}{b} \right \} \quad \left \lbrace \frac{a}{b} \right \rbrace | ||
Angle brackets | \left \langle \frac{a}{b} \right \rangle | ||
Bars and double bars | \left | \frac{a}{b} \right \vert \left \Vert \frac{c}{d} \right \| | ||
Floor and ceiling functions: | \left \lfloor \frac{a}{b} \right \rfloor \left \lceil \frac{c}{d} \right \rceil | ||
Slashes and backslashes | \left / \frac{a}{b} \right \backslash | ||
Up, down and up-down arrows | \left \uparrow \frac{a}{b} \right \downarrow \quad \left \Uparrow \frac{a}{b} \right \Downarrow \quad \left \updownarrow \frac{a}{b} \right \Updownarrow | ||
Delimiters can be mixed, |
\left [ 0,1 \right ) |
|
|
Use \left. and \right. if you don't want a delimiter to appear: |
\left . \frac{A}{B} \right \} \to X | ||
Size of the delimiters | \big( \Big( \bigg( \Bigg( ... \Bigg] \bigg] \Big] \big] | ||
\big\{ \Big\{ \bigg\{ \Bigg\{ ... \Bigg\rangle \bigg\rangle \Big\rangle \big\rangle | |||
\big\| \Big\| \bigg\| \Bigg\| ... \Bigg| \bigg| \Big| \big| | |||
\big\lfloor \Big\lfloor \bigg\lfloor \Bigg\lfloor ... \Bigg\rceil \bigg\rceil \Big\rceil \big\rceil | |||
\big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow ... \Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow |
[խմբագրել] Spacing
Note that TeX handles most spacing automatically, but you may sometimes want manual control.
Feature | Syntax | How it looks rendered |
---|---|---|
double quad space | a \qquad b | |
quad space | a \quad b | |
text space | a\ b | |
text space without PNG conversion | a \mbox{ } b | a b |
large space | a\;b | |
medium space | a\>b | [not supported] |
small space | a\,b | |
no space | ab | |
negative space | a\!b |
[խմբագրել] Align with normal text flow
If you desperately need to insert an equation like in the normal text flow, you can use a HTML <font> tag for vertical alignment:
- <font style="vertical-align:-100%;"><math>...</math></font>
[խմբագրել] Forced PNG rendering
If you must, it is possible to force the formula to render as PNG, without affecting the display of the formula, by adding \, (small space) at the end of the formula (where it is not rendered). This will force PNG if the user is in "HTML if simple" mode, but not for "HTML if possible" mode (math rendering settings in Preferences).
You can also use \,\! (small space and negative space, which cancel out) anywhere inside the math tags. This does force PNG in "HTML if possible" mode, unlike \,.
This could be useful to keep the rendering of formulae in a proof consistent, for example, or to fix formulae that render incorrectly in HTML (at one time, a^{2+2} rendered with an extra underscore), or to demonstrate how something is rendered when it would normally show up as HTML (as in the examples above).
For instance:
Syntax | How it looks rendered |
---|---|
a^{2+2} | a2 + 2 |
a^{2+2} \, | |
a^{\,\!2+2} | |
\int_{-N}^{N} e^x\, dx | |
\int_{-N}^{N} e^x\, dx \, | |
\int_{-N}^{N} e^x\, dx \,\! |
This has been tested with most of the formulae on this page, and seems to work perfectly.
You might want to include a comment in the HTML so people don't "correct" the formula by removing it:
- <!-- The \,\! is to keep the formula rendered as PNG instead of HTML. Please don't remove it.-->
[խմբագրել] See also
- Proposed GNU LilyPond support
[խմբագրել] External links
- A LaTeX tutorial. http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/
- A document introducing TeX -- see page 39 onwards for a good introduction to the maths side of things: http://www.ctan.org/tex-archive/info/gentle/gentle.pdf
- A PDF document introducing LaTeX -- skip to page 59 for the math section. See page 72 for a complete reference list of symbols included in LaTeX and AMS-LaTeX. http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
- TeX reference card: http://www.csit.fsu.edu/~mimi/tex/tex-refcard-letter.pdf
- Can't remember but I put it here so it must be ok ;-) http://www.ams.org/tex/amslatex.html
- A set of public domain fixed-size math symbol bitmaps: http://us.metamath.org/symbols/symbols.html
Next page: Editing toolbar >