sample-signals.html 4.3 KB

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