[=', '/\\{\\$(.*?)\\$\\}/e', "Keep('{\$'.PSS('$1').'\$}')"); Markup('{$$', '<{$', '/\\{\\$\\$(.*?)\\$\$\\}/se', "ProcessLatexEquation(PSS('$1'))"); # PmWiki rule for processing eqrefs. Markup('latexeqref', '>{$$', '/\\\\eqref\\{([^\\}]+)\\}/e', "ProcessEqref('$1')"); $HTMLHeaderFmt['MathJax'] = ''; $HTMLHeaderFmt['MathJax'] = ''; # The graphic is available from # http://www.pmichaud.com/pmwiki/pub/guiedit/math.gif . SDV($GUIButtons['math'],array(1000, '{$ ', ' $}', '\\\\sqrt{n}', '$GUIButtonDirUrlFmt/math.gif"$[Math formula (LaTeX/MimeTeX)]"')); # The map from reference name to the equation number. $mathjax_refarray = array(); # The current highest equation number. $mathjax_cur_ref = 1; # Process Latex DisplayEquations # # This handles equation cross-referencing, by extracting \labels and # inserting \tag's for explicit numbering. MathJax will only handle # one tag per equation, so this assign's the same number to all labels. function ProcessLatexEquation($equation) { global $mathjax_refarray, $mathjax_cur_ref; # Find all \label tags (especially the label names). preg_match_all('/\\\\label\\{(.*?)\\}/', $equation, $labelarray); # Remove all labels from the equation source. $eq = preg_replace('/\\\\label\\{.*?\\}/', '', $equation); # Store the equation number corresponding to every label. foreach ($labelarray[1] as $label) { $mathjax_refarray[$label] = $mathjax_cur_ref; } # Write out final equation source (including a single \tag, and html # anchor to it, if there were any labels found). if(count($labelarray[1]) == 0) { $retstr = Keep('{$$'.$eq.'$$}'); } else { $retstr = '[[#tag'.$mathjax_cur_ref.']]'.Keep('{$$ \\tag{'.$mathjax_cur_ref.'}'.$eq.'$$}'); $mathjax_cur_ref += 1; } return $retstr; } # Process \eqref's. This looks up the label to fetch the equation # number, and returns the formatted number, with a link to the actual # equation. function ProcessEqref($label) { global $mathjax_refarray; if(array_key_exists($label, $mathjax_refarray)) { $tagnum = $mathjax_refarray[$label]; return '([[#tag'.$tagnum.'|'.$tagnum.']])'; } else { return '(label '.$label.' undefined)'; } }