[=', '/\\{\\$(.*?)\\$\\}/', 'MathJaxInlineCallback'); function MathJaxEquationCallback($m) { return ProcessLatexEquation(PSS($m[1])); } Markup('{$$', '<{$', '/\\{\\$\\$(.*?)\\$\$\\}/s', 'MathJaxEquationCallback'); # PmWiki rule for processing eqrefs. function MathJaxLatexeqrefCallback($m) { return ProcessEqref($m[1]); } Markup('latexeqref', '>{$$', '/\\\\eqref\\{([^\\}]+)\\}/', 'MathJaxLatexeqrefCallback'); # $MathJaxConfigJS is the MathJax configuration block. global $MathJaxConfigJS; SDV($MathJaxConfigJS, 'MathJax.Hub.Config({ extensions: [ "tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js" ], jax: [ "input/TeX", "output/HTML-CSS" ], tex2jax: { inlineMath: [ [ "{$", "$}" ] ], displayMath: [ [ "{$$", "$$}" ] ] } });'); # $MathJaxUseCDN, if true, uses a CDN (content distribution network) to load # MathJax from the cloud, making it unnecessary to install MathJax locally in # your wiki.' global $MathJaxUseCDN; SDV($MathJaxUseCDN, false); # $MathJaxCDNURL is the URL of the MathJax distribution from the CDN. global $MathJaxCDNURL; SDV($MathJaxCDNURL, "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML"); # Inject the JavaScript into . global $HTMLHeaderFmt; if ($MathJaxUseCDN == true) { $HTMLHeaderFmt['MathJax'] = '' . "\n" . ''; } else { $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)'; } }