Coder Social home page Coder Social logo

davibarreira / notebooktolatex.jl Goto Github PK

View Code? Open in Web Editor NEW
72.0 2.0 4.0 9.48 MB

A Julia package for converting your Pluto and Jupyter Notebooks into beautiful Latex.

License: MIT License

Julia 20.17% Jupyter Notebook 26.30% TeX 53.53%
latex julia-language julia-package notebook-jupyter pluto-notebooks

notebooktolatex.jl's Introduction

NotebookToLaTeX.jl

Build Status Coverage

Important: The package is still in active development, so things might change/break. Note that the package name is being changed from NotebookToLatex.jl to NotebookToLaTeX.jl in order to be more consistent with the naming of other packages in the Julia environment. If you've cloned this repo before that, you might want to delete and clone again.

If you try this package and find some bug, or think of a feature you'd like to have implemented, do not hesitate to open an issue.

Why this Package?

This package converts your notebook files (Pluto or Jupyter) to beautiful and simple LaTeX files, that are easy to modify. Thus, making it ideal to write reports, articles or books from notebooks.

NotebookToLaTeX Example

Although it's already possible to convert both Pluto and Jupyter notebooks to PDFs, or even to LaTeX (via Pandoc), the PDFs are not very customizable and the LaTeX files are usually very messy. In contrast, NotebookToLaTeX.jl focuses less in generality, and more on opinionated defaults.

The package has it's own implementation to parse Markdown to LaTeX, e.g. it turns # Example to \chapter{Example}. Thus, one can dive down into the actual Julia code and customize it for his own preference. Or, submit an issue requesting the feature. Hopefully, more and more customization will be possible from the get go as the package evolves.

Another very important point to note is that NotebookToLaTeX.jl uses julia-mono-listing. This enables it to produce beautiful Julia code inside the LaTeX pdf. Note that it requires using lualatex for compilation.

Getting Started

This package is very simple to use. There is pretty much just one function to be used, i.e.

notebooktolatex

Basic Use

To convert the notebooks just use notebooktolatex("mynotebook.ipynb", template=:book). This will produce a directory ./build_latex/ where the LaTeX files will be generated. Inside build_latex/ you will have:

build_latex
│   main.tex
│   julia_font.tex
│   julia_listings.tex
│   julia_listings_unicode.tex
│   preface.tex
│
└───figures
│   │   mynotebook_plot1.png
│   └───mynotebook_plot2.png
└───fonts
│   │   JuliaMono_Regular.ttf
│   │   ...
│   
└───frontmatter
│   │   titlepage.tex
│   └───copyright.tex
│
└───notebooks
    └───mynotebook.tex

Using template=:book, we get the LaTeX book format, thus, we have a preface.tex, a titlepage.tex and a copyright.tex page. The notebook will be included as a chapter. To get your final book pdf, just compile the main.tex using lualatex.

In case you want a different project folder, you can run the command with an extra argument providing the target directory for the LaTeX files, e.g.:

`notebooktolatex("mynotebook.ipynb", "./project/",template=:book)`.

This will create a ./project/ folder instead of the ./build_latex.

If instead you just want a simple report containing the Notebook, you can use the :article template.

Pluto Users

If you want to convert Pluto notebooks, you have to import Makie.jl, CairoMakie.jl and Plots.jl, which are the packages used in order to save your figures. The reason for this is that NotebookToLaTeX.jl uses Requires.jl in order to avoid these packages as dependencies. Hence, to convert Pluto, you have to run:

using Makie, CairoMakie, Plots
notebooktolatex("myplutonotebook.jl", template=:book)

Templates

At the moment, the available templates are:

  • :book - The standard LaTeX book template;
  • :mathbook - Very similar to :book, but with some extra packages for mathematics;
  • :article - Simple template using the article document class;
  • :matharticle - The article template with extra packages for mathematics.

Read the documentation for more information.

notebooktolatex.jl's People

Contributors

davibarreira avatar pitmonticone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

notebooktolatex.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

