Pluf_Text_Latex_Equation Class Reference

List of all members.

Public Member Functions

 __construct ($output_dir=null, $tmp_dir=null)
 getFormulaURL ($latex_formula)
 getPreamble ()
 render ($latex_formula, $inline=false)
 clean ($tmp_filename)
 isCleanLatex ($latex)
 getOutputFile ($latex, $inline=false)

Public Attributes

 $tmp_dir = '/tmp'
 $output_dir = '/tmp'
 $encoding = 'utf-8'
 $fragment = ''
 $latex_path = '/usr/bin/latex'
 $dvipng_path = '/usr/bin/dvipng'
 $resolution = '120'
 $bg_color = 'ffffff'
 $debug = false
 $tags_blacklist
 $error_code = 0
 $error_msg = ''


Detailed Description

Given a shunk of a latex equation code, render it and return a corresponding image file.

Based on code by: Benjamin Zeiss Copyright (C) 2003 Benjamin Zeiss <zeiss@math.uni-goettingen.de> http://www.mayer.dial.pipex.com/tex.htm Kjell Magne Fauske http://www.fauskes.net/nb/htmleqII/

Example usage:

$latex = new Pluf_Text_Latex_Equation(); if (true === $latex->render('e = mc^2')) { $png_file = $latex->output_file; $png_full_path = $latex->output_path; } else { $error = $latex->error_code; $msg = $latex->error_msg; }

Note that the class is not using exception to return the errors, that way you can easily grab the error and depending on the error code/message generate a special .png file to display.


Constructor & Destructor Documentation

Pluf_Text_Latex_Equation::__construct ( output_dir = null,
tmp_dir = null 
)

Initializes the class

Parameters:
string Output directory (null)
string Temp directory (null)


Member Function Documentation

Pluf_Text_Latex_Equation::getFormulaURL ( latex_formula  ) 

Tries to match the LaTeX Formula given as argument against the formula cache. If the picture has not been rendered before, it'll try to render the formula and drop it in the picture cache directory.

Parameters:
string formula in LaTeX format
Returns:
the webserver based URL to a picture which contains the requested LaTeX formula. If anything fails, the resultvalue is false.

Pluf_Text_Latex_Equation::getPreamble (  ) 

Get the Latex preamble.

You can overwrite this function if you want.

Returns:
string Latex preamble.

Pluf_Text_Latex_Equation::render ( latex_formula,
inline = false 
)

Renders a LaTeX formula by the using the following method:

  • write the formula into a wrapped tex-file in a temporary directory and change to it
  • Create a DVI file using latex (tetex)
  • Convert DVI file to png or gif using dvipng
  • Save the resulting image to the picture cache directory using an md5 hash as filename. Already rendered formulas can be found directly this way.

Parameters:
string LaTeX formula
bool Render an inline formulat (false)
Returns:
true if the picture has been successfully saved to the picture cache directory

Pluf_Text_Latex_Equation::clean ( tmp_filename  ) 

Cleans the temporary directory

Pluf_Text_Latex_Equation::isCleanLatex ( latex  ) 

Check if the latex code is clean.

Parameters:
string Latex code.
Returns:
bool Is Clean.

Pluf_Text_Latex_Equation::getOutputFile ( latex,
inline = false 
)

Get the output file based on the latex fragment.

Parameters:
string Latex.
bool Is the equation an inline equation (false).
string Output file with extension without directory.


Member Data Documentation

Pluf_Text_Latex_Equation::$tmp_dir = '/tmp'

Pluf_Text_Latex_Equation::$output_dir = '/tmp'

Pluf_Text_Latex_Equation::$encoding = 'utf-8'

Pluf_Text_Latex_Equation::$fragment = ''

Pluf_Text_Latex_Equation::$latex_path = '/usr/bin/latex'

Pluf_Text_Latex_Equation::$dvipng_path = '/usr/bin/dvipng'

Pluf_Text_Latex_Equation::$resolution = '120'

Pluf_Text_Latex_Equation::$bg_color = 'ffffff'

Pluf_Text_Latex_Equation::$debug = false

Pluf_Text_Latex_Equation::$tags_blacklist

Initial value:

 array(
      'include', 'def', 'command', 'loop', 'repeat', 'open', 'toks', 'output',
      'input', 'catcode', 'name', '^^', '\\every', '\\errhelp',
      '\\errorstopmode', '\\scrollmode', '\\nonstopmode', '\\batchmode',
      '\\read', '\\write', 'csname', '\\newhelp', '\\uppercase', '\\lowercase',
      '\\relax', '\\aftergroup', '\\afterassignment', '\\expandafter',
      '\\noexpand', '\\special')
Black listing of tags.

this most certainly needs to be extended. in the long term it is planned to use a positive list for more security. this is hopefully enough for now. i'd be glad to receive more bad tags !

Pluf_Text_Latex_Equation::$error_code = 0

Pluf_Text_Latex_Equation::$error_msg = ''


The documentation for this class was generated from the following file:

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen