Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I'm trying to use mathjax in angularjs. I have a lot of html content in the server and it requires edits also. This is the directive I'm using to trigger mathJax to render.

app.directive("mathTex", ['$log',function($log) {
return {
    restrict: "C",
    link: function(scope, element, attributes) {
      var currentElement = element[0];
      //alert("mathJax directive called");
      MathJax.Hub.Queue(["Typeset", MathJax.Hub, element[0]]); 
    }
}}]);

I'm using another directive to compile the html on any changes in scope.

app.directive('dynamicHtmlCompile', ['$compile','$parse','$log','$sanitize', function ($compile, $parse, $log, $sanitize) {
    return {
    restrict: 'A',
    replace: true,
    link: function (scope, ele, attrs) {
      scope.$watch(attrs.dynamicHtmlCompile, function(html) {
        ele.html(html);
        $compile(ele.contents())(scope);
      });
    } 
  }
}]);

Both of these directives works in normal conditions, but for expressions like

<span class="math-tex">\({{2v}}/2\)</span>, it is triggering an error because of the curly braces in the expression.

Error: [$parse:syntax] Syntax Error: Token 'v' is an unexpected token at column 2 of the expression [2v] starting at [v].

For editing the content I'm using mathjax and ckeditor. It works fine too.

So far, I tried 'ng-html-bind', I could not use it because it does not support two way binding. Another option is to change interpolation start and end symbols. I've used a few libraries in the project and I do not want to mess things up just to fix this problem.

I have control over the source of html and I have an option to change (probably, find and replace) the format or texts, if it is necessary. Any suggestions would be appreciated.

Thanks

share|improve this question
    
You can try to replace {{ and }} by other characters before calling $compile and replace it back in mathTex directive. – jcubic 58 mins ago
    
@jcubic Thanks. It works. At least, for now. The html returned from the server could be an entire html page having a lot of content. I'm looking for a solution to re-render the page as it is received from the server. I do not need to trigger anything other than math-tex directive. – Raghu Venmarathoor 35 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.