|  | 
|  | 1 | +<!DOCTYPE html> | 
|  | 2 | +<html> | 
|  | 3 | +<head> | 
|  | 4 | +  <title>Plotly.js Devtools - MathJax v3 loaded with chtml output</title> | 
|  | 5 | +  <p>MathJax $V^3$ with $chtml$ output on the page and <b>svg</b> output on the plotly graphs</p> | 
|  | 6 | +  <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Droid+Sans|PT+Sans+Narrow|Gravitas+One|Droid+Sans+Mono|Droid+Serif|Raleway|Old+Standard+TT"/> | 
|  | 7 | +  <link rel="stylesheet" type="text/css" href="./style.css"> | 
|  | 8 | +</head> | 
|  | 9 | +<body> | 
|  | 10 | +  <header> | 
|  | 11 | +    <img src="http://images.plot.ly/logo/[email protected] " onClick ="Tabs.reload(); " /> | 
|  | 12 | +    <span id="reload-time"></span> | 
|  | 13 | + | 
|  | 14 | +    <input id="mocks-search" type="text" placeholder="mocks search" /> | 
|  | 15 | +    <input id="css-transform" type="text" placeholder="css transform" /> | 
|  | 16 | +  </header> | 
|  | 17 | + | 
|  | 18 | +  <section id="mocks-list"></section> | 
|  | 19 | +  <div id="plots"> | 
|  | 20 | +    <div id="graph"></div> | 
|  | 21 | +  </div> | 
|  | 22 | +  <div id="snapshot"></div> | 
|  | 23 | + | 
|  | 24 | +  <script> | 
|  | 25 | +    window.MathJax = window.MathJax || { | 
|  | 26 | +      // mocking v2 API as suggested by https://github.com/akhmerov namely to handle both chtml output on the page as well as svg outputs for plotly | 
|  | 27 | + | 
|  | 28 | +      startup: { | 
|  | 29 | +        // | 
|  | 30 | +        //  Mapping of old extension names to new ones | 
|  | 31 | +        // | 
|  | 32 | +        requireMap: { | 
|  | 33 | +          AMSmath: 'ams', | 
|  | 34 | +          AMSsymbols: 'ams', | 
|  | 35 | +          AMScd: 'amscd', | 
|  | 36 | +          SVG: 'svg', | 
|  | 37 | +          noErrors: 'noerrors', | 
|  | 38 | +          noUndefined: 'noundefined' | 
|  | 39 | +        }, | 
|  | 40 | +        ready() { | 
|  | 41 | +          // Here and later using recipe from https://github.com/mathjax/MathJax/issues/2705 | 
|  | 42 | +          // | 
|  | 43 | +          //  Get the MathJax modules that we need. | 
|  | 44 | +          // | 
|  | 45 | +          const {mathjax} = MathJax._.mathjax; | 
|  | 46 | +          const {SVG} = MathJax._.output.svg_ts; | 
|  | 47 | + | 
|  | 48 | +          // Now using https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#version-2-compatibility-example | 
|  | 49 | +          // | 
|  | 50 | +          //  Replace the require command map with a new one that checks for | 
|  | 51 | +          //    renamed extensions and converts them to the new names. | 
|  | 52 | +          // | 
|  | 53 | +          var CommandMap = MathJax._.input.tex.SymbolMap.CommandMap; | 
|  | 54 | +          var requireMap = MathJax.config.startup.requireMap; | 
|  | 55 | +          var RequireLoad = MathJax._.input.tex.require.RequireConfiguration.RequireLoad; | 
|  | 56 | +          var RequireMethods = { | 
|  | 57 | +            Require: function (parser, name) { | 
|  | 58 | +              var required = parser.GetArgument(name); | 
|  | 59 | +              if (required.match(/[^_a-zA-Z0-9]/) || required === '') { | 
|  | 60 | +                throw new TexError('BadPackageName', 'Argument for %1 is not a valid package name', name); | 
|  | 61 | +              } | 
|  | 62 | +              if (requireMap.hasOwnProperty(required)) { | 
|  | 63 | +                required = requireMap[required]; | 
|  | 64 | +              } | 
|  | 65 | +              RequireLoad(parser, required); | 
|  | 66 | +            } | 
|  | 67 | +          }; | 
|  | 68 | +          new CommandMap('require', {require: 'Require'}, RequireMethods); | 
|  | 69 | +          MathJax.Callback = function (args) { | 
|  | 70 | +              if (Array.isArray(args)) { | 
|  | 71 | +                  if (args.length === 1 && typeof(args[0]) === 'function') { | 
|  | 72 | +                  return args[0]; | 
|  | 73 | +                  } else if (typeof(args[0]) === 'string' && args[1] instanceof Object && | 
|  | 74 | +                          typeof(args[1][args[0]]) === 'function') { | 
|  | 75 | +                  return Function.bind.apply(args[1][args[0]], args.slice(1)); | 
|  | 76 | +                  } else if (typeof(args[0]) === 'function') { | 
|  | 77 | +                  return Function.bind.apply(args[0], [window].concat(args.slice(1))); | 
|  | 78 | +                  } else if (typeof(args[1]) === 'function') { | 
|  | 79 | +                  return Function.bind.apply(args[1], [args[0]].concat(args.slice(2))); | 
|  | 80 | +                  } | 
|  | 81 | +              } else if (typeof(args) === 'function') { | 
|  | 82 | +                  return args; | 
|  | 83 | +              } | 
|  | 84 | +              throw Error("Can't make callback from given data"); | 
|  | 85 | +          }; | 
|  | 86 | +          // | 
|  | 87 | +          // Add a replacement for MathJax.Hub commands | 
|  | 88 | +          // | 
|  | 89 | +          MathJax.Hub = { | 
|  | 90 | +              Queue: function () { | 
|  | 91 | +                  for (var i = 0, m = arguments.length; i < m; i++) { | 
|  | 92 | +                      var fn = MathJax.Callback(arguments[i]); | 
|  | 93 | +                      MathJax.startup.promise = MathJax.startup.promise.then(fn); | 
|  | 94 | +                  } | 
|  | 95 | +                  return MathJax.startup.promise; | 
|  | 96 | +              }, | 
|  | 97 | +              Typeset: function (element, callback) { | 
|  | 98 | +                  var promise = MathJax.typesetSVGPromise([element]).then( | 
|  | 99 | +                      () => { | 
|  | 100 | +                          element.firstElementChild.classList.add("MathJax_SVG"); | 
|  | 101 | +                      } | 
|  | 102 | +                  ); | 
|  | 103 | +                  if (callback) { | 
|  | 104 | +                      promise = promise.then(callback); | 
|  | 105 | +                  } | 
|  | 106 | +                  return promise; | 
|  | 107 | +              }, | 
|  | 108 | +              Config: function () {}, | 
|  | 109 | +              Configured: function () {console.log('MathJax cannot be configured like this')}, | 
|  | 110 | +              config: {menuSettings: {renderer: "SVG"}} | 
|  | 111 | +          }; | 
|  | 112 | + | 
|  | 113 | +          MathJax.startup.defaultReady(); | 
|  | 114 | + | 
|  | 115 | +          // Continuing from https://github.com/mathjax/MathJax/issues/2705 | 
|  | 116 | +          // | 
|  | 117 | +          //  Create an SVG output jax and a new MathDocument that uses it. | 
|  | 118 | +          // | 
|  | 119 | +          const svgOutput = new SVG(MathJax.config.svg); | 
|  | 120 | +          const svgDocument = mathjax.document(document, { | 
|  | 121 | +              ...MathJax.config.options, | 
|  | 122 | +              InputJax: MathJax.startup.input, | 
|  | 123 | +              OutputJax: svgOutput | 
|  | 124 | +          }); | 
|  | 125 | +          // | 
|  | 126 | +          //  Define the SVG-based conversion methods | 
|  | 127 | +          // | 
|  | 128 | +          MathJax.svgStylesheet = () => svgOutput.styleSheet(svgDocument); | 
|  | 129 | +          MathJax.typesetSVGPromise = (elements) => { | 
|  | 130 | +              svgDocument.options.elements = elements; | 
|  | 131 | +              svgDocument.reset(); | 
|  | 132 | +              return mathjax.handleRetriesFor(() => { | 
|  | 133 | +                  svgDocument.render(); | 
|  | 134 | +              }); | 
|  | 135 | +          }; | 
|  | 136 | +        } | 
|  | 137 | +      }, | 
|  | 138 | +      loader: {load: ["output/svg"]}, | 
|  | 139 | +      tex: { | 
|  | 140 | +          inlineMath: [["\\(", "\\)"], ["$", "$"]], | 
|  | 141 | +          displayMath: [["\\[", "\\]"], ["$$", "$$"]], | 
|  | 142 | +          processEscapes: true, | 
|  | 143 | +          processEnvironments: true, | 
|  | 144 | +          autoload: { | 
|  | 145 | +              color: [],          // don't autoload the color extension | 
|  | 146 | +              colorv2: ['color'], // do autoload the colorv2 extension | 
|  | 147 | +          } | 
|  | 148 | +      } | 
|  | 149 | +    }; | 
|  | 150 | +  </script> | 
|  | 151 | +  <script src="../../node_modules/mathjax-v3/es5/tex-mml-chtml.js"></script> | 
|  | 152 | +  <script> | 
|  | 153 | +    // let plotly.js know that v2 API is mocked | 
|  | 154 | +    window.MathJax._mockedV2API = true; | 
|  | 155 | +  </script> | 
|  | 156 | +  <script charset="utf-8" id="source"  type="module">import "../../build/plotly.js"</script> | 
|  | 157 | +  <script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script> | 
|  | 158 | +</body> | 
|  | 159 | +</html> | 
0 commit comments