Search code examples
htmllatexmathjax

Is it possible to include an input box within a LaTeX equation with MathJax?


I have the document:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Distribution</title>
        <script type="text/x-mathjax-config">
        MathJax.Hub.Config({
          tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
        });
        </script>
        <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script src="distrib.js"></script>
        <link href="distrib.css" rel="STYLESHEET">
    </head>
    <body>
        <h1>Distribution Calculator</h1>
        $\dfrac{X}{Y}=Z$<br>
        <button onclick="doStuff()">Solve for $Z$</button
    </body>
</html>

I want the user to be able to input directly into the equation, that is, have some sort of <input> tag inside the equation or something, for X and Y. Is this possible? How might I find a workaround, if it isn't possible?

(Please note that I want the functionality to do this in an equation. I am aware that some CSS and a table can do this, but I wish to have this done inside of an equation, as the need for this arises quite often. Something like how Mathway does it, preferably.)

I've tried directly putting in an input box into the equation (haha) and surrounding the box with parts of the equation. This, however, fails to work, especially in the case of a fraction, or sum, or integral, etc.


Solution

  • (Posting as an answer so that the question will not remain unanswered).

    See the forminput extension in the MathJax third-part repository. That might do what you want.