4

I've spent hours online looking for a solution, and been down too many weird alley ways...

Lets say I have a formula: x^2 + 3x + 32

I want to randomly choose to replace a part of the formula with a text box (I can do this)

x^2 + [textbox]x +32

And then display the result nicely formatted for input by the student. (I can't do this)

I have looked at MathJax and MathML and I think that If i can get the result into mathml format including the textbox I'm sorted. I can already display formulas nicely using MathJax.

What Doesnt work:

  • Find and replace on the resulting formula with a text box (replacing the number)

  • Find and replace on the resulting formula with a text box (adding annotation tags)

Both approches I have tried mess up the spacing / clip the textbox so it is unusable. I think the only way is to generate the MathML with the textbox already included, instead of trying to add it afterwards.

But I don't know how? Anyone can suggest a way to generate mathml with textbox for use in mathjax?

Here is my failed attempt so far:

<script type="math/mml" id="scriptTag">
  <math>
    <mfrac>
      <msqrt>
        <mn>
          <semantics>
            <annotation-xml encoding='application/xhtml+xml'>
              <input xmlns='http://www.w3.org/1999/xhtml' type='text' size='4' />
            </annotation-xml>
          </semantics>
       </mn>
     </msqrt>
     <mn> 3 </mn>
    </mfrac>
  </math>
</script>

I can create the basic (no textbox) mathml using this guide: http://www.xmlmind.com/tutorials/MathML/

user230910
  • 2,353
  • 2
  • 28
  • 50
  • 1
    Seems to be an interesting question, but you're providing too little information. What is the text box, exactly? HTML? Is there even a text box element in MathML? What do you generate MathML from? – Mathias Müller Oct 19 '14 at 20:31
  • Thanks for looking at the Q! Basically I want to provide the user the ability to complete the formula. I *think* i want a simple html input control, and I know that the xml-annotate part of mathml does provide for this, but I can't seem to get it to work... – user230910 Oct 20 '14 at 04:40
  • At the moment i'm getting the mathml from an online service that converts a formula to mathml. I'm still looking at a way to generate the mathml. Right now, I'm just concerned with the final step, that is get some mathml that mathjax understands that contains a text box. I don't mind if mathjax injects the text box, or if it is done up front.. – user230910 Oct 20 '14 at 04:45

1 Answers1

3

I think modern browsers allow some mixing of HTML elements and MathML elements in HTML5:

<div>
<h2>Example 2</h2>
<div>
<math>
  <mrow>
    <mn><input type="text" size="4"></mn>
    <mo>*</mo>
    <mi>x</mi>
  </mrow>
</math>
</div>
</div>

<div>
<h2>Example 2</h2>
<div>
<math>
  <mrow>
    <mn><input type="text" size="4"></mn>
    <mo>*</mo>
    <mi>x</mi>
  </mrow>
</math>
</div>
</div>

Here is a superscript example, with Firefox that input box appears:

<div>
<h2>Example msup</h2>
<div>
<math>
  <mrow>
    <msup>
      <mn>2</mn>
      <mn><input type="text" size="4"></mn>
    </msup>
  </mrow>
</math>
</div>
</div>

<div>
<h2>Example msup</h2>
<div>
<math>
  <mrow>
    <msup>
      <mn>2</mn>
      <mn><input type="text" size="4"></mn>
    </msup>
  </mrow>
</math>
</div>
</div>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • this is pretty awesome, but it fails in my use case - where the text box needs to be in a "Power" place like x^2 becomes x* where the * is the text box – user230910 Oct 20 '14 at 14:46
  • I tried an example using `msup` as well, at least with Firefox it does show the text box. I thought other browsers like Chrome support MathML as well but it looks like Chrome removed its support after some initial implementation. I am not familiar with mathjax so perhaps someone else can tell you how to get that problem solved in a cross-browser way. – Martin Honnen Oct 20 '14 at 15:19
  • yeah mathjax renders the content nicely, excluding the text box :( – user230910 Oct 20 '14 at 15:20
  • 2
    For form input in MathML with MathJax, check out [this SO answer](http://stackoverflow.com/a/21194841). For form input in TeX-input and MathJax you can try [this third party extension](https://github.com/mathjax/MathJax-third-party-extensions/tree/master/forminput) for MathJax. – Peter Krautzberger Oct 20 '14 at 19:39