Skip to content

Changing items in an equation dynamically via toggle

pkra edited this page Apr 5, 2013 · 3 revisions

From https://groups.google.com/d/msg/mathjax-users/LI3t70AU2Ec/920iIcoDbMMJ


Please help with this question: Given that my page have <div id="mathdiv">\[{3 x^2 + 4 x + 5}\]</div> I learned from the MathJax site that I can change this equation dynamically. However, I wonder if it is possible to change each item, the coefficients, the operators, the unknown ... etc individually when clicked or touched on touch devices?

=== Fred is right that MathJax doesn't currently provide an API to change
individual elements within an equation. (It would be possible to
modify the internal Element Jax tree and ask MathJax to rerender the
result, but you are probably better off just replacing the entire
equation and rerendering, as the parsing of the equation is not the
time-consuming part of MathJax.)

On the other hand, perhaps you can use the to accomplish what you need. When a user clicks
on this element, it cycles through a list of expressions to display.
There is an extension to give you access to this from within TeX. Add
"action.js" to the extensions array in the TeX section of your
configuration, and then you can use

    \toggle{math1}{math2}...\endtoggle 

to produce an expression initially showing math1, but when you click
on math1 it will change to math2, and so on. So

    x + \toggle{y}{\color{red}{y}} + z 

would produce an equation where when you click on the y it turns red
(and clicking again makes it black again). Perhaps that can do what
you need.

Davide


Clone this wiki locally