Any way to display edit caret?

  • Kenneth Tilton

    Kenneth Tilton - 2010-04-11

    I want to use jsMath for a wysiwyg math editor, but that means having some way of showing the user where they are if they cursor back to somewhere within the math expression to make a change. Ideally this would be a blinking caret to show the insertion point, but it could just be non-blinking and done as a background color or underscore or something. If jsMath cannot display the caret maybe if I can at least get precise text metrics info I could overlay the math with a caret. Is anything like this feasible? Thx.

  • Davide P. Cervone

    My suggestion would be to define a macro that inserts the caret.  For example, something like


    which uses \rlap to make the caret take up no horizontal room, a kern to move it backwards so it is centered between characters, and a \dlap (a jsMath extension) that "down-laps" the caret, meaning it is pushed below the baseline and takes no vertical space.   With this definition, "a\caret b" would put the caret between the "a" and "b".

    To make it blink, you would need to add a CSS ID value to the caret so that you can access it from JavaScript, and then use that to set the CSS visibility value alternately from hidden to visible on a timer using setTimeout.  That is done via the jsMath extension \cssId, as in


    so that document.getElementById("caret") will get you the element containing the caret symbol.

    Hope that gets you started.


  • Kenneth Tilton

    Kenneth Tilton - 2010-05-17

    Wow, I now have my math editor ported to the Web! You have no idea how much code I can throw away now. :) I am going with jsMath for now because I like the extensions not yet ported to MathJax and because I have to think it will be faster for not doing the intermediate translation to MML. Anyway, thanks for a great effort. I'll let you know as soon as there is a web site up.


Log in to post a comment.