Commit 026d9540 authored by G. Jay Kerns's avatar G. Jay Kerns

added words about the special character vertical ellipses

parent 7eec898a
......@@ -6,9 +6,10 @@
#+PROPERTY: results output
#+PROPERTY: session *julia*
#+PROPERTY: tangle yes
#+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{⋮}
#+PROPERTY: eval no-export
#+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{\vdots}
One of the reasons for this document is that I wanted to make it easier to get acquainted with =julia=.
This document is a /brief/ introduction to =julia=. It is based on a /Brief Introduction to R/ (an abbreviated Chapter 2 of [[http:ipsur.org][IPSUR]]) which I usually distribute to students using R for the first time. One of the reasons for this document is that I wanted to get better acquainted with =julia= and make it easier for others to get better acquainted, too.
* What you need to get started
......@@ -38,10 +39,9 @@ Pkg.add("DataFrames", "Distributions", "GLM", "MCMC", "Optim",
Pkg.add("RDatasets")
#+END_SRC
*** Winston
The most stable and fully featured of the =julia= graphics packages at the time of this writing appears to be the =Winston= package, among alternatives including =Gadfly=.
The most stable and fully featured of the =julia= graphics packages at the time of this writing appears to be the =Winston= package, though the =Gadfly= package is available and looks promising.
#+BEGIN_SRC julia :eval never
Pkg.add("Winston")
......@@ -121,11 +121,26 @@ The place to get the latest version of ESS is [[http://stat.ethz.ch/ESS/index.ph
There are three basic methods for communicating with julia.
- An Interactive session (julia>). :: This is the most basic way to complete simple, one-line commands. Do =M-x julia RET= during an Emacs session and the Emacs/ESS julia mode will open in a buffer. Type whatever command you like; julia will evaluate what is typed there and output the results in the buffer.
- Source files. :: For longer programs (called /scripts/) there is too much code to write all at once in an interactive session. Also, sometimes we only wish to modify a small piece of the script and run it again in julia.
The way to do this is to open a dedicated julia script buffer with the sequence =C-x C-f whatever.jl=, where =whatever.jl= is a julia script which you've named whatever. Write the code in the buffer, then when satisfied the user evaluates lines or regions according to the following table. Then julia will evaluate the respective code and give output in the interactive buffer.
- An Interactive session (julia>). :: This is the most basic way to
complete simple, one-line commands. Do =M-x julia RET= during an
Emacs session and the Emacs/ESS =julia= mode will open in a buffer.
Type whatever command you like; =julia= will evaluate what is typed
there and output the results in the buffer.
- Source files. :: For longer programs (called /scripts/) there is too
much code to write all at once in an interactive
session. Also, sometimes we only wish to modify a
small piece of the script and run it again in
=julia=.
The way to do this is to open a dedicated =julia= script buffer with
the sequence =C-x C-f whatever.jl=, where
=whatever.jl= is a =julia= script which you've named
whatever. Write the code in the buffer, then when
satisfied the user evaluates lines or regions
according to the following table. Then =julia= will
evaluate the respective code and give output in the
interactive buffer.
| =C-RET= | Send region or current line and step to next line of code. |
| =M-C-x= | Send region or function or paragraph. |
......@@ -133,15 +148,15 @@ There are three basic methods for communicating with julia.
- Script mode. ::
** julia is one fancy calculator
** =julia= is one fancy calculator
julia can do any arithmetic you can imagine. For example, in an interactive session type =2 + 3= and observe
=julia= can do any arithmetic you can imagine. For example, in an interactive session type =2 + 3= and observe
#+BEGIN_SRC julia
2 + 3
#+END_SRC
The =julia>= means that julia is waiting on your next command. Entry numbers will be generated for each row, such as
The =julia>= means that =julia= is waiting on your next command. Entry numbers will be generated for each row, such as
#+BEGIN_SRC julia
[3:50]
......@@ -173,7 +188,7 @@ The =julia>= means that julia is waiting on your next command. Entry numbers wil
50
#+end_example
Notice that julia doesn't show the whole list of numbers, it elides them with vertical ellipses \(\vdots\). Note also the =[3:50]= notation, which generates all integers in sequence from 3 to 50. One can also do things like
Notice that =julia= doesn't show the whole list of numbers, it elides them with vertical ellipses \(\vdots\). Note also the =[3:50]= notation, which generates all integers in sequence from 3 to 50. One can also do things like
#+BEGIN_SRC julia :eval no-export
2 * 3 * 4 * 5 # multiply
......@@ -189,18 +204,18 @@ sqrt(-2)
: ERROR: DomainError()
: in sqrt at math.jl:111
Notice that a =DomainError()= was produced; we are not allowed to take square roots of negative numbers. Also notice the number sign =#=, which is used for comments. Everything typed on the same line after the =#= will be ignored by julia. There is no julia continuation prompt. If you press =RET= before a statement is complete then empty lines keep piling up until you finish the command.
Notice that a =DomainError()= was produced; we are not allowed to take square roots of negative numbers. Also notice the number sign =#=, which is used for comments. Everything typed on the same line after the =#= will be ignored by julia. There is no =julia= continuation prompt. If you press =RET= before a statement is complete then empty lines keep piling up until you finish the command.
Some other fuctions that will be of use are =abs()= for absolute value, =log()= for the natural logarithm, =exp()= for the exponential function, and =factorial()= for... uh... factorials.
Assignment is useful for storing values to be used later. Notice the semicolon at the end of the first statement. Without the semicolon, julia would print the result of the assigment (namely, =5=).
Assignment is useful for storing values to be used later. Notice the semicolon at the end of the first statement. Without the semicolon, =julia= would print the result of the assigment (namely, =5=).
#+BEGIN_SRC julia
y = 5; # stores the value 5 in y
3 + y
#+END_SRC
There aren't other assignment operators (like =<-= in R). For variable names you can use letters. (possibly followed by) numbers, and/or underscore "_" characters. You cannot use mathematical operators, you cannot use dots, and numbers can't go in front of numbers (those are interpreted by julia as coefficients). Examples: =x=, =x1=, =y32=, =z_var=.
There aren't other assignment operators (like =<-= in R). For variable names you can use letters. (possibly followed by) numbers, and/or underscore "_" characters. You cannot use mathematical operators, you cannot use dots, and numbers can't go in front of numbers (those are interpreted by =julia= as coefficients). Examples: =x=, =x1=, =y32=, =z_var=.
If you would like to enter the data 74,31,95,61,76,34,23,54,96 into julia, you may create a data array with double brackets (the analogue of the =c()= function in R).
......@@ -246,7 +261,7 @@ fred[[1, 3, 5, 8]]
Notice we needed double brackets for the third example. If you would like to empty the array =fred=, you can do it by typing =fred = []=.
Data arrays in julia have type. There are all sorts of integer types (=Int8=, =uInt8=, =Int32=, ...), strings (=ASCIIString=), logical (=Bool=), unicode characters (=Char=), then there are floating-point types (=Float16=, =Float32=), even complex numbers like =1 + 2im= and even rational numbers like =3//4=, not to mention =Inf=, =-Inf=, and =NaN= (which stands for /not a number/). If you ever want to know what it is you're dealing with you can find out with the =typeof= function.
Data arrays in =julia= have type. There are all sorts of integer types (=Int8=, =uInt8=, =Int32=, ...), strings (=ASCIIString=), logical (=Bool=), unicode characters (=Char=), then there are floating-point types (=Float16=, =Float32=), even complex numbers like =1 + 2im= and even rational numbers like =3//4=, not to mention =Inf=, =-Inf=, and =NaN= (which stands for /not a number/). If you ever want to know what it is you're dealing with you can find out with the =typeof= function.
#+BEGIN_SRC julia
simpsons = ["Homer", "Marge", "Bart", "Lisa", "Maggie"]
......@@ -273,7 +288,7 @@ x >= 6
:
: false
Notice the ~>=~ symbol which stands for "greater than or equal to". Many functions in julia are vectorized. Once we have stored a data vector then we can evaluate functions on it.
Notice the ~>=~ symbol which stands for "greater than or equal to". Many functions in =julia= are vectorized. Once we have stored a data vector then we can evaluate functions on it.
#+BEGIN_SRC julia
sum(fred)
......@@ -290,7 +305,7 @@ mean(fred) # sample mean, should be same answer
Other popular functions for vectors are =min()=, =max()=, =sort()=, and =cumsum()=.
Arithmetic in julia is usually done element-wise, and the operands must be of conformable dimensions.
Arithmetic in =julia= is usually done element-wise, and the operands must be of conformable dimensions.
#+BEGIN_SRC julia
fred2 = [4, 5, 3, 6, 4, 6, 7, 3, 1];
......@@ -338,7 +353,7 @@ The operations =+= and =-= are performed element-wise. Notice in the last vector
** Getting Help
When you are using julia it will not take long before you find yourself needing help. The help resources for julia are not as extensive as those for some other languages (such as R). julia is new and many of the help topics haven't been written yet. Nevertheless sometimes a person is lucky and you can get help on a function when it's available with the =help()= function.
When you are using =julia= it will not take long before you find yourself needing help. The help resources for =julia= are not as extensive as those for some other languages (such as R). =julia= is new and many of the help topics haven't been written yet. Nevertheless sometimes a person is lucky and you can get help on a function when it's available with the =help()= function.
#+BEGIN_SRC julia
help("factorial")
......@@ -359,27 +374,17 @@ Note also =example()=. This initiates the running of examples, if available, of
* Other tips
It is unnecessary to retype commands repeatedly, since julia remembers what you have entered on the command line. To cycle through the previous commands, just push the \uparrow (up arrow) key.
Missing values in julia are denoted by =NA=. Operations on data vector =NA= values treat them as if the values can't be found. This means adding (as well as subtracting and all of the other mathematical operations) a number to =NA= results in =NA=.
It is unnecessary to retype commands repeatedly, since Emacs/ESS remembers what you have entered at the =julia>= prompt. To navigate through previous commands put point at the lowest command line and push either =M-p= or =M-n=.
To find out what all variables are in the current work environment, use the commands =ls()= or =objects()=. These list all available objects in the workspace. If you wish to remove one or more variables, use =remove(var1, var2)=, and to remove all of them use =rm(list=ls())=.
** Other resources
- Check out the official julia manual [[http://docs.julialang.org/en/latest/manual/][here]].
- Check out the official =julia= manual [[http://docs.julialang.org/en/latest/manual/][here]].
- The /Standard Library/ (a different type of manual) is [[http://docs.julialang.org/en/latest/stdlib/][here]].
- There is a vibrant and growing julia community whose gateway is [[http://julialang.org/community/][here]].
- There is a vibrant and growing =julia= community whose gateway is [[http://julialang.org/community/][here]].
- There is a large and growing list of contributed packages [[http://docs.julialang.org/en/latest/packages/packagelist/][here]].
#+BEGIN_SRC julia :results value
rand(2,3)
#+END_SRC
#+BEGIN_SRC julia :results output
print("hello")
#+END_SRC
* Plotting with Winston
#+BEGIN_SRC julia :results graphics :file example1.png :eval no-export
......@@ -400,37 +405,31 @@ file(p, "example1.png")
#+RESULTS:
[[file:example1.png]]
* Plotting with Gadfly
* Fitting (generalized) linear models
#+BEGIN_SRC julia :results graphics :file iris_plot.svg :eval never
using RDatasets
using Gadfly
using Compose
iris = data("datasets", "iris")
p = plot(iris, {:x => "Sepal.Length", :y => "Sepal.Width"}, Geom.point);
SVG("iris_plot.svg", 6inch, 4inch)
#+END_SRC
Douglas Bates (of [[http://www.springer.com/statistics/statistical+theory+and+methods/book/978-1-4419-0317-4][Mixed Effects Models in S and S-PLUS]] fame) has been putting together a =julia= package called GLM which already supports fitting generalized linear models to datasets. This, together with the RDatasets package means there is already a bunch of stuff to keep a person busy. Below is a modified example from the Multiple Regression chapter of IPSUR, translated to =julia= speak.
* Fitting (generalized) linear models
First, we load the packages we'll need.
#+BEGIN_SRC julia
#+BEGIN_SRC julia :exports code
using RDatasets, DataFrames, Distributions, GLM
#+END_SRC
Next we load the =trees= data frame from the RDatasets package and fit a linear model to the data.
#+BEGIN_SRC julia :exports code
trees = data("datasets", "trees");
treeslm = lm(:(Girth ~ Height + Volume), trees);
treeslm = lm(:(Girth ~ Height + Volume), trees)
#+END_SRC
The extended output above should look similar to something we might see in an R session. We can extract the model coefficients with the =coef= function:
#+BEGIN_SRC julia :exports code
coef(treeslm)
coeftable(treeslm)
#+END_SRC
#+RESULTS:
#+begin_example
3-element Float64 Array:
10.8164
-0.0454835
0.19518
3x4 DataFrame:
Estimate Std.Error t value Pr(>|t|)
[1,] 10.8164 1.9732 5.48165 7.44691e-6
[2,] -0.0454835 0.0282621 -1.60935 0.118759
[3,] 0.19518 0.0109553 17.8161 8.2233e-17
#+end_example
and we can look at a summary table similar to something like =summary(treeslm)= in R
#+BEGIN_SRC julia :exports code
coeftable(treeslm)
#+END_SRC
......@@ -6,19 +6,29 @@
#+PROPERTY: results output
#+PROPERTY: session *julia*
#+PROPERTY: tangle yes
#+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{}
#+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{\vdots}
This document is an introduction to Org-mode + =julia=. The only prerequisites are a passing familiarity with Org-mode and Emacs keybindings.
This document is an introduction to Org-mode + =julia=. The only
prerequisites are a passing familiarity with Org-mode and Emacs
keybindings.
\newpage
* What you need to get started
- Note: :: a lot of the code blocks below have the header argument =:eval no-export=. This means that the code block can be evaluated interactively by =C-c C-c= with point in the code block but will /not/ be evaluated during export. That header argument is present because those blocks have settings which conflict with my current setup (or are otherwise redundant) yet are meant to be useful for other people working through this document.
- Note: :: a lot of the code blocks below have the header argument
=:eval no-export=. This means that the code block can be
evaluated interactively by =C-c C-c= with point in the code
block but will /not/ be evaluated during export. That
header argument is present because those blocks have
settings which conflict with my current setup (or are
otherwise redundant) yet are meant to be useful for other
people working through this document.
** Julia
You are going to need a working installation of =julia=. The homepage on [[https://github.com/JuliaLang/julia][GitHub]] has the pertinent links collected all in one place:
You are going to need a working installation of =julia=. The homepage
on [[https://github.com/JuliaLang/julia][GitHub]] has the pertinent links collected all in one place:
- *Homepage:* http://julialang.org
- *Binaries:* http://code.google.com/p/julialang/downloads/list
......@@ -29,35 +39,51 @@ You are going to need a working installation of =julia=. The homepage on [[http
- *Git clone URL:* =git://github.com/JuliaLang/julia.git=
- *Documentation:* http://julialang.org/manual/
_Fair warning:_ the initial install takes a /long time/, largely because julia has a lot of dependencies. Never fear, though; subsequent updates are brief.
_Fair warning:_ the initial install takes a /long time/, largely
because julia has a lot of dependencies. Never fear, though;
subsequent updates are brief.
** ESS - Emacs Speaks Statistics
You are going to need a relavely bleeding-edge version of ESS since it is only due to recent ESS changes that this document is even possible. The place to look for the latest version of ESS is [[http://stat.ethz.ch/ESS/index.php?Section=download][here]]. One of the options offered there is to clone [[https://github.com/emacs-ess/ESS][the ESS github repository]] and put the following in your =.emacs= (or whatever other initialiation file you use):
You are going to need a relavely bleeding-edge version of ESS since it
is only due to recent ESS changes that this document is even possible.
The place to look for the latest version of ESS is [[http://stat.ethz.ch/ESS/index.php?Section=download][here]]. At some
point after installation you will likely put something like the
following in your =.emacs=:
#+BEGIN_SRC emacs-lisp :eval never
(add-to-list 'load-path "/path/to/ESS/lisp")
(require 'ess-site)
#+END_SRC
Once ESS is up and running you will need to tell it where the =julia= executable is. Edit the following and place it in your =.emacs=:
Once ESS is up and running you will need to tell it where the =julia=
executable is. Edit the following and place it in your =.emacs=:
#+BEGIN_SRC emacs-lisp :eval never
(setq inferior-julia-program-name "/path/to/julia-release-basic")
#+END_SRC
After the above steps are complete then you should be able to start Emacs and launch an interactive =julia= session via =M-x julia=. If you manage to get that settled then at this point you should be able to do everything in the [[file:intro-julia.org][Introduction to Julia]].
After the above steps are complete then you should be able to start
Emacs and launch an interactive =julia= session via =M-x julia=. If
you manage to get that settled then at this point you should be able
to do everything in the [[file:intro-julia.org][Introduction to Julia]].
** Add-on packages
There is a large (and growing) list of [[http://docs.julialang.org/en/release-0.1/packages/packagelist/][contibuted packages]] which add to the base functionality of =julia=. For example, several statistics packages were recently mentioned in a blog post by [[https://github.com/johnmyleswhite][John Myles White]] entitled [[http://www.johnmyleswhite.com/notebook/2012/12/02/the-state-of-statistics-in-julia/][The State of Statistics in Julia]]. The instructions in the blog post are (already) a bit out-of-date; the currently recommended way to install the packages is to launch an interactive =julia= session and execute the following command:
There is a growing list of [[http://docs.julialang.org/en/release-0.1/packages/packagelist/][contibuted packages]] which add to the base
functionality of =julia=. For example, several statistics packages
were mentioned a few moths ago in a blog post by [[https://github.com/johnmyleswhite][John Myles White]]
entitled [[http://www.johnmyleswhite.com/notebook/2012/12/02/the-state-of-statistics-in-julia/][The State of Statistics in Julia]]. The instructions in the
blog post are (already) a bit out-of-date; the currently recommended
way to install the packages is to launch an interactive =julia=
session and execute the following command:
#+BEGIN_SRC julia :eval no-export
Pkg.add("DataFrames", "Distributions", "GLM", "MCMC", "Optim",
"NHST", "Clustering")
#+END_SRC
As John notes, the =RDatasets= package takes a lot longer to download than the others. Perhaps it would be wise to install it separately.
As John notes, the =RDatasets= package takes a lot longer to download
than the others. Perhaps it would be wise to install it separately.
#+BEGIN_SRC julia :eval no-export
Pkg.add("RDatasets")
......@@ -65,7 +91,8 @@ Pkg.add("RDatasets")
** Org-mode
Since you have at least a passing familiarity with org-mode then you probably already have something like the following in your =.emacs=:
Since you have at least a passing familiarity with org-mode then you
probably already have something like the following in your =.emacs=:
#+BEGIN_SRC emacs-lisp :eval no-export
(require 'org)
......@@ -77,7 +104,8 @@ Another handy setting to have is
(setq org-confirm-babel-evaluate nil)
#+END_SRC
The following lines (either here or in your =.emacs=) permit inline image display in the Emacs buffer.
The following lines (either here or in your =.emacs=) permit inline
image display in the Emacs buffer.
#+BEGIN_SRC emacs-lisp :eval no-export
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
......@@ -86,13 +114,18 @@ The following lines (either here or in your =.emacs=) permit inline image displa
** =ob-julia.el=
You are going to want a copy of =ob-julia.el= to fully integrate =julia= with Org-mode. You can find it and some other documents to get you started [[https://github.com/gjkerns/ob-julia][here]]. Download =ob-julia.el= into a convenient place. Edit the code block below and evaluate it by =C-c C-c= with point in the code block.
You are going to want a copy of =ob-julia.el= to fully integrate
=julia= with Org-mode. You can find it and some other documents to
get you started [[https://github.com/gjkerns/ob-julia][here]]. Download =ob-julia.el= into a convenient place.
Edit the code block below and evaluate it by =C-c C-c= with point in
the code block.
#+BEGIN_SRC emacs-lisp :results silent :eval no-export
(load "/path/to/ob-julia.el")
#+END_SRC
An alternative method is to put the following in your =.emacs= (these should go below the =(require 'org)= line):
An alternative method is to put the following in your =.emacs= (these
should go below the =(require 'org)= line):
#+BEGIN_SRC emacs-lisp :eval no-export
(add-to-list 'load-path "/path/to/ob-julia.el")
......@@ -105,7 +138,8 @@ You are all set.
* Evaluation inside the Org buffer
If you've gotten this far then everything is installed in the right place and initialized properly. Now the fun begins.
If you've gotten this far then everything is installed in the right
place and initialized properly. Now the fun begins.
** :results value
......@@ -113,23 +147,34 @@ If you've gotten this far then everything is installed in the right place and in
* Graphics
The most stable and fully featured of the =julia= graphics packages at the time of this writing appears to be the [[https://github.com/nolta/Winston.jl][Winston package]], although the [[https://github.com/dcjones/Gadfly.jl][Gadfly package]] is also available and appears promising. To install the Winston package execute the following in an interactive session. I recommend you *not* execute te (if you do it in this buffer then you can't watch the download and install as it is happening).
The most stable and fully featured of the =julia= graphics packages at
the time of this writing appears to be the [[https://github.com/nolta/Winston.jl][Winston package]], although
the [[https://github.com/dcjones/Gadfly.jl][Gadfly package]] is also available and appears promising. To
install the Winston package execute the following in an interactive
session. I recommend you *not* execute this here (if you do it in
this buffer then you can't watch the download and install as it is
happening).
#+BEGIN_SRC julia :eval never
Pkg.add("Winston")
#+END_SRC
The Winston package has lots of dependencies and many of them must be built from source (on Ubuntu).
The Winston package has lots of dependencies and many of them must be
built from source (on Ubuntu).
** Plotting with Winston
To get up and running with plots in =julia= check out the many example graphs (with code) on the [[https://github.com/nolta/Winston.jl/blob/master/doc/examples.md][Winston examples page]]. As far as Org-mode is concerned, you can do plotting
To get up and running with plots in =julia= check out the many example
graphs (with code) on the [[https://github.com/nolta/Winston.jl/blob/master/doc/examples.md][Winston examples page]]. As far as Org-mode is
concerned, you can do plotting
1. Interactively with a plot window,
2. In-buffer with a =png=,
3. Via export into LaTeX, HTML, Beamer...
Let's describe each in turn. All three methods require setting up the plot object as a first step, after, of course, loading the Winston package. Let's set up a simple plot object (do =C-c C-c= with point in the block):
All three methods require setting up the plot object as a first step,
after, of course, loading the Winston package. Let's set up a simple
plot object (do =C-c C-c= with point in the block):
#+BEGIN_SRC julia :results silent :eval no-export
using Winston
......@@ -145,29 +190,65 @@ add(p, Curve(x, c, "color", "red") )
add(p, Curve(x, s, "color", "blue") )
#+END_SRC
We did =:results silent= to omit the lengthy output from being inserted in the org buffer. So the hard part is finished -- we've created a plot object =p= which is now available to manipulate.
We did =:results silent= to omit the lengthy output from being
inserted in the org buffer. So the hard part is finished -- we've
created a plot object =p= which is now available to manipulate.
To launch a plot window and look at the graph right now evaluate the following code block.
To launch a plot window and look at the graph right now evaluate the
following code block.
#+BEGIN_SRC julia :exports code :eval no-export
Winston.tk(p)
#+END_SRC
A plot should open in an X11 window with a pretty graph. Suppose instead we'd like to insert the graph in the org buffer right now. We need the inline-image display options described in section [[Org mode]]. Assuming you've done that, evaluate the following code block.
A plot should open in an X11 window with a pretty graph. Suppose
instead we'd like to insert the graph in the org buffer right now. We
need the inline-image display options described in section [[Org
mode]]. Assuming you've done that, evaluate the following code block.
#+BEGIN_SRC julia :results graphics :file example1.png :eval no-export
file(p, "example1.png")
#+END_SRC
The code block evaluates the command =file(p, "example1.png")=, which tells =julia= to write the graph to a =.png= file (also available are =.pdf=, =.svg=, and =.eps=, though none of those can be inserted in the org buffer). The header argument =:results graphics= tells org-mode that the results are going to be graphics (as opposed to elisp tables or STDOUT output) and the header argument =:file example1.png= tells org to insert an link to the file =example1.png= (just created by =julia=) right after the the code block. This link is evaluated by =org-display-inline-images= which results in a =.png= in the org buffer.
Notice that we had to specify the file name /twice/, once inside the code block and once as a header argument. Some languages (such as R) only require one specification: the header argument. The reason for this is simple: =ob-R.el= includes code which dynamically constructs a graphics device call behind the scenes, the call depending on the file extension in the =:file= header argument. Such a thing is more difficult with =julia= because different graphics packages have markedly different device calls (for instance, =Gadfly= uses =SVG("filename", p)=). Maybe someday the calls will stabilize and it will make sense to write wrapper code to do that automatically. In the meantime, use whatever package you like and write the filename twice.
The code block evaluates the command =file(p, "example1.png")=, which
tells =julia= to write the graph to a =.png= file (also available are
=.pdf=, =.svg=, and =.eps=, though none of those can be inserted in
the org buffer). The header argument =:results graphics= tells
org-mode that the results are going to be graphics (as opposed to
elisp tables or STDOUT output) and the header argument =:file
example1.png= tells org to insert an link to the file =example1.png=
(just created by =julia=) right after the the code block. This link
is evaluated by =org-display-inline-images= which results in a =.png=
in the org buffer.
Notice that we had to specify the file name /twice/, once inside the
code block and once as a header argument. Some languages (such as R)
only require one specification: the header argument. The reason for
this is simple: =ob-R.el= includes code which dynamically constructs a
graphics device call behind the scenes, the call depending on the file
extension in the =:file= header argument. Such a thing is more
difficult with =julia= because different graphics packages have
markedly different device calls (for instance, =Gadfly= uses
=SVG("filename", p)=). Maybe someday the calls will stabilize and it
will make sense to write wrapper code to do that automatically. In
the meantime, use whatever package you like and write the filename
twice.
We'll defer the export method discussion to the next section.
* Export to other formats
Sonner or later you will want to share your work with others, people who have not (yet) fully come to the realization that Emacs+Org is really quite better than sliced bread and also is destined to conquer the entire observable Universe. Perhaps you'd like to make a presentation about how awesome =julia= is at a(n) (inter)national conference. Org-mode supports export to multiple formats. Here we'll describe a few. There has been work recently on a brand new exporter which hasn't yet made it to the official maintenance branch as of the time of this writing. The following instructions apply to the new exporter, which is one of the reasons why it was important in the first section to update your Org-mode.
Sooner or later you will want to share your work with others, people
who have not (yet) fully come to the realization that Emacs+Org is
really quite better than sliced bread and also is destined to conquer
the entire observable Universe. Perhaps you'd like to make a
presentation about how awesome =julia= is at a(n) (inter)national
conference. Org-mode supports export to multiple formats. Here we'll
describe a few. There has been work recently on a brand new exporter
which hasn't yet made it to the official maintenance branch as of the
time of this writing. The following instructions apply to the new
exporter, which is one of the reasons why it was important in the
first section to update your Org-mode.
** HTML
This is the easiest. Insert the following in your =.emacs=:
......@@ -176,13 +257,16 @@ This is the easiest. Insert the following in your =.emacs=:
(require 'ox-html)
#+END_SRC
Then open this file and execute =C-c C-e= to open the export dispatcher. From there you have three options:
Then open this file and execute =C-c C-e= to open the export
dispatcher. From there you have three options:
1. =h H= exports as an HTML buffer (can be saved later),
2. =h h= exports as an HTML file (saved in the working directory),
3. =h o= exports as an HTML file and opens in a browser.
That's it. There are a lot of other cool things you can do; see the Org manual. If you export to HTML then you are going to want your images (if any) to be =.png= or =.svg= files.
That's it. There are a lot of other cool things you can do; see the
Org manual. If you export to HTML then you are going to want your
images (if any) to be =.png= or =.svg= files.
** LaTeX
......@@ -199,34 +283,81 @@ Then open this file and do
3. =C-c C-e l p= to export as LaTeX and generate a PDF,
3. =C-c C-e l o= to export as LaTeX, generate PDF, and open.
There are a /ton/ of other LaTeX things to do. See the Org manual. If you export to PDF then it's fine to use image formats =.png=, =.eps=, or =.pdf=, but the =.png= exports as a blurry raster image - use =.pdf= instead (or =.eps= for external plain LaTeX export).
There are a /ton/ of other LaTeX things to do. See the Org manual.
If you export to PDF then it's fine to use image formats =.png=,
=.eps=, or =.pdf=, but the =.png= exports as a blurry raster image -
use =.pdf= instead (or =.eps= for external plain LaTeX export).
** Beamer
Beamer is a special case unto itself. The short story is that you need the following in your =.emacs=:
Beamer is a special case unto itself. The short story is that you need
the following in your =.emacs=:
#+BEGIN_SRC emacs-lisp :eval no-export
(require 'ox-beamer)
#+END_SRC
Then also add an entry for the beamer class in your =.emacs=. Here is a boilerplate version which you can customize to taste:
Then also add an entry for the beamer class in your =.emacs=. Here is
a boilerplate version which you can customize to taste:
#+BEGIN_SRC emacs-lisp :eval no-export
(add-to-list 'org-latex-classes
'("beamer"
"\\documentclass[presentation]{beamer}
\[DEFAULT-PACKAGES]
\[PACKAGES]
\[EXTRA]"
\[DEFAULT-PACKAGES]
\[PACKAGES]
\[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
#+END_SRC
Since beamer is such a special case I have tweaked a minimal =julia= beamer presentation in [[file:ob-julia-beamer.org][Sample =julia= Presentation]]. See there, see the Org manual, and see Worg too for more information.
* Other things
- You can extract all of the =julia= source code (also known as /tangling/ the Org document) with the keystrokes =C-c C-v t=. This will generate a =julia= script (with extension =.jl=) in the working directory. Note that this capability is turned off by default. You can activate it by adding the header argument =:tangle yes= to those code blocks you'd like to tangle or doing a buffer-wide header setting with the line =#+PROPERTY: tangle yes= near the top of the org file. See the Org manual for details.
- You may have noticed that those =julia= code lines with no output (for instance, lines with semicolons =;= at the end) generate an empty line in the =#+RESULTS= below the code block. Consequently, the first time you evaluate a =julia= code block without having previously initiated a =julia= session with =M-x julia= the =#+RESULTS= will have an extra mystery empty line. It is no mystery. The first statement executed by ESS when loading =julia= is an =include= command. That command has no output. If that empty line bothers you then execute the code block again; the mystery empty line will disappear.
- Be careful when executing code blocks with =:results value=. Code block evaluation in that case works by writing the =julia= commands to an external file in the =/tmp= directory, evaluating the commands with =julia=, writing the results to a comma-separated (=.csv=) file, then reading the =.csv= file and converting the result to =elisp= for insertion to the org buffer. Not all object types are supported by =julia= for writing to =.csv= files, in particular, =1x1= matrices and arrays of ASCII characters are not supported (yet). If you try to evaluate code blocks in those cases (or any other case where output to =.csv= is not supported) then you will get an error.
Since beamer is such a special case I have tweaked a minimal =julia=
beamer presentation in [[file:ob-julia-beamer.org][Sample =julia= Presentation]]. See there, see the
Org manual, and see Worg too for more information.
* Other things to mention
- You can extract all of the =julia= source code (also known as
/tangling/ the Org document) with the keystrokes =C-c C-v t=. This
will generate a =julia= script (with extension =.jl=) in the working
directory. Note that this capability is turned off by default. You
can activate it by adding the header argument =:tangle yes= to those
code blocks you'd like to tangle or doing a buffer-wide header
setting with the line =#+PROPERTY: tangle yes= near the top of the
org file. See the Org manual for details.
- You may have noticed that those =julia= code lines with no output
(for instance, lines with semicolons =;= at the end) generate an
empty line in the =#+RESULTS= below the code block. Consequently,
the first time you evaluate a =julia= code block without having
previously initiated a =julia= session with =M-x julia= the
=#+RESULTS= will have an extra mystery empty line. It is no
mystery. The first statement executed by ESS when loading =julia=
is an =include= command. That command has no output. If that empty
line bothers you then execute the code block again; the mystery
empty line will disappear.
- Be careful when executing code blocks with =:results value=. Code
block evaluation in that case works by writing the =julia= commands
to an external file in the =/tmp= directory, evaluating the commands
with =julia=, writing the results to a comma-separated (=.csv=)
file, then reading the =.csv= file and converting the result to
=elisp= for insertion to the org buffer. Not all object types are
supported by =julia= for writing to =.csv= files, in particular,
=1x1= matrices and arrays of ASCII characters are not supported
(yet). If you try to evaluate code blocks in those cases (or any
other case where output to =.csv= is not supported) then you will
get an error.
- After playing around with =julia= for a while you will notice that
instead of printing long arrays it will elide them with vertical
dots in the middle of the output which look similar to this \(
\vdots \) in the buffer. It turns out that LaTeX does not like
those three dots because they correspond to a special character, and
the upshot is that your org file will not export to LaTeX
successfully. One way around this is to explicitly declare that
special symbol in the LaTeX header. That is the reason for the
following line at the top of this org file.
: #+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{\vdots}
No preview for this file type
% Created 2013-02-28 Thu 23:35
% Created 2013-03-02 Sat 18:42
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
......@@ -15,7 +15,7 @@
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\DeclareUnicodeCharacter{22EE}{}
\DeclareUnicodeCharacter{22EE}{\vdots}
\author{G. Jay Kerns}
\date{\today}
\title{Org-mode and julia: an introduction}
......@@ -28,7 +28,9 @@
\maketitle
\tableofcontents
One of the reasons for this document was a desire for an easier method to get acquainted with \texttt{julia}. The only prerequisites are a passing familiarity with Org-mode and Emacs keybindings.
This document is an introduction to Org-mode + \texttt{julia}. The only
prerequisites are a passing familiarity with Org-mode and Emacs
keybindings.
\newpage
......@@ -36,13 +38,21 @@ One of the reasons for this document was a desire for an easier method to get ac
\label{sec-1}
\begin{description}
\item[Note:] a lot of the code blocks below have the header argument \texttt{:eval no-export}. This means that the code block can be evaluated interactively by \texttt{C-c C-c} with point in the code block but will \emph{not} be evaluated during export. That header argument is present because those blocks have settings which conflict with my current setup (or are otherwise redundant) yet are meant to be useful for other people going through this document.
\item[Note:] a lot of the code blocks below have the header argument
\texttt{:eval no-export}. This means that the code block can be
evaluated interactively by \texttt{C-c C-c} with point in the code
block but will \emph{not} be evaluated during export. That
header argument is present because those blocks have
settings which conflict with my current setup (or are
otherwise redundant) yet are meant to be useful for other
people working through this document.
\end{description}
\subsection[Julia]{Julia}
\label{sec-1-1}
You are going to need a working installation of \texttt{julia}. The homepage on \href{https://github.com/JuliaLang/julia}{GitHub} has the pertinent links collected all in one place:
You are going to need a working installation of \texttt{julia}. The homepage
on \href{https://github.com/JuliaLang/julia}{GitHub} has the pertinent links collected all in one place:
\begin{itemize}
\item \textbf{Homepage:} \url{http://julialang.org}
......@@ -55,35 +65,51 @@ You are going to need a working installation of \texttt{julia}. The homepage on
\item \textbf{Documentation:} \url{http://julialang.org/manual/}
\end{itemize}
\underline{Fair warning:} the initial install takes a \emph{long time}, largely because julia has a lot of dependencies. Never fear, though; updates are brief.
\underline{Fair warning:} the initial install takes a \emph{long time}, largely
because julia has a lot of dependencies. Never fear, though;
subsequent updates are brief.
\subsection[ESS - Emacs Speaks Statistics]{ESS - Emacs Speaks Statistics}
\label{sec-1-2}
You are going to need a relavely bleeding-edge version of ESS since it is only due to recent ESS work that this document is even possible. The place to look for the latest version of ESS is \href{http://stat.ethz.ch/ESS/index.php?Section=download}{here}. One of the options there is to clone \href{https://github.com/emacs-ess/ESS}{the ESS github repository} and put the following in your \texttt{.emacs} (or whatever other initialiation file you use):
You are going to need a relavely bleeding-edge version of ESS since it
is only due to recent ESS changes that this document is even possible.
The place to look for the latest version of ESS is \href{http://stat.ethz.ch/ESS/index.php?Section=download}{here}. At some
point after installation you will likely put something like the
following in your \texttt{.emacs}:
\begin{verbatim}
(add-to-list 'load-path "/path/to/ESS/lisp")
(require 'ess-site)
\end{verbatim}
Once ESS is up and running you will need to tell it where the \texttt{julia} executable is. Edit the following and place it in your \texttt{.emacs}:
Once ESS is up and running you will need to tell it where the \texttt{julia}
executable is. Edit the following and place it in your \texttt{.emacs}:
\begin{verbatim}
(setq inferior-julia-program-name "/path/to/julia-release-basic")
\end{verbatim}
After the above steps are complete then you should be able to start Emacs and do \texttt{M-x julia} to launch an interactive julia session. At this point you should be able to do everything in the \href{file://intro-julia.org}{Introduction to Julia}.
After the above steps are complete then you should be able to start
Emacs and launch an interactive \texttt{julia} session via \texttt{M-x julia}. If
you manage to get that settled then at this point you should be able
to do everything in the \href{file://intro-julia.org}{Introduction to Julia}.
\subsection[Add-on packages]{Add-on packages}
\label{sec-1-3}
There is a large (and growing) list of \href{http://docs.julialang.org/en/release-0.1/packages/packagelist/}{contibuted packages} which add to the base functionality of \texttt{julia}. For example, several statistics packages were recently collected in a blog post by \href{https://github.com/johnmyleswhite}{John Myles White} entitled \href{http://www.johnmyleswhite.com/notebook/2012/12/02/the-state-of-statistics-in-julia/}{The State of Statistics in Julia}. The instructions in the blog post are (already) a bit out-of-date; the currently recommended way to install the packages is to launch an interactive \texttt{julia} session and execute the following command:
There is a growing list of \href{http://docs.julialang.org/en/release-0.1/packages/packagelist/}{contibuted packages} which add to the base
functionality of \texttt{julia}. For example, several statistics packages
were mentioned a few moths ago in a blog post by \href{https://github.com/johnmyleswhite}{John Myles White}
entitled \href{http://www.johnmyleswhite.com/notebook/2012/12/02/the-state-of-statistics-in-julia/}{The State of Statistics in Julia}. The instructions in the
blog post are (already) a bit out-of-date; the currently recommended
way to install the packages is to launch an interactive \texttt{julia}
session and execute the following command:
\begin{verbatim}
Pkg.add("DataFrames", "Distributions", "GLM", "MCMC", "Optim",
"NHST", "Clustering")
\end{verbatim}
As John notes, the \texttt{RDatasets} package takes a lot longer to download. Perhaps you would like to install it separately.
As John notes, the \texttt{RDatasets} package takes a lot longer to download
than the others. Perhaps it would be wise to install it separately.
\begin{verbatim}
Pkg.add("RDatasets")
......@@ -91,7 +117,8 @@ Pkg.add("RDatasets")
\subsection[Org-mode]{Org-mode}
\label{sec-1-4}
Since you have at least a passing familiarity with org-mode then you probably already have something like the following in your \texttt{.emacs}:
Since you have at least a passing familiarity with org-mode then you
probably already have something like the following in your \texttt{.emacs}:
\begin{verbatim}
(require 'org)
......@@ -103,7 +130,8 @@ Another handy setting to have is
(setq org-confirm-babel-evaluate nil)
\end{verbatim}
The following lines (either here or in your \texttt{.emacs}) permit inline image display in the Emacs buffer.
The following lines (either here or in your \texttt{.emacs}) permit inline
image display in the Emacs buffer.
\begin{verbatim}
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
......@@ -112,13 +140,18 @@ The following lines (either here or in your \texttt{.emacs}) permit inline image
\subsection[\texttt{ob-julia.el}]{\texttt{ob-julia.el}}
\label{sec-1-5}
You are going to want a copy of \texttt{ob-julia.el} to fully integrate \texttt{julia} with Org-mode. You can find it and some other documents to get you started \href{https://github.com/gjkerns/ob-julia}{here}. Download \texttt{ob-julia.el} into a convenient place. Edit the code block below and evaluate it by \texttt{C-c C-c} with point in the code block.
You are going to want a copy of \texttt{ob-julia.el} to fully integrate
\texttt{julia} with Org-mode. You can find it and some other documents to
get you started \href{https://github.com/gjkerns/ob-julia}{here}. Download \texttt{ob-julia.el} into a convenient place.
Edit the code block below and evaluate it by \texttt{C-c C-c} with point in
the code block.
\begin{verbatim}
(load "/path/to/ob-julia.el")
\end{verbatim}
An alternative method is to put the following in your \texttt{.emacs} (these should go below the \texttt{(require 'org)} line):
An alternative method is to put the following in your \texttt{.emacs} (these
should go below the \texttt{(require 'org)} line):
\begin{verbatim}
(add-to-list 'load-path "/path/to/ob-julia.el")
......@@ -131,7 +164,8 @@ You are all set.
\section[Evaluation inside the Org buffer]{Evaluation inside the Org buffer}
\label{sec-2}
If you've gotten this far then everything is installed in the right place and initialized properly. Now the fun begins.
If you've gotten this far then everything is installed in the right
place and initialized properly. Now the fun begins.
\subsection[:results value]{:results value}
\label{sec-2-1}
......@@ -141,18 +175,27 @@ If you've gotten this far then everything is installed in the right place and in
\section[Graphics]{Graphics}
\label{sec-3}
The most stable and fully featured of the \texttt{julia} graphics packages at the time of this writing appears to be the \href{https://github.com/nolta/Winston.jl}{Winston package}, although the \href{https://github.com/dcjones/Gadfly.jl}{Gadfly package} is also available and appears promising. To install the Winston package execute the following in an interactive session (if you do it here then you can't watch the download and install as it is happening).
The most stable and fully featured of the \texttt{julia} graphics packages at
the time of this writing appears to be the \href{https://github.com/nolta/Winston.jl}{Winston package}, although
the \href{https://github.com/dcjones/Gadfly.jl}{Gadfly package} is also available and appears promising. To
install the Winston package execute the following in an interactive
session. I recommend you \textbf{not} execute this here (if you do it in
this buffer then you can't watch the download and install as it is
happening).
\begin{verbatim}
Pkg.add("Winston")
\end{verbatim}
The Winston package has lots of dependencies and many of them must be built from source (on Ubuntu).
The Winston package has lots of dependencies and many of them must be
built from source (on Ubuntu).
\subsection[Plotting with Winston]{Plotting with Winston}
\label{sec-3-1}
To get up and running with plots in \texttt{julia} check out the many example graphs (with code) on the \href{https://github.com/nolta/Winston.jl/blob/master/doc/examples.md}{Winston examples page}. As far as Org-mode is concerned, you can do plotting
To get up and running with plots in \texttt{julia} check out the many example
graphs (with code) on the \href{https://github.com/nolta/Winston.jl/blob/master/doc/examples.md}{Winston examples page}. As far as Org-mode is
concerned, you can do plotting
\begin{enumerate}
\item Interactively with a plot window,
......@@ -160,7 +203,9 @@ To get up and running with plots in \texttt{julia} check out the many example gr
\item Via export into \LaTeX{}, HTML, Beamer\ldots{}
\end{enumerate}
Let's describe each in turn. All three methods require setting up the plot object as a first step, after, of course, loading the Winston package. Let's set up a simple plot object (do \texttt{C-c C-c} with point in the block):
All three methods require setting up the plot object as a first step,
after, of course, loading the Winston package. Let's set up a simple
plot object (do \texttt{C-c C-c} with point in the block):
\begin{verbatim}
using Winston
......@@ -176,29 +221,65 @@ add(p, Curve(x, c, "color", "red") )
add(p, Curve(x, s, "color", "blue") )
\end{verbatim}
We did \texttt{:results silent} to omit the lengthy output from being inserted in the org buffer. So the hard part is finished -- we've created a plot object \texttt{p} which is now available to manipulate.
We did \texttt{:results silent} to omit the lengthy output from being
inserted in the org buffer. So the hard part is finished -- we've
created a plot object \texttt{p} which is now available to manipulate.
To launch a plot window and look at the graph right now evaluate the following code block.
To launch a plot window and look at the graph right now evaluate the
following code block.
\begin{verbatim}
Winston.tk(p)
\end{verbatim}
A plot should open in an X11 window with a pretty graph. Suppose instead we'd like to insert the graph in the org buffer right now. We need the inline-image display options described in section \texttt{Org mode}. Assuming you've done that, evaluate the following code block.
A plot should open in an X11 window with a pretty graph. Suppose
instead we'd like to insert the graph in the org buffer right now. We
need the inline-image display options described in section \texttt{Org
mode}. Assuming you've done that, evaluate the following code block.
\begin{verbatim}
file(p, "example1.png")
\end{verbatim}
The code block evaluates the command \texttt{file(p, "example1.png")}, which tells \texttt{julia} to write the graph to a \texttt{.png} file (also available are \texttt{.pdf}, \texttt{.svg}, and \texttt{.eps}, though none of those can be inserted in the org buffer). The header argument \texttt{:results graphics} tells org-mode that the results are going to be graphics (as opposed to elisp tables or STDOUT output) and the header argument \texttt{:file example1.png} tells org to insert an link to the file \texttt{example1.png} (just created by \texttt{julia}) right after the the code block. This link is evaluated by \texttt{org-display-inline-images} which results in a \texttt{.png} in the org buffer.
Notice that we had to specify the file name \emph{twice}, once inside the code block and once as a header argument. Some languages (such as R) only require one specification: the header argument. The reason for this is simple: \texttt{ob-R.el} includes code which dynamically constructs a graphics device call behind the scenes, the call depending on the file extension in the \texttt{:file} header argument. Such a thing is more difficult with \texttt{julia} because different graphics packages have markedly different device calls (for instance, \texttt{Gadfly} uses \texttt{SVG("filename", p)}). Maybe someday the calls will stabilize and it will make sense to write wrapper code to do that automatically. In the meantime, use whatever package you like and write the filename twice.
The code block evaluates the command \texttt{file(p, "example1.png")}, which
tells \texttt{julia} to write the graph to a \texttt{.png} file (also available are
\texttt{.pdf}, \texttt{.svg}, and \texttt{.eps}, though none of those can be inserted in
the org buffer). The header argument \texttt{:results graphics} tells
org-mode that the results are going to be graphics (as opposed to
elisp tables or STDOUT output) and the header argument \texttt{:file
example1.png} tells org to insert an link to the file \texttt{example1.png}
(just created by \texttt{julia}) right after the the code block. This link
is evaluated by \texttt{org-display-inline-images} which results in a \texttt{.png}
in the org buffer.
Notice that we had to specify the file name \emph{twice}, once inside the
code block and once as a header argument. Some languages (such as R)
only require one specification: the header argument. The reason for
this is simple: \texttt{ob-R.el} includes code which dynamically constructs a
graphics device call behind the scenes, the call depending on the file
extension in the \texttt{:file} header argument. Such a thing is more
difficult with \texttt{julia} because different graphics packages have
markedly different device calls (for instance, \texttt{Gadfly} uses
\texttt{SVG("filename", p)}). Maybe someday the calls will stabilize and it
will make sense to write wrapper code to do that automatically. In
the meantime, use whatever package you like and write the filename
twice.
We'll defer the export method discussion to the next section.
\section[Exporting to other formats]{Exporting to other formats}
\section[Export to other formats]{Export to other formats}
\label{sec-4}
Sonner or later you will want to share your work with others, people who have not (yet) fully come to the realization that Emacs+Org is really quite better than sliced bread and also is destined to conquer the entire observable Universe. Perhaps you'd like to make a presentation about how awesome \texttt{julia} is at a(n) (inter)national conference. Org-mode supports export to multiple formats. Here we'll describe a few. There has been work recently on a brand new exporter which hasn't yet made it to the official maintenance branch as of the time of this writing. The following instructions apply to the new exporter, which is one of the reasons why it was important in the first section to update your Org-mode.
Sooner or later you will want to share your work with others, people
who have not (yet) fully come to the realization that Emacs+Org is
really quite better than sliced bread and also is destined to conquer
the entire observable Universe. Perhaps you'd like to make a
presentation about how awesome \texttt{julia} is at a(n) (inter)national
conference. Org-mode supports export to multiple formats. Here we'll
describe a few. There has been work recently on a brand new exporter
which hasn't yet made it to the official maintenance branch as of the
time of this writing. The following instructions apply to the new
exporter, which is one of the reasons why it was important in the
first section to update your Org-mode.
\subsection[HTML]{HTML}
\label{sec-4-1}
......@@ -208,7 +289,8 @@ This is the easiest. Insert the following in your \texttt{.emacs}:
(require 'ox-html)
\end{verbatim}
Then open this file and execute \texttt{C-c C-e} to open the export dispatcher. From there you have three options:
Then open this file and execute \texttt{C-c C-e} to open the export
dispatcher. From there you have three options:
\begin{enumerate}
\item \texttt{h H} exports as an HTML buffer (can be saved later),
......@@ -216,7 +298,9 @@ Then open this file and execute \texttt{C-c C-e} to open the export dispatcher.
\item \texttt{h o} exports as an HTML file and opens in a browser.
\end{enumerate}
That's it. There are a lot of other cool things you can do; see the Org manual. If you export to HTML then you are going to want your images (if any) to be \texttt{.png} or \texttt{.svg} files.
That's it. There are a lot of other cool things you can do; see the
Org manual. If you export to HTML then you are going to want your
images (if any) to be \texttt{.png} or \texttt{.svg} files.
\subsection[\LaTeX{}]{\LaTeX{}}
\label{sec-4-2}
......@@ -235,60 +319,87 @@ Then open this file and do
\item \texttt{C-c C-e l o} to export as \LaTeX{}, generate PDF, and open.
\end{enumerate}
There are a \emph{ton} of other \LaTeX{} things to do. See the Org manual. If you export to PDF then it's fine to use image formats \texttt{.png}, \texttt{.eps}, or \texttt{.pdf}, but the \texttt{.png} exports as a blurry raster image - use \texttt{.pdf} instead (or \texttt{.eps} for external plain \LaTeX{} export).
There are a \emph{ton} of other \LaTeX{} things to do. See the Org manual.
If you export to PDF then it's fine to use image formats \texttt{.png},
\texttt{.eps}, or \texttt{.pdf}, but the \texttt{.png} exports as a blurry raster image -
use \texttt{.pdf} instead (or \texttt{.eps} for external plain \LaTeX{} export).
\subsection[Beamer]{Beamer}
\label{sec-4-3}
Beamer is a special case unto itself. The short story is that you need the following in your \texttt{.emacs}:
Beamer is a special case unto itself. The short story is that you need
the following in your \texttt{.emacs}:
\begin{verbatim}
(require 'ox-beamer)
\end{verbatim}
Then also add an entry for the beamer class in your \texttt{.emacs}. Here is a boilerplate version which you can customize to taste:
Then also add an entry for the beamer class in your \texttt{.emacs}. Here is
a boilerplate version which you can customize to taste:
\begin{verbatim}
(add-to-list 'org-latex-classes
'("beamer"
"\\documentclass[presentation]{beamer}
\[DEFAULT-PACKAGES]
\[PACKAGES]
\[EXTRA]"
\[DEFAULT-PACKAGES]
\[PACKAGES]
\[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
\end{verbatim}
Since beamer is such a special case I have tweaked a minimal \texttt{julia} beamer presentation in \href{file://ob-julia-beamer.org}{A julia beamer example}. See there, see the Org manual, and see Worg too for more information.
\section[Other things]{Other things}
Since beamer is such a special case I have tweaked a minimal \texttt{julia}
beamer presentation in \href{file://ob-julia-beamer.org}{Sample \texttt{julia} Presentation}. See there, see the
Org manual, and see Worg too for more information.
\section[Other things to mention]{Other things to mention}
\label{sec-5}
\begin{itemize}
\item You can extract all of the \texttt{julia} source code (also known as \emph{tangling} the Org document) with the keystrokes \texttt{C-c C-v t}. This will generate a \texttt{julia} script (with extension \texttt{.jl}) in the working directory. Note that this capability is turned off by default. You can activate it by adding the header argument \texttt{:tangle yes} to those code blocks you'd like to tangle or doing a buffer-wide header setting with the line \texttt{\#+PROPERTY: tangle yes} near the top of the org file. See the Org manual for details.
\item You may have noticed that those \texttt{julia} code lines with no output (for instance, lines with semicolons \texttt{;} at the end) generate an empty line in the \texttt{\#+RESULTS} below the code block. Consequently, the first time you evaluate a \texttt{julia} code block without having previously initiated a \texttt{julia} session with \texttt{M-x julia} the \texttt{\#+RESULTS} will have an extra mystery empty line. It is no mystery. The first statement executed by ESS when loading \texttt{julia} is an \texttt{include} command. That command has no output. If that empty line bothers you then execute the code block again; the mystery empty line will disappear.
\item Be careful when executing code blocks with \texttt{:results value}. Code block evaluation in that case works by writing the \texttt{julia} commands to an external file in the \texttt{/tmp} directory, evaluating the commands with \texttt{julia}, writing the results to a comma-separated (\texttt{.csv}) file, then reading the \texttt{.csv} file and converting the result to \texttt{elisp} for insertion to the org buffer. Not all object types are supported by \texttt{julia} for writing to \texttt{.csv} files, in particular, \texttt{1x1} matrices and arrays of ASCII characters are not supported (yet). If you try to evaluate code blocks in those cases (or any other case where output to \texttt{.csv} is not supported) then you will get an error.
\end{itemize}
\section[Fitting (generalized) linear models]{Fitting (generalized) linear models}
\label{sec-6}
\begin{verbatim}
using RDatasets, DataFrames, Distributions, GLM
trees = data("datasets", "trees");
treeslm = lm(:(Girth ~ Height + Volume), trees);
coef(treeslm)
coeftable(treeslm)
\end{verbatim}
\item You can extract all of the \texttt{julia} source code (also known as
\emph{tangling} the Org document) with the keystrokes \texttt{C-c C-v t}. This
will generate a \texttt{julia} script (with extension \texttt{.jl}) in the working
directory. Note that this capability is turned off by default. You
can activate it by adding the header argument \texttt{:tangle yes} to those
code blocks you'd like to tangle or doing a buffer-wide header
setting with the line \texttt{\#+PROPERTY: tangle yes} near the top of the
org file. See the Org manual for details.
\item You may have noticed that those \texttt{julia} code lines with no output
(for instance, lines with semicolons \texttt{;} at the end) generate an
empty line in the \texttt{\#+RESULTS} below the code block. Consequently,
the first time you evaluate a \texttt{julia} code block without having
previously initiated a \texttt{julia} session with \texttt{M-x julia} the
\texttt{\#+RESULTS} will have an extra mystery empty line. It is no
mystery. The first statement executed by ESS when loading \texttt{julia}
is an \texttt{include} command. That command has no output. If that empty
line bothers you then execute the code block again; the mystery
empty line will disappear.
\item Be careful when executing code blocks with \texttt{:results value}. Code
block evaluation in that case works by writing the \texttt{julia} commands
to an external file in the \texttt{/tmp} directory, evaluating the commands
with \texttt{julia}, writing the results to a comma-separated (\texttt{.csv})
file, then reading the \texttt{.csv} file and converting the result to
\texttt{elisp} for insertion to the org buffer. Not all object types are
supported by \texttt{julia} for writing to \texttt{.csv} files, in particular,
\texttt{1x1} matrices and arrays of ASCII characters are not supported
(yet). If you try to evaluate code blocks in those cases (or any
other case where output to \texttt{.csv} is not supported) then you will
get an error.
\item After playing around with \texttt{julia} for a while you will notice that
instead of printing long arrays it will elide them with vertical
dots in the middle of the output which look similar to this \(
\vdots \) in the buffer. It turns out that \LaTeX{} does not like
those three dots because it corresponds to a special character, and
the upshot is that your org file will not export to \LaTeX{}
successfully. One way around this is to explicitly declare that
special symbol in the \LaTeX{} header. That is the reason for the
following line at the top of this org file.
\begin{verbatim}
3-element Float64 Array:
10.8164
-0.0454835
0.19518
3x4 DataFrame:
Estimate Std.Error t value Pr(>|t|)
[1,] 10.8164 1.9732 5.48165 7.44691e-6
[2,] -0.0454835 0.0282621 -1.60935 0.118759
[3,] 0.19518 0.0109553 17.8161 8.2233e-17
#+LaTeX_HEADER: \DeclareUnicodeCharacter{22EE}{\vdots}
\end{verbatim}
\end{itemize}
% Generated by Org mode 7.9.3f in Emacs 24.3.50.1.
\end{document}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment