function wikiplugin_equation($data, $params) { if (empty($data)) { return ''; } extract($params, EXTR_SKIP); if (empty($size)) { $size = 100; } $latexrender_path = getcwd() . "/lib/equation"; include_once $latexrender_path . "/class.latexrender.php"; $latexrender_path_http = "lib/equation"; $latex = new LatexRender($latexrender_path . "/pictures", $latexrender_path_http . "/pictures", $latexrender_path . "/tmp"); $latex->_formula_density = 120 * $size / 100; extract($params, EXTR_SKIP); $data = html_entity_decode(trim($data), ENT_QUOTES); $url = $latex->getFormulaURL($data); $alt = "~np~" . $data . "~/np~"; if ($url != false) { $html = "<img src=\"{$url}\" alt=\"{$alt}\" style=\"vertical-align:middle\">"; } else { $html = "__~~#FF0000:Unparseable or potentially dangerous latex formula. Error {$latex->_errorcode} {$latex->_errorextra}~~__"; } return $html; }
function latex_content($text) { global $config; // -------------------------------------------------------------------------------------------------- // adjust this to match your system configuration $latexrender_path = dirname(__FILE__); $latexrender_path_http = $config["base_path"] . "/functions/latexrender"; // -------------------------------------------------------------------------------------------------- include_once $latexrender_path . "/class.latexrender.php"; preg_match_all("#\\[tex\\](.*?)\\[/tex\\]#si", $text, $tex_matches); $latex = new LatexRender($latexrender_path . "/pictures", $latexrender_path_http . "/pictures", $latexrender_path . "/tmp"); for ($i = 0; $i < count($tex_matches[0]); $i++) { $pos = strpos($text, $tex_matches[0][$i]); $latex_formula = $tex_matches[1][$i]; // if you use htmlArea to input the text then uncomment the next 6 lines $latex_formula = str_replace("&", "&", $latex_formula); $latex_formula = str_replace("&", "&", $latex_formula); $latex_formula = str_replace(" ", " ", $latex_formula); $latex_formula = str_replace("<BR>", "", $latex_formula); $latex_formula = str_replace("<P>", "", $latex_formula); $latex_formula = str_replace("</P>", "", $latex_formula); $url = $latex->getFormulaURL($latex_formula); $alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES); $alt_latex_formula = str_replace("\r", " ", $alt_latex_formula); $alt_latex_formula = str_replace("\n", " ", $alt_latex_formula); if ($url != false) { $text = substr_replace($text, "<img src='" . $url . "' title='" . $alt_latex_formula . "' alt='" . $alt_latex_formula . "' align=absmiddle>", $pos, strlen($tex_matches[0][$i])); } else { $text = substr_replace($text, "[Unparseable or potentially dangerous latex formula. Error {$latex->_errorcode} {$latex->_errorextra}]", $pos, strlen($tex_matches[0][$i])); } } return $text; }
/** * Callback function for preg_replace_callback (LaTeX replacement). * Returns replacement image for LaTeX code. * @param $matches (string) array containing matches: $matches[0] is the complete match, $matches[1] the match for the first subpattern enclosed in '(...)' (the LaTeX code) * @return string replacement HTML code string to include the equivalent LaTeX image. */ function F_latex_callback($matches) { require_once '../../shared/code/tce_latexrender.php'; $latex = new LatexRender(); $latex_code = unhtmlentities($matches[1]); // get image URL $imgurl = $latex->getFormulaURL($latex_code); if ($imgurl) { // alternative text to image $alt_latex = '[LaTeX]' . "\n" . htmlentities($latex_code, ENT_QUOTES); $alt_latex = str_replace("\r", ' ', $alt_latex); $alt_latex = str_replace("\n", ' ', $alt_latex); // XHTML code for image $newtext = '<img src="' . $imgurl . '" alt="' . $alt_latex . '" class="tcecode" />'; } else { $newtext = '[LaTeX: ERROR ' . $latex->getErrorCode() . ']'; } return $newtext; }