Ob-julia-vterm provides Org Babel support for the Julia Programming Language.
Babel is a function of the Emacs Org-mode that provides ability of executing code in various programming languages in Org buffers. With ob-julia-vterm, you can embed and execute Julia code and also capture the results in your Org documents.
You need to have julia-vterm installed in Emacs.
You can install ob-julia-vterm from MELPA. If you want to install it manually, download ob-julia-vterm.el into somewhere in your local directory and install it with the following.
(package-install-file "/path-to-download-dir/ob-julia-vterm.el")
You need to enable julia-vterm code block evaluation by customizing org-babel-load-languages or by adding the following lines to your init file.
(require 'org)
(add-to-list 'org-babel-load-languages '(julia-vterm . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)
By default, you need to specify julia-vterm
as the language name for source blocks. To use julia
as the language name, define the following aliases.
(defalias 'org-babel-execute:julia 'org-babel-execute:julia-vterm)
(defalias 'org-babel-variable-assignments:julia 'org-babel-variable-assignments:julia-vterm)
- A src code block with
julia-vterm
(orjulia
if you define the above aliases) specified as language will be executed withC-c C-c
(org-babel-execute-src-block
). The code is sent to a julia-vterm REPL and the result is inserted below the src code block. - You can specify
value
(functional mode, default) oroutput
(scripting mode) for:results
. - The results in
value
mode are formatted astext/plain
MIME type as in the REPL. To have the results in source code format, specifypp
in the:results
header argument. - Long Arrays in
value
results are truncated using ellipses by default. To show the full result without omission, specifynolimit
in the:results
header argument. - For graphics output (plots), specify
file
andgraphics
for:results
and filename with:file
. Then in the code block, save the output image with the filename. A link to the image is inserted as the result. It can be inline-displayed by Org.- For inline display of PDF or GIF/PNG animation, see org-inline-pdf and org-inline-anim.
- Session-based evaluation is supported.
- Without
:session
, the code block is executed inside alet
block. - With
:session
, the code block is executed inmain
session. - With
:session <name>
, the code block is executed in the named session. - Unlike most other ob-* packages, the buffer name for the Julia session will be automatically formatted as
*julia:<name>*
. So, you can just specify the pure name, such asmain
orses1
, for the session name.
- Without
- Passing code block arguments using
:var
is supported.- Currently, only a number or a string can be passed.
- Another code block or a result of a code block can be referred to and used as the argument.
- Execution of julia-vterm code blocks is asynchronous by default and does not block Emacs.
- As an exception, if you use babel’s
:var
reference from another block, the referencedjulia-vterm
block will be executed synchronously. - At this time, it is not possible to explicitly specify synchronous execution.
- As an exception, if you use babel’s
#+BEGIN_SRC julia
2π
#+END_SRC
#+RESULTS:
: 6.283185307179586
#+BEGIN_SRC julia :results output
println("Hello, Julia!")
#+END_SRC
#+RESULTS:
: Hello, Julia!
#+BEGIN_SRC julia :results none :session ses1
x = 12345
#+END_SRC
#+BEGIN_SRC julia :results none :session ses2
x = 67890
#+END_SRC
#+BEGIN_SRC julia :results value :session ses1
x
#+END_SRC
#+RESULTS:
: 12345
#+NAME: radius
#+BEGIN_SRC julia :results value
12.345
#+END_SRC
#+BEGIN_SRC julia :results value :var r = radius
"The area of a circle with radius of $r is $(π * r ^ 2)."
#+END_SRC
#+RESULTS:
: The area of the circle with radius of 12.345 is 478.7756573542473.
#+BEGIN_SRC julia :results file graphics :file plot.png :output-dir figs
using Plots
scatter(rand(100), rand(100))
savefig("figs/plot.png")
#+END_SRC
#+RESULTS:
[[file:figs/plot.png]]