Inserting Notebooks into LaTeX (LyX) documents?

I’m trying to figure out how to insert Jupyter Notebooks into LaTeX documents. Specifically, I’m interested in how to do this with LyX. Although the latest version of LyX (2.4.0, in RC4 at the moment) supports Unicode characters, it is not straightforward to use Unicode characters in Program Listings [at least not for me…]

I’m trying to see if I instead can convert Jupyter Notebooks to LaTeX code, and import the LaTeX code into LyX.

  • JupyterLab (via IJulia) has support for exporting the notebook to LaTeX in the file menu.

  • However, this export creates weird code that does not automatically import into LyX. Perhaps some packages is needed??

  • I can, of course, save the Jupyter Notebook to HTML, and then to PDF, and include the PDF file in LyX, but I assume that gives some restrictions as to having to start on a new page (??).

Any experience with this?

  • I’d probably prefer to treat headlines in the notebook as unnumbered headlines…
  • It would be even better to be able to import directly from the *.ipynb file, but that may require more LaTeX/LyX knowledge.
  • My notebooks typically contain markup-text, code cells – sometimes with Unicode characters, and output also in the form of plots.
  • Would it be simpler to do this using Pluto?
1 Like

The built-in Program Listings environment has its issues. I’ve had much more luck with Minted. This post covers much of what’s needed: What do you use to embed Julia code in LaTeX? - #2 by baggepinnen

1 Like

NotebookToLaTeX.jl might help.


Looks nice and simple to use. A handful of questions…

  • The documentation says it is in active development, but there has been no release for more than 2 years. Is that because it has been perfected, or because there have been few wishes for new possibilities?
  • OK – documentation seems to say that I need to use LuaTeX. I use MikTeX, which I assume is a distribution that also contains LuaTeX. It seems like I can easily switch to LuaTeX for preview.
    – Are there any disadvantages with LuaTeX? (It is less developed than pdflatex, I guess). Does LuaTeX work with KOMA script documents? (Seems like so.)
  • Documentation says that the package uses something called “julia-mono-listing”.
    – Is “julia-mono-listing” a package? Seems like so from the example (\usepackage{julia-mono-listing}…). If so, how can I download that package so that it works with MikTeX/LyX?
    – It seems like I also need to install fonts. But the following info is not clear to me:

    – I assume JuliaMono is a font that I need to install. But what is Julia Unicode? and Julia pygments? Do I need to install those, too?
    – The description seems to be directed towards Overleaf. Will the procedures for LyX be the same?
1 Like

So, I’m the one who developed the package. I did it for personal use, cause I wanted to ease the process of turning notebooks into LaTeX. The package has some rough edges. No new releases have been made cause I simply didn’t need anything else. Also, there wasn’t much request for new stuff.

The use of LuaTeX was no “my choice”, but because I used julia-mono-listing to allow for listings. The julia-mono-listings is not a package, but a bunch of latex configurations to write Julia code and apply propor syntax highlight and formatting. It uses the Julia-Mono font by default. But one can just alter for whatever font one wants.

I don’t know much about LaTeX in general. My package simply reads the notebook and produces some latex files, easing the process of writing everything from the start.

I don’t think pygments is actually used anywhere… You might want to read the julia-mono-listing repo. To be honest, my package simply uses the julia-mono-listing config, and I personally don’t quite know much about LaTeX. I’m more of a user for LaTeX then a dev.

1 Like