can't convert notebooks with package dependencies

When I try to convert a notebook 2x2Jacobians.jl that has a dependency on Symbolics (which is installed, and using Symbolics works at the julia> prompt), I get an error:

julia> using NotebookToLaTeX, Makie, CairoMakie, Plots

julia> notebooktolatex("notes/2x2Jacobians.jl", template=:book)
ERROR: ArgumentError: Package NotebookToLaTeX does not have Symbolics in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have NotebookToLaTeX checked out for development and have
  added Symbolics as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with NotebookToLaTeX
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1167 [inlined]
 [2] macro expansion
   @ ./lock.jl:223 [inlined]
 [3] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1144
 [4] top-level scope
   @ none:2
 [5] eval
   @ ./boot.jl:368 [inlined]
 [6] collectoutputs(notebookdata::Dict{Symbol, Any}, path::String)
   @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/plutoconverter.jl:91
 [7] plutotolatex(notebookname::String, targetdir::String; template::Symbol, fontpath::Nothing)
   @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/plutoconverter.jl:154
 [8] #notebooktolatex#30
   @ ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/NotebookToLaTeX.jl:56 [inlined]
 [9] top-level scope
   @ REPL[3]:1

It looks like it might be eval-ing the notebook in the wrong module, in NotebookToLaTeX.Runner (which cannot load Symbolics) rather than in Main (which can)?

Package NotebookToLaTeX does not have Pkg in its dependencies

The system is Mac Apple M3 max
Julia Version 1.10.0 (2023-12-25)
NotebookToLaTeX v0.1.5
Here is the message:


ERROR: ArgumentError: Package NotebookToLaTeX does not have Pkg in its dependencies:

  • You may have a partially installed environment. Try Pkg.instantiate()
    to ensure all packages in the environment are installed.
  • Or, if you have NotebookToLaTeX checked out for development and have
    added Pkg as a dependency but haven't updated your primary
    environment's manifest file, try Pkg.resolve().
  • Otherwise you may need to report an issue with NotebookToLaTeX
    Stacktrace:
    [1] macro expansion
    @ Base ./loading.jl:1770 [inlined]
    [2] macro expansion
    @ Base ./lock.jl:267 [inlined]
    [3] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1747
    [4] #invoke_in_world#3
    @ Base ./essentials.jl:921 [inlined]
    [5] invoke_in_world
    @ Base ./essentials.jl:918 [inlined]
    [6] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1740
    [7] top-level scope
    @ none:2
    [8] eval
    @ ./boot.jl:385 [inlined]
    [9] collectoutputs(notebookdata::Dict{Symbol, Any}, path::String)
    @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/plutoconverter.jl:91
    [10] plutotolatex(notebookname::String, targetdir::String; template::Symbol, fontpath::Nothing)
    @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/plutoconverter.jl:154
    [11] plutotolatex
    @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/plutoconverter.jl:135 [inlined]
    [12] #notebooktolatex#30
    @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/NotebookToLaTeX.jl:56 [inlined]
    [13] notebooktolatex
    @ NotebookToLaTeX ~/.julia/packages/NotebookToLaTeX/lDy6Q/src/NotebookToLaTeX.jl:54 [inlined]
    [14] top-level scope
    @ REPL[6]:1

Pluto Notebook Environments and @bind

Nice package, I could see this useful for writing journal articles. I was running into a few issues when converting Pluto.jl notebooks:

  1. The Pluto.jl @bind macro isn't in scope so notebooks with code lines using it throw:
notebooktolatex("MyNotebook.jl",template=:book)
ERROR: LoadError: UndefVarError: @bind not defined
  1. Similarly the environment/package setup within a pluto notebook isn't activated, so these have to be manually added in the working julia environment. Seems like somewhere before this function call:
    plutotolatex(notebook, targetdir, template=template, fontpath=fontpath)
    you should be able to use Pluto.activate_notebook_environment("MyNotebook.jl") to achieve configuring the environment if Pluto is added as a dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.