Show PDF in Julia Notebook & general advises for for jupyterlab extensions

Hey there,

I prepared a JupyterHub Server for a class and I converted old exercise material from matlab into beautiful julia notebooks. Unfortunately, I haven’t found any possibility to view PDF images in the notebook. Is there something similar for the Julia kernel like this: https://stackoverflow.com/questions/19470099/view-pdf-image-in-an-ipython-notebook ? I need this in order to get rid of the separately prepared latex documents. Final goal is to just export the notebooks as PDFs.

Besides that, do you have any advises regarding extensions? Do you use something like nbgrader for classes? Do you have any extension installed which was a game changer for teaching?

Edit: current workaround is to include svg as html img, however it’s very unlikely that I will have svgs from all figures I want to include.

Thanks and cheers,
Max

2 Likes

You can convert them to SVG, and then show SVG inline in the notebook. PGFPlotsX has a converter function (which calls pdf2svg I believe, so you have to have that installed).

using PGFPlotsX

# Create a PDF
x = range(0.0, 2pi; length=100)
y = sin.(x)
p = @pgf Axis({}, Plot({}, Coordinates(x, y)))
PGFPlotsX.save("sin.pdf", p)

# Create a PDF struct that can be showed as inline svg
struct PDF
    file::String
    PDF(file) = new(abspath(file))
end
function Base.show(io::IO, ::MIME"image/svg+xml", pdf::PDF)
    svg = first(splitext(pdf.file)) * ".svg"
    PGFPlotsX.convert_pdf_to_svg(pdf.file, svg)
    write(io, read(svg))
    try; rm(svg; force=true); catch e; end
    return nothing
end

PDF("sin.pdf")

I have not used it, but IIRC @mbauman has at least experimented with it.

5 Likes

I just tried it and it works :slight_smile: Thank you very much Fredrik!