Re-rendering KaTEX - Help a Teacher w/ Meteor


#1

Hi everyone,

I’m working on a project that lets me (and other teachers) write randomized questions to use with students for both practice and assessment. I’m using the simple:katex project from @sashko to use the Khan Academy KaTEX library to do the rendering of the math. The idea is that the questions are formatted in HTML, with tags around any text that should be formatted as math.

Part of making this useful is letting teachers preview what the questions will look like. This is always a trial and error process. Unfortunately, I’m having trouble making the KaTEX render reactively as the text in the question HTML changes.

I’ve put together a Meteorpad to show the problem I’m having here:
MeteorPad EquationsRender

I want to be able to change the text in the textarea, hit the ‘Show Rendered’ button, and have the new text between the tags be rendered using KaTEX. Right now, clicking the button changes the text in the rendered area, but the tags are not re-rendered.

I’m pretty sure this is a job for an Autorun function, but nothing I’ve tried thus far works. I realize that one solution is to just put {{#katex}} block helpers around the result helper, but I don’t want to render all of the text using the Katex rendering for aesthetic reasons.

Anyone up for giving a teacher a hand?


#2

http://meteorpad.com/pad/83NAKR57MsxxRhoGr/Copy%20of%20EquationsRender


#3

This is great! I knew it was something simple. I had something similar before, but left out the call to Session.get(). I’ve updated the MeteorPad with the correct code.

Is it correct to say that any change to a reactive variable referenced in the autorun function will cause that function to be rerun? Will this still occur if the reactive variable isn’t actually used for anything in the template that calls the autorun function?


#4

yes, when the reactive source is invalidated, helper will rerun.
and as it is type of String, if you try to push button multiple times, it should not fire if text did not changed.