Skip to content
Advertisement

How to use mathjax inside qtip on a cytoscape node

How could I use the Mathjax library within qtip in a cytoscape node?

In the sample code below, the tooltip is displayed when clicking over the top of a node, but the Mathjax is not rendered.

How can this be fixed so that the equation is also shown in the tooltip? The solution in this answer by @peterkrautzberger could be an option, but I didn’t manage to adapt it to this case.

Edited: The answer by @dipenshah solves the original question. However, when extending the sample code allowing for dynamic Mathjax content it doesn’t seem to work. If instead of having a fixed text for the tooltips, the text is taken from the element txt in the definition of the node, then the Mathjax is not rendered. I have modified the code below to show it.

JavaScript
JavaScript

Advertisement

Answer

Based on updated question: For dynamic content there is no guarantee that by the time MathJax starts processing dom element will be available in the same event callback, so here we can use setTimeout to queue processing after current Javascript calls have finished processing:

JavaScript

Let’s take a look:

JavaScript
JavaScript

Original answer:

You can use render callback on qtip, to let MathJax know about update:

JavaScript

checkout updated code:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement