Changing items in an equation dynamically

495 views
Skip to first unread message

agentyikes

unread,
Jun 24, 2012, 8:55:00 PM6/24/12
to mathja...@googlegroups.com
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?

Frédéric WANG

unread,
Jun 25, 2012, 6:25:06 AM6/25/12
to mathja...@googlegroups.com
As far as I know (Davide, correct me if I'm wrong) the best you can do
in MathJax is to update each equation individually, if that's what you
are asking. With standard MathML you can just use javascript to modify
one part of an equation and your browser (if it supports MathML) should
update the rendering immediately. That's not possible with MathJax: it
is not aware of DOM changes unless it is told explicitly. Adding a
system to MathJax to locate which part of the original input has changed
and automatically update the corresponding part of the output tree would
probably be hard and cause more problems than benefits. If the equation
is not too large, I guess updating the whole equation would not be too
slow compared to updating one part of it...

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

Dr. Dayal D. Purohit

unread,
Jun 25, 2012, 9:56:07 PM6/25/12
to mathja...@googlegroups.com
you have to change the content inside the div element using javascript. this change does not trigger mathjax to re-render the page, so you have to call mathjax to-render the page. the call is MathJax.Hub.Typeset(). this renders the entire page. but you can also ask mathjax to rerender just that div element. these techniques are used to dynamic websites.

i have a whole set of math routines that generate dynamic math using ajax and mathjax works just fine. check out my site at http://www.jds.com, the old plugins are dynamic in that site.

d^3p

agentyikes

unread,
Jun 26, 2012, 9:04:57 AM6/26/12
to mathja...@googlegroups.com
Thanks a lot!

agentyikes

unread,
Jun 26, 2012, 9:05:10 AM6/26/12
to mathja...@googlegroups.com
Thanks for the information.

Davide P. Cervone

unread,
Jun 28, 2012, 8:55:25 AM6/28/12
to mathja...@googlegroups.com
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 <maction
actiontype="toggle"> 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
Message has been deleted

agentyikes

unread,
Jun 28, 2012, 10:59:06 AM6/28/12
to mathja...@googlegroups.com
I tried and it works!
Thanx Davide

Davide P. Cervone

unread,
Jun 28, 2012, 11:59:46 AM6/28/12
to mathja...@googlegroups.com
No problem.  Glad that does what you need.

Davide
Reply all
Reply to author
Forward
0 new messages