Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

ASCIIMath

Summary: Display MathML rendered ascii formula into PmWiki 2.x pages
Version: 20061028
Status: Stable
Prerequisites: pmwiki-2.0.beta24 and IE6 + MathPlayer or Netscape7.1/Mozilla/Firefox with appropriates fonts
Maintainer: Dfaure
Categories: Markup Math
Download: asciimath.zipΔ

Question addressed by this recipe

Would you (or your students) like to easily produce good-looking math formulas on wiki pages using a simple calculator-style syntax ?

Description

asciimath.zipΔ will help you incorporating mathematical formulas on PmWiki pages with a minimum of fuss.

Notes and Comments

ASCIIMath recipe is based on ASCIIMathPHP by Steven Chan -> mailto:kc56 [snail] cornell [period] edu, a PHP port of ASCIIMathML.js from Peter Jipsen.

Installation

  1. Download and extract asciimath.zipΔ to the PmWiki's root directory.
  2. Make sure you have:
    • cookbook/asciimath.php file and cookbook/asciimath directory,
    • pub/asciimath directory (note to updaters: the pub/xsl directory is no more used).
  3. In your local/config.php file, you must include the asciimath.php script:
     include_once('cookbook/asciimath.php');
    

Optionally, you may keep the provided Cookbook text pages content (including this one) for further references.

Markup

Once installed, the following markups are available:

{$ %<parameters...>% formula $}
(:eqn <parameters...> :) [=
formula
=]
(:eqn <parameters...> :) 
formula
(:eqnend:)

with the following optional parameters:

  • height=PIXELS to set the height reserved for the formula,
  • num(=VALUE) to display (and eventually set) an equation number,

The markup parameters are filtered and all +... and -... unhandled options are silently discarded. All other parameters are forwarded to the MathML style definition.

Syntax

(Excerpt from ASCIIMathML.js : Syntax and List of Constants. Please refer to original site for complete references):

The syntax is very permissive and does not generate syntax errors. This allows mathematically incorrect expressions to be displayed, which is important for teaching purposes. It also causes less frustration when previewing formulas.

The parser uses no operator precedence and only respects the grouping brackets, subscripts, superscript, fractions and (square) roots. This is done for reasons of efficiency and generality. The resulting MathML code can quite easily be processed further to ensure additional syntactic requirements of any particular application.

The sample given on ASCIIMathML.js home page will be rendered with following page content:

'''Example:''' Solving the quadratic equation.

Suppose {$ %height=70px% ax^2+bx+c=0 text( with ) a!=0 $}

We first divide by ''a'' to get
{$ %num=1% x^2+b/ax+c/a=0 $}

Then we complete the square and obtain
{$ %num% x^2+b/ax+(b/(2a))^2-(b/(2a))^2+c/a=0 $}

The first three terms factor to give
{$ %num% (x+b/(2a))^2=(b^2)/(4a^2)-c/a $}

Now we take square roots on both sides and get
{$ %num% x+b/(2a)=+-sqrt((b^2)/(4a^2)-c/a) $}

Finally we move {$ b/(2a) $} to the right and simplify to
get the two solutions:
{$ %num=5% x_(1,2)=(-b+-sqrt(b^2-4ac))/(2a) $}

Example: Solving the quadratic equation.

Suppose

We first divide by a to get

(1)

Then we complete the square and obtain

(2)

The first three terms factor to give

(3)

Now we take square roots on both sides and get

(4)

Finally we move

to the right and simplify to get the two solutions:

(5)

Implementation considerations, Limitations

Currently, formulas are handled in a two step process:

  1. Generate formulas as XML files of MathML code into the pub/asciimath directory.
  2. Render generated formulas in wiki page via some <iframe> tags with the help of the pmathml.xsl and pmathmlcss.xsl stylesheets provided in the pub/asciimath directory.

A formula file is generated only if it didn't previously exist or if formula text has changed. In edition mode (?action=edit) formulas are inconditionnally generated to handle preview feedback.

An extra ?action=purgeqns is made available to allow some clean up of the pub/asciimath directory if needed.

Each formula is anchored no its own page with the name eqn_<number> (the order of apparition in the page).

Nota
ASCIIMathPHP is based on an outdated version of ASCIIMathML.js (v1.3). Despite the current version has been patched to support more ASCIIMathML.js features, some of them are still lacking or non-functional. You may ask the author for upgrades.

See also

Cookbook /
Formula  Lightweight rendering of mathematical formulas in wiki pages (Beta)
JsMath  Add markup to display and embed mathematical formulas in wiki pages using TeX. (Stable)
LaTeXMathML  Translating LaTeX math notation dynamically to Presentation MathML (Stable)
LinuxTex  Enable TeX markup
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)
SimpleJsMath  
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

Releases Notes

  • 2005-06-07 Initial version
  • 2005-08-20 Updated to modified ASCIIMathPHP v1.10 (patch submitted to the author), and fixed typo bugs.
  • 2005-09-04 Fixed <:vspace> hint with 2.0.0 and above.
  • 2006-01-30 Added missing stylesheet and reduced pub/ directory pollution. Minor tweaks.
  • 2006-03-07 Merging unreleased enhancements.
  • 2006-10-26 Add RecipeInfo data. Cleaned code.
  • 2006-10-28 Minor tweaks.

Comments

Note: This recipe seems to have a collision with with markup like {$pagetextvar}. In other words, it seems to currently be broken, and I can't see how to fix it except to disable that markup in asciimath.php. --stvltvs 12 Jan 2012

Is there a way to render mathematical expressions inline? --jody (April 22, 2008)

As far as I can see from the source code, not yet. The result is put into a DIV context, which implies a new paragraph. -- rainglasz (November 15, 2008)

I found another way to display math formula by wiky, which is a Markup Converter. The author is Stefan Goessner, http://goessner.net/articles/wiky/. Would someone like to write a recipt for this? Just simply input [$\pi$] to produce the math formula? Thanks! --xhf

Nothing is planned for now. --Dfaure

I am getting the following error:

 Warning: file_put_contents(/.../pub/asciimath/Main. ... .xml)
 [function.file-put-contents]:
 failed to open stream: Permiso denegado in
 /opt/lampp/htdocs/envmod/cookbook/asciimath.php on line 91

 Warning: Cannot modify header information - headers already sent
 by (output started at /opt/lampp/htdocs/envmod/cookbook/asciimath.php:91)
 in /opt/lampp/htdocs/envmod/pmwiki.php on line 885

Any idea about what the problem is? Thanks! Magdiel

The recipe should be able to write its temporary files into the 'pub/asciimath' directory. You should make sure that your php configuration as sufficient rights to do so --Dfaure April 29, 2007, at 04:34 AM

Just set the permissions on the pmwiki/pub/asciimath folder to 777, and Bob's your uncle! =P --Promsan August the 5th, 2010, at 16.06pm

What happens to the xml files created in pub/asciimath when I remove an equation from a page? Is it deleted or not?

The xml will stay there, until you trigger the action ?action=purgeqns which would empty the pub/asciimath directory when required.--Dfaure September 24, 2007, at 09:03 AM

I was using asciimath with no problem. But now I see only Greek letters in equations instead of Latin, in my page and in this page also! This happens when I browse the page with firefox (I have version 2.0.0.8) but not with IE. I have Greek language installed in my system but not as default. Please see:

User notes? : 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.

Edit - History - Print - Recent Changes - Search
Page last modified on January 12, 2012, at 01:43 PM