Help:Contributing/math

From Wikibase
Jump to navigation Jump to search

Languages: English · français · Esperanto

Mathematical expressions can be put on a page in two ways:

  • Math in page text — LaTeX written directly in the wikitext, delimited with $…$ (inline) or $$…$$ (display); typeset in the browser by MathJax.
  • Math snippets — an expression stored as an item with Special:AddMath, whose embeds render with KaTeX.

Which one to use

Math content should usually exist as in-page blocks: $…$ for inline math, $$…$$ for standalone blocks. Reserve Special:AddMath (semantic math snippets) for known formulas — the named, defining results worth citing and reusing — which should always exist as standalone semantic content blocks.

  • In-page math — inline variables and symbols in prose, mathematical demonstrations, worked steps, numerical examples and computations. A worked example is Power series: its general form is a semantic block, while all the demonstrations and numeric examples are in-page $$…$$ blocks.
  • Semantic snippets — the general/known formulas of a topic (e.g. the general form of a power series, a named series, a named equation). Create them with Special:AddMath and embed them on the page with {{#content:Q…}} so they render as standalone blocks.
  • Never write math as styled text — no raw ''a'', ''x''² or <sup>-subscript markup for mathematics. Use inline math instead: $a_0$, $x^2$.

Math in page text (MathJax)

Write LaTeX directly in the page text between delimiters:

Delimiter What it does
$…$ inline math inside a sentence
$$…$$ display math on its own line, centred
<math></math> inline math (tag form — works in templates)
The famous identity is $e^{i\pi} + 1 = 0$.

Result: The famous identity is $e^{i\pi} + 1 = 0$.

For a formula on its own line, use double dollars:

$$\int_0^1 x^2 \, dx = \frac{1}{3}$$

Result:

$$\int_0^1 x^2 \, dx = \frac{1}{3}$$

Rendering happens in your browser (MathJax). The raw LaTeX source is shown when JavaScript is unavailable or while the page is still loading.

Literal dollar signs

MathJax treats a balanced $…$ pair in prose as math. A lone dollar (prices, amounts) is escaped as \$:

The licence fee is \$5 per copy.

Code stays literal

Code blocks and inline code (Help:Contributing/code) are never typeset — dollars inside them stay literal:

price=$5.00

Math snippets (KaTeX, known formulas)

Adding an expression

Open Special:AddMath and fill the form:

Field What it is
Label A short description of the expression (e.g. E = mc² or "Newton's second law").
Content The LaTeX source. Enclosing delimiters ($…$, $$…$$, \(…\) or \[…\]) are stripped automatically on save — paste from Markdown or MediaWiki as-is.
Describes Optional: the concept the expression is about — search and pick the entity (several allowed, comma-separated).
Attributed to / Source / Date Provenance, same as quotations.

Click Preview to render the content with KaTeX before saving (the preview strips the delimiters exactly like the save step).

Saving creates the item and redirects to it.

From the item page, click Copy embed code and paste the snippet on any page; the expression renders as KaTeX (the raw LaTeX source is shown if JavaScript is unavailable).

Editing an expression

Open the expression's item page and click Edit content under the title — or go to Special:UpdateMath with the item's id (e.g. Special:UpdateMath/Q100). The content field shows the stored LaTeX exactly as entered (delimiters stay stripped), and the Preview button renders it with KaTeX before you save. Fields you leave blank keep their existing values.

See also