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

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 <- xtable(tli[1:20, ])
digits(tli.table) <- matrix( 0:4, nrow = 20, ncol = ncol(tli)+1 )

options(repr.vector.quote=FALSE)

display_html(paste(capture.output(print(head(tli.table), type = 'html')), collapse="", sep=""))


# Cell 2 ------------------------------------------------------------------

display_html("<span style='color:red; float:right'>hello</span>")

# Cell 3 ------------------------------------------------------------------

display_markdown("[this](http://google.com)")

# Cell 4 ------------------------------------------------------------------

display_png(file="shovel-512.png")

# Cell 5 ------------------------------------------------------------------

display_html("<table style='width:20%;border:1px solid blue'><tr><td style='text-align:right'>cell 1</td></tr></table>")

enter image description here


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 <- lm(speed ~ ., data = cars)
xtable(model)

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.

Tags:

Html

Xml

R

Jupyter