Cloud Development Kit

Capture text result in myscript-math-web

I've implemented the demo provided with myscript-math-web and I want to capture the annotation encoding result that is fed into the html and send that to my server application.

So the equation 21 minus 35 divided by 13 would have the following within the katex section of the html

<div id="resultField" class="style-scope myscript-math-web">
<span class="katex">
<span class="katex-mathml">
<math>
<semantics>
<mrow>
<mfrac>
<mrow>
<mn>2</mn>
<mn>1</mn>
<mo>−</mo>
<mn>3</mn>
<mn>5</mn>
</mrow>
<mrow>
<mn>1</mn>
<mn>3</mn>
</mrow>
</mfrac>
<annotation encoding="application/x-tex">dfrac {21-35} {13}</annotation>
</semantics>
</math>
</span>
</span>
</div>


I want to capture the dfrac {21-35} {13} in a field I can use elsewhere. Is there js within MyScript to enable this?


Nevermind, I've worked it out using a little javascript, namely:

<script>
function copy_result() {
elms = document.getElementById("resultField").getElementsByTagName("annotation");
console.log(elms[0].innerHTML);
}
</script>

Thanks for sharing this. This is a solution that enables you to get the latex result and normalize it with Katex. You could also get the result directly from the webcomponents with the following code:

<script>
function copy_result() {
elms = document.querySelector('myscript-math-web').result['LATEX'];
console.log(elms[0].innerHTML);
}
</script>

Please let us know if you have any other questions.

Login or Signup to post a comment