How to render LaTeX / HTML in Jupyter (R)?

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I just started using Jupyter with R, and I'm wondering if there's a good way to display HTML or LaTeX output.

Here's some example code that I wish worked:

library(xtable) x 

Instead of rendering the HTML, it just displays it as plaintext. Is there any way to change that behavior?

回答1:

A combination of repr (for setting options) and IRdisplay will work for HTML. Others may know about latex.

# Cell 1 ------------------------------------------------------------------  library(xtable) library(IRdisplay) library(repr)  data(tli) tli.table hello")  # Cell 3 ------------------------------------------------------------------  display_markdown("[this](http://google.com)")  # Cell 4 ------------------------------------------------------------------  display_png(file="shovel-512.png")  # Cell 5 ------------------------------------------------------------------  display_html("
cell 1
")



回答2:

I found a simpler answer, for the initial, simple use case.

If you call xtable without wrapping it in a call to print, then it totally works. E.g.,

library(xtable) data(cars) model 


回答3:

In Jupyter, you can use Markdown. Just be sure to change the Jupyter cell from a code cell to a Markdown cell. Once you have done this you can simply place a double dollar sign ("$$") before and after the LaTex you have. Then run the cell.

The steps are as follows: 1. Create a Markdown cell. 2. $$ some LaTex $$ 3. Press play button within Jupyter.



回答4:

Defining the following function in the session will display objects returned by xtable as html generated by xtable:

repr_html.xtable 

Without the repr_html.xtable function, because the returned object is also of class data.frame, the display system in the kernel will rich display that object (=html table) via repr::repr_html.data.frame.

Just don't print(...) the object :-)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!