How can I get TeX input-string on V3

137 views
Skip to first unread message

tsubolabo

unread,
Jan 30, 2020, 12:38:42 AM1/30/20
to MathJax Users
Hello,

InnerText of rendered characters, for example "\pi", on V2 and V3 are shown below. On V2, there is the input-string "\pi" surrounded by "script" tags in the last three lines. But on V3, I can't find it anywhere.

How can I get TeX input-string on V3?

I use the content between "script" tags in my web page "MathJax Quick Reference" for V2 (see, my posting dated 9 Jan), to display TeX input-string on a sub window. I have difficulty in remaking it into V3.

==== V3 ====

<mjx-container class="MathJax CtxtMenu_Attached_0" jax="CHTML" justify="left" tabindex="0" ctxtmenu_counter="0">
  <mjx-math class="MJX-TEX">
    <mjx-mi class="mjx-i">
      <mjx-c class="mjx-c3C0">
      </mjx-c>
    </mjx-mi>
  </mjx-math>
</mjx-container>

==== V2 ====

<span class="MathJax_Preview" style="color: inherit;">
</span>
<span id="MathJax-Element-1-Frame" class="mjx-chtml MathJax_CHTML" tabindex="0" data-mathml="
    <mi>
      &amp;#x03C0;
    </mi>
  </math>
" role="presentation" style="font-size: 105%; position: relative;">
  <span id="MJXc-Node-1" class="mjx-math" aria-hidden="true">
    <span id="MJXc-Node-2" class="mjx-mrow">
      <span id="MJXc-Node-3" class="mjx-mi">
        <span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.182em; padding-bottom: 0.301em; padding-right: 0.003em;">
          π
        </span>
      </span>
    </span>
  </span>
  <span class="MJX_Assistive_MathML" role="presentation">
      <mi>
        π
      </mi>
    </math>
  </span>
</span>
<script type="math/tex" id="MathJax-Element-1">
  \pi
</script>

Davide Cervone

unread,
Jan 31, 2020, 9:44:47 AM1/31/20
to mathja...@googlegroups.com
How can I get TeX input-string on V3?

As you know, in v2 the original TeX is stored in a <script> tag within the page, but that is no longer the case in v3.  In v3, the original TeX is stored in an internal object (a MathItem) in the internal MathDocument structure.  There are several ways you could access that original TeX.

The first would be, given the <mjx-container> element, look through the math list for the math item that has that container as its typesetRoot:

function findTeX(container) {
  for (const math of MathJax.startup.document.math) {
    if (container === math.typesetRoot) return math.math;
  }
}

So you can call this, passing it the mjx-container and it will return the TeX string.

Alternatively, you could add a renderAction to the document so that when the math is inserted into the page, it will add the original TeX as a data attribute on the mjx-container itself.  For example

MathJax = {
  options: {
    renderActions: {
      addTeX: [151,
        (doc) => {for (const math of doc.math) MathJax.config.addTeX(math, doc)},
        (math, doc) => MathJax.config.addTeX(math, doc)
      ]
    }
  },
  addTeX(math, doc) {
    doc.adaptor.setAttribute(math.typesetRoot, 'data-tex', math.math);
  }
};

would add a data-tex attribute where you could read out the original TeX.

Hope that helps.

Davide

tsubolabo

unread,
Feb 2, 2020, 2:40:33 AM2/2/20
to MathJax Users
Thank you very much, Davide

The problem was resolved thanks to your support.

By the first way, I can get original TeX directly, and by the alternative way, original TeX comes to be displayed inside the "mjx-container" tag, as a "data-tex" property.

HTML file used for test is attached.

MathJax_test39_for_V3.html
Reply all
Reply to author
Forward
0 new messages