# [IPython-dev] Unique cell render div ids

Mon Oct 29 15:59:15 CDT 2012

Hi Developers,

While fixing the code for MathJax rendering that I broke earlier this week,
I came across the need to address a specific element in the DOM:

http://docs.mathjax.org/en/latest/typeset.html

I know there has been some work attaching unique ids to cells in the code
in the past, but there didn't seem to be any obvious functionality
currently implemented in Cells for this.  You'll notice that the pull
request I just updated here:
textcell.js:

.....**

@@ -39,9 +39,11 @@ var IPython = (function (IPython) {

3939**

extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},

4040**

onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) 4141** }); 42** + this.cell_id = IPython.utils.uuid(); 4243** // The tabindex=-1 makes this div focusable. 44** + // id is a unique cell_id necessary for updating MathJax intelligently 4345** var render_area =$('<div/>').addClass('text_cell_render
border-box-sizing').

44 **

46**

4547**

cell.append(input_area).append(render_area);

4648**

this.element = cell;

4749**

};

What I'm doing here is first calling into IPython.utils.uuid() to generate
a cell_id (The one from the Cell prototype appears to be broken/unused?),
then adding that as an id to the
rendered html div.

Then later, I can grab this id when I need to update the math:

82**

+    TextCell.prototype.typeset = function () {

83**

+        if (window.MathJax){

84**

+            var cell_math = document.getElementById(this.cell_id);

85**

+            MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]);

86**

+        }

87**

+    };

88**

+

This really speeds up MathJax rendering considerably, so I think it's worth
doing, but I feel like I'm really nosing into code I don't understand well,
so it would be good to hear feedback if there are opinions on this.

A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20121029/e885b1d3/attachment-0001.html