1<?php 2/** 3 * DokuWiki Plugin Math Action 4 * 5 */ 6 7if (!defined('DOKU_INC')) die(); 8require_once(__DIR__ . '/../webcomponent.php'); 9require_once(__DIR__ . '/../syntax/math.php'); 10 11/** 12 * Math 13 */ 14class action_plugin_webcomponent_math extends DokuWiki_Action_Plugin 15{ 16 17 18 /** 19 * Registers our handler 20 * @param Doku_Event_Handler $controller 21 */ 22 public function register(Doku_Event_Handler $controller) 23 { 24 25 $controller->register_hook( 26 'TPL_DOCUMENT_CLOSING', 27 'BEFORE', 28 $this, 29 'handle_closing', 30 array() 31 ); 32 33 34 } 35 36 /** 37 * * 38 * 39 * @param Doku_Event $event 40 * @param $param 41 */ 42 public function handle_closing(Doku_Event &$event, $param) 43 { 44 // config=TeX-MML-AM_CHTML 45 // where: 46 // Tex = TeX and LaTeX 47 // MML = MathML - http://www.w3.org/TR/MathML3 48 // AM = AsciiMath - http://asciimath.org/ 49 // CHTML = output using HTML with CSS 50 51 // Check metadata to see if there is a math syntax 52 // https://www.dokuwiki.org/devel:metadata#metadata_index 53 global $ID; 54 $isMathExpression = p_get_metadata($ID, syntax_plugin_webcomponent_math::MATH_EXPRESSION); 55 if ($isMathExpression) { 56 57 $math_div_id = webcomponent::PLUGIN_NAME . '_' . syntax_plugin_webcomponent_math::getComponentName(); 58 59 ptln('<div id="' . $math_div_id . '"">'); 60 ptln(DOKU_TAB . '<script type="text/x-mathjax-config"> 61 MathJax.Hub.Config({ 62 showProcessingMessages: true, 63 extensions: ["tex2jax.js"], 64 jax: ["input/TeX", "output/HTML-CSS"], 65 tex2jax: { 66 inlineMath: [ ["<math>","</math>"]], 67 displayMath: [ ["<MATH>","</MATH>"] ], 68 processEscapes: true, 69 scale:120 70 }, 71 "HTML-CSS": { fonts: ["TeX"] } 72 }); 73 </script>'); 74 ptln(DOKU_TAB . '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js" async></script>'); 75 ptln('</div>'); 76 } 77 78 } 79 80 81} 82 83