sample-signals.html 4.2 KB

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