editor.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  5. <title>Mathematical term rewriting frontend</title>
  6. <script type="text/javascript" src="../../../build/external/jquery/jquery.min.js"></script>
  7. <script type="text/javascript" src="../../../external/mathjax/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full"></script>
  8. </head>
  9. <body>
  10. <style>
  11. html {
  12. background-color: #ccc;
  13. margin: 0;
  14. padding: 0;
  15. }
  16. body {
  17. margin: 0;
  18. padding: 20px;
  19. font: 16px/24px Verdana, Arial, sans;
  20. }
  21. .panel {
  22. border: 3px solid #bbb;
  23. background-color: #fff;
  24. width: 47%;
  25. position: absolute;
  26. }
  27. #input {
  28. float:left;
  29. left: 2%;
  30. }
  31. #input textarea {
  32. width: 100%;
  33. border: 0;
  34. margin: 0;
  35. padding: 0;
  36. height: 100%;
  37. overflow-y: visible;
  38. font: 16px/24px Verdana, Arial, sans;
  39. }
  40. #math {
  41. float:right;
  42. right: 2%;
  43. }
  44. .box {
  45. height: 380px;
  46. padding: 10px;
  47. }
  48. #math .box {
  49. height: 384px;
  50. padding: 0 10px;
  51. }
  52. </style>
  53. <div id="input" class="panel">
  54. <div class="box">
  55. <textarea id="MathInput"></textarea>
  56. </div>
  57. </div>
  58. <div id="math" class="panel">
  59. <div class="box" id="box" style="visibility:hidden">
  60. <div id="MathOutput">$${}$$</div>
  61. </div>
  62. </div>
  63. <script type="text/javascript">
  64. (function () {
  65. var QUEUE = MathJax.Hub.queue; // shorthand for the queue
  66. var math = null, box = null; // the element jax for the math output, and the box it's in
  67. // Hide and show the box (so it doesn't flicker as much)
  68. var hide_box = function () {box.style.visibility = "hidden"}
  69. var show_box = function () {box.style.visibility = "visible"}
  70. // Get the element jax when MathJax has produced it.
  71. QUEUE.Push(function () {
  72. math = MathJax.Hub.getAllJax("MathOutput")[0];
  73. box = document.getElementById("box");
  74. show_box();
  75. var trigger_update = true,
  76. input_box = document.getElementById("MathInput");
  77. input_box.onkeydown = input_box.onchange = function(e){
  78. trigger_update = true;
  79. };
  80. // The onchange event handler that typesets the math entered
  81. // by the user. Hide the box, then typeset, then show it again
  82. // so we don't see a flash as the math is cleared and replaced.
  83. var update_math = function (tex) {
  84. //var start = '\\begin{equation}\\begin{split}';
  85. //var end = '\\end{split}\\end{equation}';
  86. //tex = start + tex.replace(/\n/g, end + start) + end;
  87. tex = '\\displaystyle{' + tex.replace(/\n/g, '\\\\') + '}';
  88. QUEUE.Push(hide_box, ["Text", math, tex], show_box);
  89. }
  90. setInterval(function() {
  91. if (trigger_update) {
  92. trigger_update = false;
  93. update_math(input_box.value);
  94. }
  95. }, 50);
  96. });
  97. })();
  98. </script>
  99. </body>
  100. </html>