HTMLWidgets.widget({

  name: 'katexR',

  type: 'output',

  initialize: function(el, width, height) {

    return {
      // TODO: add instance fields as required
    }

  },

  renderValue: function(el, x, instance) {

    // empty out our widget el in case of dynamic or Shiny
    el.innerHTML = "";
    
    // check for blank katex
    //   if blank assume katexR just used for dependency injection
    if( x.katex !== "" ){
      el.style.display = "";
      katex.render( x.katex, el );
      // use expando to attach original KaTeX string
      el.katex = x.katex;
    } else {
      el.style.display = "none";
    }
    
  },

  resize: function(el, width, height, instance) {

  }

});

@@ -449,24 +449,38 @@
 splay = %22%22;%0A
+      try %7B%0A  
       katex.
@@ -508,16 +508,18 @@
 ;%0A      
+ 
+ 
 // use e
@@ -563,16 +563,18 @@
 g%0A      
+  
 el.katex
@@ -585,16 +585,114 @@
 .katex;%0A
+      %7D catch(e) %7B%0A        el.innerHTML = %5B%22%3Cpre%3E%22,x.katex,e.message,%22%3C/pre%3E%22%5D.join(%22%5Cn%22)%0A      %7D%0A
     %7D el

add try catch to return error if problem