Not signed in (Sign In)

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthordanlec
    • CommentTimeNov 18th 2009 edited

    Not sure where the best place for this is, but I thought people might find this useful:

    Note: I've only verified that this works in Chrome and FireFox

    If you'd like to have a live preview of the $math$ formatting as you type, you can use the following scriptlet:

    javascript:if($("#wmd-preview:visible").length){$("#wmd-preview").hide().after("<div style='background-color: #dadada; border: 2px dotted white; font-size: 107%; clear: both; line-height: 130%; margin-top: 14px; padding: 3px; width: 660px;' id='math-preview'></div>"); $("#wmd-input").keyup(function() { jsMath.ConvertTeX('wmd-preview');jsMath.ProcessBeforeShowing('wmd-preview'); $("#math-preview").html($("#wmd-preview").html())}).keyup();$("input[value=Preview Math]").hide();}void(0);

    To see what this does:

    1. Go to a question or answer page on mathoverflow
    2. Put the long string from above (from "javascript:" to "void(0);") into the address bar, hit enter.
    3. Type something like $e^{\pi i}=-1$ in the editor, note that you see the preview update as you type (i.e. as soon as you type the second $, the preview will show the math)

    To setup a scriptlet for easy use:

    1. Create a new bookmark named "Live Math Preview" (or whatever)
    2. Set the address to the long string above (from "javascript:" to "void(0)").
    3. Put the bookmark in your links bar, so you can easily click on it
    4. Whenever you're on question or answer mathoverflow page, just click that bookmark link. You'll notice that the "preview math" button disappears, and the preview will show the math formatting as you type it.

    Anton, should we (can we?) implement this for everyone?


    Thanks danlec! It should work for everybody automatically now.


    No! Please don't make it work for everybody! I find that mathoverflow creaks along at an alarmingly slow pace when I'm working from home and anything that adds to that will make it unusable.

    Actually, having said that then I perhaps ought to test this new feature at home before complaining about this specifically, but my general point is still valid: don't add features just for the sake of adding them. Rather, make it easy for people to add themselves. If you put an "add bookmarklet" button somewhere that easily installs this then I can add it to my work computer and not on my home computer.


    Since installing this feature, I have now found that I type faster than the answer text box updates. (Note: this is the field I am typing in that updates slowly, not the preview. I could easily ignore it if the preview updated slowly.) I find this more annoying than the feature is helpful.


    @David: I'll see what I can do about that later today. I'd like the live preview to happen by default, but I'll see if I can work out a way to optionally disable math preview if you're having problems with it.

    • CommentAuthordanlec
    • CommentTimeNov 19th 2009 edited

    @Anton: There are a lot of things that can be done to address issues people are having; perhaps the easiest is to have the "live $math$ preview mode" enabled/disabled by a checkbox (it could be tied to a cookie, so the user's choice would persist).

    Another approach is to only generate the full preview when the user's input has been idle for more than some amount of time (maybe 1 second)

    A slightly more complicated approach is to time how long it takes the preview to generate, and use that number to throttle how often a new preview is generated (i.e. if a user's browser is taking 1 second to generate a preview, then the preview should be generated much less frequently than if their browser could generate the preview in 1ms)


    @danlec: your javascript prowess clearly far exceeds mine. The cookie sounds like the way to go, but I don't know how to implement it. If you have some time today, I'd love to work it out. Is there a more efficient way for the two of us to chat than using this forum? My email is geraschenko@gmail.


    I have no javascript knowledge, but I think danlec's two timing suggestions sound great if they are doable.


    This sounds great. Can I put in a plea for the "turn off live preview" button.

    I'd actually be happy with turning off the markdown live preview. It's frequently "below the fold" so I don't see it as I type, and as a die-hard TeX-addict, I have no use for the ability to see what it will look like as I actually type it. Of course, I understand that there are people that aren't enlightened, which is why I'm prepared to compromise on the "turn off annoying feature" button - and also I'm aware that turning off the full preview maybe beyond your powers but if the live mathematics preview can be turned off, that'd be great. And cookies are great too so I don't have to keep remembering it.


    Please, please, please turn this off!

    I'm working from home on a very fast computer but with only ordinary internet speed (4Mbs) and it is painfully slow.

    I would now go so far as to say that this should be off by default. I'm not sure that people are going to realise that it's the preview that is making the site slow and that they can turn it off, and they may just decided that MO is too slow to use (that's one reason why I never use planetmath). Make it easy to turn on, by all means, (and with a warning that it might slow things down), but please, please, please don't have it on by default.


    Ok, ok, ok. I've turned it off by default, and added an "Auto Preview" button. I hope this solution is tolerable until I learn how to do something awesomer.


    Thank you so much!


    Thank you for turning this off.

    • CommentAuthordanlec
    • CommentTimeNov 24th 2009

    @Anton: Sorry this caused so much trouble (in my defense, it was only designed to be used as an "opt-in" scriptlet)

    In any case, I've worked out some potential ways of addressing this, and (I think?) I emailed you the details.


    @danlec: Thanks for your work on this. If it can be made to work without the slowdown, it will definitely be an improvement to the site.