Wiki source for SimpleMathFormula


Show raw source

===Simple Math Formulae in Wikka===

This is, I'll readily admit, almost a direct steal from Wikini. It uses a rendering engine to convert simple math scripts to images. For details on syntax see http://wiki.algebra.com/index.php/Formula_plotting_feature_guide

Note that for multi-line actions to work you must modify wikka.php as per the instructions at TableAction (thanks JavaWoman, or I'd never have gotten this working).

Place the following code as a file ##actions/math.php##
%%(php)
<?php
/*
titre: Action Math pour Wikini
Auteur: Clément Seifert
License: GPL
slightly modified by GmBowen for Wikka
example: {{math expression="x^2/sqrt(sin(x))"}}
*/

$baseurl = "http://www.algebra.com/cgi-bin/plot-formula.mpl?expression=";
$fullurl = $baseurl . rawurlencode($expression);

echo "<img src=\"$fullurl\" alt=\"expression math\" valign=\"middle\"/>";

?>
%%

examples of actions that can be implemented in wikka are:
%%
{{math expression="x^2"}}
{{math expression="x^2/sqrt(sin(x))"}}
{{math expression="graph( 200, 200, -1, 10, -2, 2, sin( x ) )"}}
{{math expression="(x^2-x-2)*(x^2-x-2)/(x^2+2*x+1)/(x^2-4*x+4)"}}
{{math expression="int( e^(-x^2/2), dx, -infinity, pi )"}}
{{math expression="drawing( 400, 300, -10, 10, -10, 10,
locate( 0, 0, O( 0, 0 ) ),
circle( 5, -2, 2 ), circle( 5, -2, 0.1 ), locate( 5, -2, X ),
circle( 0, 0, 0.2 ),
rectangle( -8, -8, -4, -6 ),
locate( -9, 6, number_line( 350, -5, 5, 3.3, -2.212 ) ),
triangle( 3, -9, 6, -8, 5, -3 ),

triangle( -8, -5, -3, -4, -7, 0 ),
locate( -8.5, -5, A ), locate( -2.5, -4, B ), locate( -8, 0, C ),

line( -9, 9, -8, 7 ),
line( -8, 7, -7, 9 ),
line( -7, 9, -6, 7 ),
line( -6, 7, -5, 9 ),
line( -5, 9, -4, 7 )
)
"}}

{{math expression="(
matrix( 2, 3,
x, y,
x/2, y+3&1/2,
x^2, pi^e
)
)
"}}
{{math expression="sum( i^2+2x+1, 0+1+1, N+2 )"}}
%%

It's simple, fast and works like a charm. The syntax is easy for a non-mathematician like myself to learn.
----
CodeContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki