sample-signals.html (4406B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>MathJax Signals Test Page</title> 5 <!-- Copyright (c) 2010-2015 The MathJax Consortium --> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 7 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 8 <meta name="viewport" content="width=device-width, initial-scale=1"> 9 10 <!-- 11 | This example shows how to use MathJax's signal mechanism to find out 12 | about what MathJax is doing, and to hook into various events as they 13 | occur. 14 --> 15 16 <script type="text/x-mathjax-config"> 17 18 // 19 // Configure MathJax 20 // 21 MathJax.Hub.Config({ 22 extensions: ["tex2jax.js","TeX/noUndefined.js"], 23 jax: ["input/TeX","output/HTML-CSS"], 24 tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}, 25 TeX: {extensions: ["AMSmath.js","AMSsymbols.js"]} 26 }); 27 // 28 // Display messages when these files are loaded 29 // (Note the difference between extensions and TeX.extensions, 30 // and the difference between when noUndefind is loaded compared 31 // to when it signals that it is ready) 32 // 33 MathJax.Hub.Register.LoadHook("[MathJax]/extensions/TeX/noUndefined.js", 34 function () {MathJax.Hub.Startup.signal.Post("*** noUndefined Loaded ***")}); 35 MathJax.Hub.Register.LoadHook("[MathJax]/extensions/TeX/AMSmath.js", 36 function () {MathJax.Hub.Startup.signal.Post("*** AMSmath Loaded ***")}); 37 38 // 39 // Display a message that we are in the configuration code 40 // (The Message function is not yet defined when this code 41 // runs, so we can't use that here. Post a signal 42 // of our own, so it will be displayed along with all 43 // the other signals). 44 // 45 MathJax.Hub.Startup.signal.Post("*** In Startup Configuration code ***"); 46 47 // 48 // When the "onLoad" message is posted, display a message. 49 // (Since this hook is registered before the ones in the main body 50 // below, it runs before the code to print the "Startup: onLoad" 51 // message, so this message shows up first in the output.) 52 // 53 MathJax.Hub.Register.StartupHook("onLoad",function () { 54 Message("*** The onLoad handler has run, page is ready to process ***"); 55 }); 56 57 // 58 // This will be performed after MathJax has completed its 59 // setup and typesetting run, which have already been 60 // pushed onto the queue. 61 // (Since the Message function isn't defined yet when this code 62 // runs, we need to enclose it in a function so it will be 63 // looked up later when it is defined.) 64 // 65 MathJax.Hub.Queue(function () {Message("*** MathJax is done ***")}); 66 67 </script> 68 <script type="text/javascript" src="../MathJax.js"></script> 69 70 <style> 71 .output { 72 background-color: #F0F0F0; 73 border-top: 1px solid; 74 border-bottom: 1px solid; 75 padding: 3px 1em; 76 } 77 </style> 78 79 </head> 80 <body> 81 82 <p> 83 When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are 84 $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ 85 </p> 86 87 <p> 88 Messages about mathematics: 89 <pre id="MathMessages" class="output"> 90 </pre> 91 </p> 92 93 <p> 94 All Messages: 95 <pre id="AllMessages" class="output"> 96 </pre> 97 </p> 98 99 <script> 100 (function () { 101 // 102 // The output areas 103 // 104 var math = document.getElementById("MathMessages"); 105 var all = document.getElementById("AllMessages"); 106 107 // 108 // A function to display messages in the "AllMessages" area. 109 // We make it global so it can be used in the startup code above. 110 // 111 window.Message = function (message) { 112 MathJax.HTML.addText(all,message); 113 MathJax.HTML.addElement(all,"br"); 114 }; 115 116 // 117 // Find out about "New Math" messages from the Hub and display them. 118 // (Look up the TeX code for each new math element) 119 // 120 MathJax.Hub.Register.MessageHook("New Math",function (message) { 121 var script = MathJax.Hub.getJaxFor(message[1]).SourceElement(); 122 MathJax.HTML.addText(math,message.join(" ")+": '"+script.text+"'"); 123 MathJax.HTML.addElement(math,"br"); 124 }); 125 126 // 127 // Find out about ALL startup and hub messages 128 // 129 MathJax.Hub.Startup.signal.Interest(function (message) {Message("Startup: "+message)}); 130 MathJax.Hub.signal.Interest(function (message) {Message("Hub: "+message)}); 131 // 132 // Since signals are remembered, registering an interest will cause 133 // use to receive all the past signals as well as new ones. 134 // This marks the point were the above routines were called. 135 // 136 Message("##### events above this have already occurred #####"); 137 138 })(); 139 </script> 140 141 </body> 142 </html>