# Problems and advices using Julia in Emacs' Org babel

**URL:** <https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477>\
**Category:** Tooling\
**Tags:** emacs, literate-programming, notebooks\
**Created:** [October 9, 2022, 1:57pm UTC](https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477 "2022-10-09T13:57:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertulli](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Post date:** [October 9, 2022, 1:57pm UTC](https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477/1 "2022-10-09T13:57:24Z")

</div>

Hi all!

I wanted to embed some Julia code in some notes I’m taking, thus creating a notebook-like document. I am using Emacs with Org-mode, so I went for Org babel. I followed [the instructions on Worg](https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-julia.html), but I still have some problems. I collect them all here, if you think it’s better to open a topic for each one I can do it of course, and I apologize. Anyway:

- Simple blocks like

```julia
#+begin_src julia :results output
  4
#+end_src

```

actually are good. However, if I change the result type to

```julia
#+begin_src julia :results value
  4+4
#+end_src

```

the execution is **way** slower, taking roughly 8 seconds and quite a lot of CPU time (even if the result is still produced and correct). Why?

- How can I produce graphs and pictures? Having

```julia
#+begin_src julia :results output
  using Plots;
  t = 0:0.01:4;

  f₀ = 1; #Hz
  Fₛ = 2;
  Tₛ = 1/Fₛ;
  CTsignal = sin.(2π * f₀ * t);

  n = 0:Tₛ:4;
  DTsignal = sin.(2π * f₀ * t);

  graph = plot(t, CTsignal);
  graph = scatter!(n, DTsignal);

   gui(graph);
#+end_src

```

briefly produces the picture, but then it **closes automatically**. Can I keep the graph on screen?

- Starting time is quite slow if I use external packages, like in the previous example where I used `using Plots;`. In my usual Julia workflow I have a **sysimage** to speed up this time. Can I do the same in Org mode?

- Even if I end an instruction with a semicolon, the value of the expression is always printed. This is strange: can I stop it? Moreover, if I process a long array, all of it is printed in the document (possibly thousands of values!), whereas in the usual Julia REPL it’s condensed with a vertical **ellipsis** (`⋮`). Can I do the same in Org?

Thanks!

---

<div class="post-metadata">

**Author:** ![fsantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fsantos/32/44790_2.png) [@fsantos](https://discourse.julialang.org/u/fsantos)\
**Post date:** [October 10, 2022, 7:14am UTC](https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477/2 "2022-10-10T07:14:20Z")

</div>

Hi,  
I think you should also send this message to the [Org mailing list](https://orgmode.org/worg/org-mailing-list.html). The Julia support in Org is a very complicated (and quite disappointing) story, and it is really far from perfect. I tried myself to maintain [another backend](https://github.com/frederic-santos/ob-ess-julia), which is now deprecated since Org has an official `ob-julia` support. However, I’m not sure that it is actively maintained…

---

<div class="post-metadata">

**Author:** ![bertulli](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Post date:** [October 10, 2022, 10:36am UTC](https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477/3 "2022-10-10T10:36:22Z")

</div>

Thanks. I’ll have a look at it.

I’ve seen that my problems can be partially solved using [`ob-julia-vterm`](https://github.com/shg/ob-julia-vterm.el), available on MELPA. In particular:

- Evaluation of packages is still slow on the first time (I need to investigate if sysimages can be used). However, session is persisted (optionally it can be disabled), so subsequent runs are fast. Overall, it’s a usual Julia session
- Images can now be displayed
- `:results value` is just as fast as `:results output`
- Outputted vectors are abbreviated
- However, REPL outputs are not printed, unless it’s the last value returned and result type is `value` (which is the default). I mean a block like this:

```julia
#+begin_src julia :results value
  2*4
  1+4
#+end_src

```

produces

```julia
#+RESULTS:
: 5

```

even if in a usual Julia REPL we expect to see both `8` and `5`

---

<div class="post-metadata">

**Author:** ![fsantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fsantos/32/44790_2.png) [@fsantos](https://discourse.julialang.org/u/fsantos)\
**Post date:** [October 10, 2022, 11:21am UTC](https://discourse.julialang.org/t/problems-and-advices-using-julia-in-emacs-org-babel/88477/4 "2022-10-10T11:21:39Z")

</div>

Yep, `ob-julia-vterm` may be the best way to use Julia within Org-mode today!

As concerns your last remark,

> However, REPL outputs are not printed, unless it’s the last value returned and result type is `value` (which is the default).

I think this is really the intended behavior when using the `value` type, for all languages supported in Org-mode.
