Formula
{$ \varphi=\frac{1+\sqrt{5}}{2} $}
A very lightweight rendering of mathematical formulas in wiki pages (using MathJax locally).
Description
This is a simple, small and lightweight recipe for displaying mathematical formulas in PmWiki pages. Authors write in the wiki page the TeX code of the formula inside a {$ ... $} block. The formula is rendered to a picture by a local copy of the MathJax SVG library.
Note, Google killed the Charts API, so the recipe now uses MathJax and was rewritten to the new Extensions format. See Notes.
The solutions of the equation {$ ax^2+bx+c=0 $} can be found with
{$ x_{1,2}=\frac{-b \pm \sqrt {b^2-4ac}}{2a} $}
|
The solutions of the equation {$ ax^2+bx+c=0 $} can be found with {$ x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a} $} |
Installation
If you have installed the old Formula recipe, please remove it from config.php.
This extension requires ExtensionHub.
Place Formula-2026-01-07.zip in the pmwiki/extensions directory on your server. Optionally you can unzip it.
Alternatively, you can clone the Git repo into pmwiki/extensions with such a command line: git clone --depth=1 https://github.com/5ko/Formula.git
Configuration
To enable the extension, navigate to SiteAdmin.ExtensionHub, locate the "Formula" row and press "Edit". On the new page, check the checkbox "Enable configuration" and near the bottom press "Save".
Usage
Just write the TeX code of the formula inside a {$ ... $} block:
Golden ratio
{$ \varphi = \frac{1 + \sqrt{5}}{2} \simeq 1,618034 $}
|
Golden ratio {$ \varphi=\frac{1+\sqrt{5}}{2}\simeq 1,618034 $} |
How many solutions this equation has? (9th grade Algebra class)
{$ 2 = \frac{(3-x) \times 2}{3-x} $}
|
How many solutions this equation has? (9th grade Algebra class) {$ 2=\frac{(3-x)\times 2}{3-x} $} |
Maximum allowed deformation of a concrete beam under charge (1st year Architecture class)
{$ f_{max} = {L \over \beta } = { M_{max} \times L^2 \over \alpha \times E \times I } \
= { ( q \times L^2 ) \times L^2 \times 12 \over 2 \times \mu^2 \times \alpha \times E \times b \times h^3 } $}
|
Maximum allowed deformation of a concrete beam under charge (1st year Architecture class) {$ f_{max}={L\over\beta}={M_{max}\times L^2\over\alpha\times E\times I}={(q\times L^2)\times L^2\times 12\over 2\times\mu^2\times\alpha\times E\times b\times h^3} $} |
You can find more information about TeX at Wikipedia:TeX.
It is possible to set the text and background colors of individual formulas, wrap these in WikiStyles:
Here is a red formula %red% {$ e^x=\lim_{n\to\infty}\(1+\frac xn\)^n $} %%
Text and background: %green bgcolor=#eef% {$ (a+b)^2=a^2+2ab+b^2 $} %%
Background only: %bgcolor=#fbb% {$ \sum_{i=1}^ni=\frac{n(n+1)}2 $} %%
|
Here is a red formula {$ e^x=\lim_{n\to\infty}(1+\frac xn)^n $} Text and background: {$ (a+b)^2=a^2+2ab+b^2 $} Background only: {$ \sum_{i=1}^ni=\frac{n(n+1)}2 $} |
Notes
- There may be slight differences between the current MathJax library and the previous Google Charts service.
- So far it seems that parentheses no longer need to be escaped with backslashes.
- A
\hspaceor\vspacemarkup needs to have the dimension in units like\vspace{9mm}rather than\vspace9. - There may be more.
- Versions before 2026-01-07 embedded pictures, and the text and background colors needed to be written inside the formula and be passed to the API. Now you can simply use WikiStyles.
- The new version adapts to the container font size, so you can have formulas in headings or again wrap them in WikiStyles with bigger or smaller fonts:
# %font-size=.7em% {$ ax^2+bx+c $} Smaller
# {$ ax^2+bx+c $} Normal size
# %font-size=1.2em% {$ ax^2+bx+c $} Bigger
|
|
- The answer to the Algebra question is, "An infinite number of solutions: x can be any number, except 3."
Change log / Release notes
- 2026-01-07 - Google has disabled the Chart API, so I rewrote this to be an extension using MathJax locally.
If you previously used Formula, please disable it before installing the extension. - 20220104 - Update for Cookbook:PmSyntax and Cookbook:CustomSyntax (2+spaces).
- 20211229 - Update for Cookbook:PmSyntax.
- 20211217a - Highlight some additional control characters in the formula.
- 20211217 - Minor simplification of the highlighting rules.
- 20211216 - Update for Cookbook:PmSyntax compatibility with highlighted attributes, special strings and meta.
- 20211215 - Update for Cookbook:PmSyntax compatibility.
- 20211214 - Change deprecated curly brackets in lines 50 - 54 (warning in PHP 7.4, Siegfried Seibert)
- 20180420 - Fixes for PHP 7.2.
- 20150405 - Fixes for PHP 5.5.
- 20111029a - Fixed bugs with special characters, added per-formula colors.
- 20111027 - Initial public release, ready to be tested.
See also
- Cookbook /
- AMmathjax Add markup to embed math using ASCII MATH by MathJax. (Stable)
- ASCIIMath Display MathML rendered ascii formula into PmWiki 2.x pages (Stable)
- FractionsPlus Adds simple markup to write fractions. (Maintained)
- JsMath Add markup to display and embed mathematical formulas in wiki pages using TeX. (Obsolete - use MathJax)
- LaTeXMathJax MathJax support for PmWiki (stable)
- LaTeXMathML Translating LaTeX math notation dynamically to Presentation MathML (Stable)
- LinuxTex Enable TeX markup
- LuaExecute Lets Lua scripts dynamically generate parts of your wiki page (Beta)
- MathJax Add markup to embed math using TeX syntax. (Stable)
- Mathtex Add markup to display and embed several lines of mathematical formulas in wiki pages (testing)
- MimeTeX Add markup to display and embed mathematical formulas in wiki pages (Stable)
- SageCell This allows you to embed an interactive SageCell into your webpage. Sage is an open source alternative to MathLab, Mathematica, and Maple. (Stable)
- SimpleJsMath Notes on modifying the jsMath for a skin (not a complete recipe)
- TrueLatex Enables interpretation and rendering of real LaTeX markups in PmWiki. Support for XeLaTex included in v1.8. (Working perfectly. Very simple to use, customizable and comes with lots of options.)
Contributors
- Extension written and maintained by Petko (5ko [snail] 5ko [period] fr).
- The old/classic recipe formula.php file was partly based on the MimeTex recipe, copyright 2004-2007 Patrick R. Michaud.
- If this recipe helps you or saves you time, you can help support its continued development by ♥ .
Comments
See discussion at Formula-Talk
User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.