# Make Jupyter notebook with JsROOT=on convertible to LaTeX

**URL:** <https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035>\
**Category:** Evolution Proposals, Apps & Ideas\
**Tags:** graphics, jsroot\
**Created:** [April 22, 2020, 5:00pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035 "2020-04-22T17:00:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![berserker](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/berserker/32/17693_2.png) [@berserker](https://root-forum.cern.ch/u/berserker)\
**Post date:** [April 22, 2020, 5:00pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/1 "2020-04-22T17:00:37Z")

</div>

Plz make JsROOT plots representable when converting to LaTeX using `nbconvert`:

```diff
--- a/JupyROOT/helpers/utils.py	2020-04-22 19:44:27.144068951 +0300
+++ b/JupyROOT/helpers/utils.py	2020-04-22 19:30:35.847373018 +0300
@@ -391,6 +391,18 @@
     def register(self):
         self.shell.events.register('post_execute', self._post_execute)
 
+class HTMLwithPDF(HTML):
+ def __init__ (self, data, drawableObject, **kwargs):
+ with tempfile.NamedTemporaryFile(suffix=".pdf") as ofile:
+ with _setIgnoreLevel(ROOT.kError):
+ drawableObject.SaveAs(ofile.name)
+ self._pdf = ofile.read()
+
+ super(HTMLwithPDF, self). __init__ (data, **kwargs)
+
+ def _repr_mimebundle_(self, include=None, exclude=None):
+ return { 'application/pdf': self._pdf }
+
 class NotebookDrawer(object):
     '''
     Capture the canvas which is drawn and decide if it should be displayed using
@@ -466,7 +478,7 @@
         return thisJsCode
 
     def _getJsDiv(self):
- return HTML(self._getJsCode())
+ return HTMLwithPDF(self._getJsCode(), self.drawableObject)
 
     def _jsDisplay(self):
         IPython.display.display(self._getJsDiv())

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [April 22, 2020, 5:41pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/2 "2020-04-22T17:41:54Z")

</div>

Hi,

Can you explain little bit more that is your code doing?  
`_getJsCode()` function returns just JSON code, which is inserted into HTML page.  
There is no SVG code until JSROOT rendering is performed.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![berserker](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/berserker/32/17693_2.png) [@berserker](https://root-forum.cern.ch/u/berserker)\
**Post date:** [April 22, 2020, 6:24pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/3 "2020-04-22T18:24:21Z")

</div>

Hi,

> [@linev](#):
>
> Can you explain little bit more that is your code doing?

It converts `drawableObject` to svg and attaches it to the object passed to `IPython.display.display`.

> [@linev](#):
>
> There is no SVG code until JSROOT rendering is performed.

Indeed, so I get nothing in place of plot when I convert a notebook to LaTeX.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [April 23, 2020, 3:56pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/4 "2020-04-23T15:56:58Z")

</div>

Hi,

To make `nbconvert` working one has to invoke JSROOT before.  
I am not sure how this can be implemented - normally JSROOT executed in context of the browser.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![berserker](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/berserker/32/17693_2.png) [@berserker](https://root-forum.cern.ch/u/berserker)\
**Post date:** [April 23, 2020, 7:00pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/5 "2020-04-23T19:00:11Z")

</div>

> [@linev](#):
>
> To make `nbconvert` working one has to invoke JSROOT before.  
> I am not sure how this can be implemented - normally JSROOT executed in context of the browser.

That’s why I propose to attach a statically ~~SVG~~ PDF-prerendered plot so that a user gets it when uses `nbconvert`.

---

<div class="post-metadata">

**Author:** ![sdusini](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@sdusini](https://root-forum.cern.ch/u/sdusini)\
**Post date:** [May 24, 2021, 12:35pm UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/6 "2021-05-24T12:35:50Z")

</div>

I am also looking for a solution to export notebooks with plots when jsroot is on. the proposal of @berserker which goes beyond my knowledge on how to implement, are there any other way?

Thanks a lot  
Stefano

---

<div class="post-metadata">

**Author:** ![OnaKoepp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@OnaKoepp](https://root-forum.cern.ch/u/OnaKoepp)\
**Post date:** [September 6, 2021, 9:05am UTC](https://root-forum.cern.ch/t/make-jupyter-notebook-with-jsroot-on-convertible-to-latex/39035/7 "2021-09-06T09:05:21Z")

</div>

I’ll be sure to keep an eye on this thread. Looking for the same info. Bumped into your thread.
