Search code examples
javascripthtmlmathjaxmathml

MathJax works on Firefox Browser but on the rest of the Browsers it doesn't work


I use MathJax on a Website I have done. On Firefox, it all works fine, and I don't have a Problem with the MathJax input, but if I open the Site on Opera by example it doesn't work well. This is the Code that doesn't work on other Browsers:

<math id="mitHoch">
            <mstyle displaystyle="true">
              <mtext>- ln *&nbsp;</mtext>
              <mtext style="font-size: 300%; font-weight: 100;">(</mtext>
                <mfrac>
                  <msup>
                    <semantics>
                      <annotation-xml encoding="application/xhtml+xml">
                        <input
                          xmlns="http://www.w3.org/1999/xhtml"
                          type="text"
                          size="2"
                          name="VCT"
                        />
                      </annotation-xml>
                    </semantics>
                    <semantics>
                      <annotation-xml encoding="application/xhtml+xml">
                        <input
                          xmlns="http://www.w3.org/1999/xhtml"
                          style="text-align: right"
                          type="text"
                          size="1"
                          name="VCTH"
                        />
                      </annotation-xml>
                    </semantics>
                  </msup>
                  <msup>
                    <semantics>
                      <annotation-xml encoding="application/xhtml+xml">
                        <input
                          xmlns="http://www.w3.org/1999/xhtml"
                          type="text"
                          size="2"
                          name="VCL"
                        />
                      </annotation-xml>
                    </semantics>
                    <semantics>
                      <annotation-xml encoding="application/xhtml+xml">
                        <input
                          xmlns="http://www.w3.org/1999/xhtml"
                          style="text-align: right"
                          type="text"
                          size="1"
                          name="VCLH"
                        />
                      </annotation-xml>
                    </semantics>
                  </msup>
                </mfrac>
              <mtext style="font-size: 300%; font-weight: 100;">)</mtext>
              <mo>&nbsp;*&nbsp;</mo>
              <mfrac>
                <mtext>5 730 a</mtext>
                <mtext>ln(2)</mtext>
              </mfrac>
              <mtext>&nbsp;=&nbsp;</mtext>
            </mstyle>
          </math>

I think it's because of the different Versions of Mathjax. But how do I know which Version Firefox uses, and how do I change it that all use the same Version?

PS: On Firefox, it looks like this: Firefox MathJax

And on Opera and other Browsers it looks like this: Opera MathJax

I need it for a School Project and I would be really happy if anyone could help me. Thanks in advance!


Solution

  • The output you show in your screen captures is not from MathJax; these are the native MathML renderings in those browsers, so you may not have Mathjax running properly in your website.

    Technically, the MathML you give is invalid because the first child of <semantics> is supposed to be a presentation MathML node, not an annotation node. Early versions of Firefox did not enforce this requirement, and so it provided a hack to allow mixing HTML content with MathML, and because people had started to use it, they never changed that. MathJax provided support for that as well, for the same reason, but the newer MathML implementations in Chrome, Edge, and Opera don't.

    The MathJax rendering for your expression is the following:

    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js" defer></script>
    
    <math id="mitHoch">
                <mstyle displaystyle="true">
                  <mtext>- ln *&nbsp;</mtext>
                  <mtext style="font-size: 300%; font-weight: 100;">(</mtext>
                    <mfrac>
                      <msup>
                        <semantics>
                          <annotation-xml encoding="application/xhtml+xml">
                            <input
                              xmlns="http://www.w3.org/1999/xhtml"
                              type="text"
                              size="2"
                              name="VCT"
                            />
                          </annotation-xml>
                        </semantics>
                        <semantics>
                          <annotation-xml encoding="application/xhtml+xml">
                            <input
                              xmlns="http://www.w3.org/1999/xhtml"
                              style="text-align: right"
                              type="text"
                              size="1"
                              name="VCTH"
                            />
                          </annotation-xml>
                        </semantics>
                      </msup>
                      <msup>
                        <semantics>
                          <annotation-xml encoding="application/xhtml+xml">
                            <input
                              xmlns="http://www.w3.org/1999/xhtml"
                              type="text"
                              size="2"
                              name="VCL"
                            />
                          </annotation-xml>
                        </semantics>
                        <semantics>
                          <annotation-xml encoding="application/xhtml+xml">
                            <input
                              xmlns="http://www.w3.org/1999/xhtml"
                              style="text-align: right"
                              type="text"
                              size="1"
                              name="VCLH"
                            />
                          </annotation-xml>
                        </semantics>
                      </msup>
                    </mfrac>
                  <mtext style="font-size: 300%; font-weight: 100;">)</mtext>
                  <mo>&nbsp;*&nbsp;</mo>
                  <mfrac>
                    <mtext>5 730 a</mtext>
                    <mtext>ln(2)</mtext>
                  </mfrac>
                  <mtext>&nbsp;=&nbsp;</mtext>
                </mstyle>
              </math>

    which should show the input boxes in all browsers.

    You may notice that the parentheses, for example, are not well placed, and are excessively heavy. This is because the MathML you are using is not really very good, as you are using <mtext> elements inappropriately, and are not taking advantage of the features that MathML offers. A better version of your expression is the following:

    <script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js"></script>
    
    <math id="mitHoch" displaystyle="true">
      <mo>-</mo>
      <mi>ln</mi>
      <mrow>
        <mo>(</mo>
        <mfrac>
          <msup>
            <semantics>
              <annotation-xml encoding="application/xhtml+xml">
                <input xmlns="http://www.w3.org/1999/xhtml"
                  type="text"
                  size="2"
                  name="VCT"
                />
              </annotation-xml>
            </semantics>
            <semantics>
              <annotation-xml encoding="application/xhtml+xml">
                <input xmlns="http://www.w3.org/1999/xhtml"
                  style="text-align: right"
                  type="text"
                  size="1"
                  name="VCTH"
                />
              </annotation-xml>
            </semantics>
          </msup>
          <msup>
            <semantics>
              <annotation-xml encoding="application/xhtml+xml">
                <input xmlns="http://www.w3.org/1999/xhtml"
                  type="text"
                  size="2"
                  name="VCL"
                />
              </annotation-xml>
            </semantics>
            <semantics>
              <annotation-xml encoding="application/xhtml+xml">
                <input xmlns="http://www.w3.org/1999/xhtml"
                  style="text-align: right"
                  type="text"
                  size="1"
                  name="VCLH"
                />
              </annotation-xml>
            </semantics>
          </msup>
        </mfrac>
        <mo>)</mo>
      </mrow>
      <mo symmetric="true" rspace=".15em">*</mo>
      <mfrac>
        <mrow>
          <mn>5 730</mn>
          <mi>a</mi>
        </mrow>
        <mrow>
          <mi>ln</mi>
          <mo>(</mo>
          <mn>2</mn>
          <mo>)</mo>
        </mrow>
      </mfrac>
      <mo>=</mo>
      <mi></mi>
    </math>

    This still uses the <semantic> hack to get the input elements into the expression, but in version 4 (now in alpha release), there is support for HTML in MathML directly (as in the HTML5 specification); see the release notes for v4.0-alpha for details.