# Formula

Summary: Lightweight rendering of mathematical formulas in wiki pages
Version: 20220104
Prerequisites:
Status: Beta
Maintainer: Petko
Users: +1 (view / edit)
Discussion: Formula-Talk?

A very lightweight rendering of mathematical formulas in wiki pages (using Google Chart API).

## 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 the Google Charts service, so there is no need to install TeX processing packages.

 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 can be found with

## Installation

• Add to config.php such a line:
• FormulaBgColor = 'ffffff'; the RGB color code of the background, default is white ie "ffffff". To have a transparent background, use a RGBA color code with 2 zeros at the end, eg. 'ffffff00'. You can set CSS styles of the formula pictures in the file pmwiki/pub/css/local.css (if it doesn't exist you can create it):  img.formula { vertical-align:middle; } /* better alignment within text */ img.formula { margin: .1em .5em; } /* Vert+Hz distance from text */ img.formula { border: 1px solid #ddd;} /* thin gray border */  ## 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  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)  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) You can find more information about TeX at Wikipedia:TeX. It is possible to set the text and background colors of individual formulas, if the formula starts with #123456 color codes.  The #f00 code is red {$ #f00 e^x=\lim_{n\to\infty}$$1+\frac xn$$^n $} Text and background: {$ #008#eef (a+b)^2=a^2+2ab+b^2 $} Background only: {$ ##ffb \sum_{i=1}^ni=\frac{n(n+1)}2 \$}  The #f00 code is red Text and background: Background only:

To change the default black on white colors for the whole wiki see the section Configuration.

## Notes

• Each formula can have up to 200 characters.
• The answer to the Algebra question is, "An infinite number of solutions: x can be any number, except 3."

## Change log / Release notes

• 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.

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

• Recipe written and maintained by Petko (5ko [snail] 5ko [period] fr). The formula.php file is 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 .

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.