Commit 6ffbb2da authored by G. Jay Kerns's avatar G. Jay Kerns

I think we're pretty much there.

parent acdba58b
.juliahistory .juliahistory
*~ *~
*.pdf
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="Introduction to <code>julia</code>"/> <meta name="title" content="Introduction to <code>julia</code>"/>
<meta name="generator" content="Org-mode"/> <meta name="generator" content="Org-mode"/>
<meta name="generated" content="March 2, 2013"/>
<meta name="author" content="G. Jay Kerns"/> <meta name="author" content="G. Jay Kerns"/>
<style type="text/css"> <style type="text/css">
<!--/*--><![CDATA[/*><!--*/ <!--/*--><![CDATA[/*><!--*/
...@@ -310,7 +311,6 @@ interactive session type <code>2 + 3</code> and observe ...@@ -310,7 +311,6 @@ interactive session type <code>2 + 3</code> and observe
</div> </div>
<pre class="example"> <pre class="example">
5 5
</pre> </pre>
...@@ -651,7 +651,6 @@ and you can get help on a function when it's available with the ...@@ -651,7 +651,6 @@ and you can get help on a function when it's available with the
</div> </div>
<pre class="example"> <pre class="example">
Loading help data...
Base.factorial(n) Base.factorial(n)
Factorial of n Factorial of n
...@@ -781,7 +780,7 @@ like <code>summary(treeslm)</code> in R. ...@@ -781,7 +780,7 @@ like <code>summary(treeslm)</code> in R.
</div> </div>
</div><div id="postamble"> </div><div id="postamble">
<p class="date">Date: </p> <p class="date">Date: March 2, 2013</p>
<p class="author">Author : G. Jay Kerns</p> <p class="author">Author : G. Jay Kerns</p>
<p class="creator">Generated by <a href="http://orgmode.org">Org</a> mode 7.9.3f in <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.50.1.</p> <p class="creator">Generated by <a href="http://orgmode.org">Org</a> mode 7.9.3f in <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.50.1.</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a> <a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head> <head>
<title>Org-mode and julia: an introduction</title> <title>Org-mode and <code>julia</code>: an introduction</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="Org-mode and julia: an introduction"/> <meta name="title" content="Org-mode and <code>julia</code>: an introduction"/>
<meta name="generator" content="Org-mode"/> <meta name="generator" content="Org-mode"/>
<meta name="generated" content="March 2, 2013"/>
<meta name="author" content="G. Jay Kerns"/> <meta name="author" content="G. Jay Kerns"/>
<style type="text/css"> <style type="text/css">
<!--/*--><![CDATA[/*><!--*/ <!--/*--><![CDATA[/*><!--*/
...@@ -147,7 +148,7 @@ for the JavaScript code in this tag. ...@@ -147,7 +148,7 @@ for the JavaScript code in this tag.
</head> </head>
<body> <body>
<div id="content"> <div id="content">
<h1 class="title">Org-mode and julia: an introduction</h1> <h1 class="title">Org-mode and <code>julia</code>: an introduction</h1>
<div id="table-of-contents"> <div id="table-of-contents">
<h2>Table of Contents</h2> <h2>Table of Contents</h2>
<div id="text-table-of-contents"> <div id="text-table-of-contents">
...@@ -402,10 +403,88 @@ place and initialized properly. Now the fun begins. ...@@ -402,10 +403,88 @@ place and initialized properly. Now the fun begins.
<div id="outline-container-2-1" class="outline-3"> <div id="outline-container-2-1" class="outline-3">
<h3 id="sec-2-1"><span class="section-number-3">2.1</span> :results value</h3> <h3 id="sec-2-1"><span class="section-number-3">2.1</span> :results value</h3>
<div class="outline-text-3" id="text-2-1">
<p>
The collection class of the <code>:results</code> header argument supports two mutually exclusive options: <code>value</code> and <code>output</code>. When <code>:results value</code> is specified, Org takes the body of the source block, creates a function with that body, evaluates the function with <code>julia</code>, stores the result in a <code>.csv</code> file, then converts the <code>.csv</code> file to an <code>emacs-lisp</code> table, and finally inserts the table in the buffer. <i>Whew!</i> The bottom line? Hit <code>C-c C-c</code> in the following code block.
</p>
<div class="org-src-container">
<pre class="src src-julia"><span style="color: #0000ff;">rand</span>(2,3)
</pre>
</div> </div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="right"/>
<col class="right"/>
<col class="right"/>
</colgroup>
<tbody>
<tr>
<td class="right">0.999939439042129</td>
<td class="right">0.05372529032959994</td>
<td class="right">0.02450126420987675</td>
</tr>
<tr>
<td class="right">0.08199970646956767</td>
<td class="right">0.015234813811405568</td>
<td class="right">0.1871767733729599</td>
</tr>
</tbody>
</table>
<p>
As expected, the output of the command was a <code>2x3</code> array and Org inserted a table into the buffer. This functionality is relatively powerful with other languages such as R, for instance, because <code>ob-R.el</code> works with <code>TAB</code> separated files instead and <code>read.table</code> in R supports reading of much more varied data types compared to <code>readcsv</code> in <code>julia</code> (at the present time). Nevertheless, the functionality exists in <code>julia</code> and as time passes and <code>julia</code> adds more options we'll add more, too.
</p>
</div>
</div>
<div id="outline-container-2-2" class="outline-3"> <div id="outline-container-2-2" class="outline-3">
<h3 id="sec-2-2"><span class="section-number-3">2.2</span> :results output</h3> <h3 id="sec-2-2"><span class="section-number-3">2.2</span> :results output</h3>
<div class="outline-text-3" id="text-2-2">
<p>
We will get a lot more mileage out of the <code>:results output</code> option. Every command in the src block body is evaluated by <code>julia</code> in turn and the results are placed in the buffer to be typeset in a verbatim environment. This option is similar to typing commands in <code>julia</code> at an interactive session. The analogy isn't exact, though, because at an interactive session it is one (1) command in, one (1) result out. Multiple lines in an org SRC block in contrast have RESULTS which are lumped together. Like this: (do <code>C-c C-c</code>)
</p>
<div class="org-src-container">
<pre class="src src-julia">2 + 3
<span style="color: #0000ff;">print</span>(<span style="color: #8b2252;">"hello"</span>)
<span style="color: #0000ff;">sqrt</span>(5)
</pre>
</div>
<pre class="example">
5
hello
2.23606797749979
</pre>
<p>
It is sometimes helpful to split up SRC blocks into smaller chunks so that buildup of RESULTS does not get out of hand. Also, specific to <code>julia</code> we can sometimes put a semicolon at the end of the command to suppress output, like this:
</p>
<div class="org-src-container">
<pre class="src src-julia">2 + 3;
<span style="color: #0000ff;">print</span>(<span style="color: #8b2252;">"hello"</span>);
<span style="color: #0000ff;">sqrt</span>(5);
</pre>
</div>
<pre class="example">
hello
</pre>
<p>
Notice the outer two results were suppressed, but not the middle one.
</p>
</div>
</div> </div>
</div> </div>
<div id="outline-container-3" class="outline-2"> <div id="outline-container-3" class="outline-2">
...@@ -502,6 +581,12 @@ mode</i>. Assuming you've done that, evaluate the following code block. ...@@ -502,6 +581,12 @@ mode</i>. Assuming you've done that, evaluate the following code block.
</pre> </pre>
</div> </div>
<div class="figure">
<p><img src="example1.png" alt="example1.png"/></p>
<p></p>
</div>
<p> <p>
The code block evaluates the command <code>file(p, "example1.png")</code>, which The code block evaluates the command <code>file(p, "example1.png")</code>, which
tells <code>julia</code> to write the graph to a <code>.png</code> file (also available are tells <code>julia</code> to write the graph to a <code>.png</code> file (also available are
...@@ -739,7 +824,7 @@ following line at the top of this org file. ...@@ -739,7 +824,7 @@ following line at the top of this org file.
</div> </div>
</div><div id="postamble"> </div><div id="postamble">
<p class="date">Date: </p> <p class="date">Date: March 2, 2013</p>
<p class="author">Author : G. Jay Kerns</p> <p class="author">Author : G. Jay Kerns</p>
<p class="creator">Generated by <a href="http://orgmode.org">Org</a> mode 7.9.3f in <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.50.1.</p> <p class="creator">Generated by <a href="http://orgmode.org">Org</a> mode 7.9.3f in <a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.3.50.1.</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a> <a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
......
#+TITLE: Introduction to =julia= #+TITLE: Introduction to =julia=
#+AUTHOR: G. Jay Kerns #+AUTHOR: G. Jay Kerns
#+EMAIL: gkerns@ysu.edu #+EMAIL: gkerns@ysu.edu
#+DATE: March 2, 2013
#+OPTIONS: H:2 #+OPTIONS: H:2
#+PROPERTY: exports both #+PROPERTY: exports both
#+PROPERTY: results output #+PROPERTY: results output
......
...@@ -4,6 +4,16 @@ Pkg.add("DataFrames", "Distributions", "GLM", "MCMC", "Optim", ...@@ -4,6 +4,16 @@ Pkg.add("DataFrames", "Distributions", "GLM", "MCMC", "Optim",
Pkg.add("RDatasets") Pkg.add("RDatasets")
rand(2,3)
2 + 3
print("hello")
sqrt(5)
2 + 3;
print("hello");
sqrt(5);
Pkg.add("Winston") Pkg.add("Winston")
using Winston using Winston
......
(require 'ess-site)
(setq inferior-julia-program-name "/path/to/julia-release-basic")
(require 'org)
(setq org-confirm-babel-evaluate nil)
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
(add-hook 'org-mode-hook 'org-display-inline-images)
(load "/path/to/ob-julia.el")
(add-to-list 'load-path "/path/to/ob-julia.el")
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t) (julia . t)))
(require 'ox-html)
(require 'ox-latex)
(require 'ox-beamer)
(add-to-list 'org-latex-classes
'("beamer"
"\\documentclass[presentation]{beamer}
\[DEFAULT-PACKAGES]
\[PACKAGES]
\[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
#+TITLE: Org-mode and julia: an introduction #+TITLE: Org-mode and =julia=: an introduction
#+AUTHOR: G. Jay Kerns #+AUTHOR: G. Jay Kerns
#+EMAIL: gkerns@ysu.edu #+EMAIL: gkerns@ysu.edu
#+DATE: March 2, 2013
#+OPTIONS: H:2 #+OPTIONS: H:2
#+PROPERTY: exports both #+PROPERTY: exports both
#+PROPERTY: results output #+PROPERTY: results output
...@@ -148,8 +149,47 @@ place and initialized properly. Now the fun begins. ...@@ -148,8 +149,47 @@ place and initialized properly. Now the fun begins.
** :results value ** :results value
The collection class of the =:results= header argument supports two mutually exclusive options: =value= and =output=. When =:results value= is specified, Org takes the body of the source block, creates a function with that body, evaluates the function with =julia=, stores the result in a =.csv= file, then converts the =.csv= file to an =emacs-lisp= table, and finally inserts the table in the buffer. /Whew!/ The bottom line? Hit =C-c C-c= in the following code block.
#+BEGIN_SRC julia :results value
rand(2,3)
#+END_SRC
#+RESULTS:
| 0.3715303800228136 | 0.21579188514924108 | 0.3291019424007178 |
| 0.659813851572707 | 0.20079077424458047 | 0.9476793913656847 |
As expected, the output of the command was a =2x3= array and Org inserted a table into the buffer. This functionality is relatively powerful with other languages such as R, for instance, because =ob-R.el= works with =TAB= separated files instead and =read.table= in R supports reading of much more varied data types compared to =readcsv= in =julia= (at the present time). Nevertheless, the functionality exists in =julia= and as time passes and =julia= adds more options we'll add more, too.
** :results output ** :results output
We will get a lot more mileage out of the =:results output= option. Every command in the src block body is evaluated by =julia= in turn and the results are placed in the buffer to be typeset in a verbatim environment. This option is similar to typing commands in =julia= at an interactive session. The analogy isn't exact, though, because at an interactive session it is one (1) command in, one (1) result out. Multiple lines in an org SRC block in contrast have RESULTS which are lumped together. Like this: (do =C-c C-c=)
#+BEGIN_SRC julia
2 + 3
print("hello")
sqrt(5)
#+END_SRC
#+RESULTS:
: 5
: hello
: 2.23606797749979
It is sometimes helpful to split up SRC blocks into smaller chunks so that buildup of RESULTS does not get out of hand. Also, specific to =julia= we can sometimes put a semicolon at the end of the command to suppress output, like this:
#+BEGIN_SRC julia
2 + 3;
print("hello");
sqrt(5);
#+END_SRC
#+RESULTS:
:
: hello
Notice the outer two results were suppressed, but not the middle one.
* Graphics * Graphics
The most stable and fully featured of the =julia= graphics packages at The most stable and fully featured of the =julia= graphics packages at
...@@ -214,6 +254,9 @@ mode]]. Assuming you've done that, evaluate the following code block. ...@@ -214,6 +254,9 @@ mode]]. Assuming you've done that, evaluate the following code block.
file(p, "example1.png") file(p, "example1.png")
#+END_SRC #+END_SRC
#+RESULTS:
[[file:example1.png]]
The code block evaluates the command =file(p, "example1.png")=, which The code block evaluates the command =file(p, "example1.png")=, which
tells =julia= to write the graph to a =.png= file (also available are 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 =.pdf=, =.svg=, and =.eps=, though none of those can be inserted in
......
No preview for this file type
No preview for this file type
% Created 2013-03-02 Sat 21:14 % Created 2013-03-02 Sat 22:40
\documentclass[11pt]{article} \documentclass[11pt]{article}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
\tolerance=1000 \tolerance=1000
\DeclareUnicodeCharacter{22EE}{\vdots} \DeclareUnicodeCharacter{22EE}{\vdots}
\author{G. Jay Kerns} \author{G. Jay Kerns}
\date{\today} \date{March 2, 2013}
\title{Introduction to \texttt{julia}} \title{Introduction to \texttt{julia}}
\hypersetup{ \hypersetup{
pdfkeywords={}, pdfkeywords={},
...@@ -124,8 +124,6 @@ interactive session type \texttt{2 + 3} and observe ...@@ -124,8 +124,6 @@ interactive session type \texttt{2 + 3} and observe
\end{verbatim} \end{verbatim}
\begin{verbatim} \begin{verbatim}
5 5
\end{verbatim} \end{verbatim}
...@@ -403,7 +401,6 @@ help("factorial") ...@@ -403,7 +401,6 @@ help("factorial")
\end{verbatim} \end{verbatim}
\begin{verbatim} \begin{verbatim}
Loading help data...
Base.factorial(n) Base.factorial(n)
Factorial of n Factorial of n
......
% Created 2013-03-02 Sat 21:15 % Created 2013-03-02 Sat 22:35
\documentclass[11pt]{article} \documentclass[11pt]{article}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
\tolerance=1000 \tolerance=1000
\DeclareUnicodeCharacter{22EE}{\vdots} \DeclareUnicodeCharacter{22EE}{\vdots}
\author{G. Jay Kerns} \author{G. Jay Kerns}
\date{\today} \date{March 2, 2013}
\title{Org-mode and julia: an introduction} \title{Org-mode and \texttt{julia}: an introduction}
\hypersetup{ \hypersetup{
pdfkeywords={}, pdfkeywords={},
pdfsubject={}, pdfsubject={},
...@@ -173,8 +173,51 @@ place and initialized properly. Now the fun begins. ...@@ -173,8 +173,51 @@ place and initialized properly. Now the fun begins.
\subsection[:results value]{:results value} \subsection[:results value]{:results value}
\label{sec-2-1} \label{sec-2-1}
The collection class of the \texttt{:results} header argument supports two mutually exclusive options: \texttt{value} and \texttt{output}. When \texttt{:results value} is specified, Org takes the body of the source block, creates a function with that body, evaluates the function with \texttt{julia}, stores the result in a \texttt{.csv} file, then converts the \texttt{.csv} file to an \texttt{emacs-lisp} table, and finally inserts the table in the buffer. \emph{Whew!} The bottom line? Hit \texttt{C-c C-c} in the following code block.
\begin{verbatim}
rand(2,3)
\end{verbatim}
\begin{center}
\begin{tabular}{rrr}
0.5584357754021063 & 0.9136408669454337 & 0.506642489779598\\
0.74985978094506 & 0.04938552792586104 & 0.596697983703395\\
\end{tabular}
\end{center}
As expected, the output of the command was a \texttt{2x3} array and Org inserted a table into the buffer. This functionality is relatively powerful with other languages such as R, for instance, because \texttt{ob-R.el} works with \texttt{TAB} separated files instead and \texttt{read.table} in R supports reading of much more varied data types compared to \texttt{readcsv} in \texttt{julia} (at the present time). Nevertheless, the functionality exists in \texttt{julia} and as time passes and \texttt{julia} adds more options we'll add more, too.
\subsection[:results output]{:results output} \subsection[:results output]{:results output}
\label{sec-2-2} \label{sec-2-2}
We will get a lot more mileage out of the \texttt{:results output} option. Every command in the src block body is evaluated by \texttt{julia} in turn and the results are placed in the buffer to be typeset in a verbatim environment. This option is similar to typing commands in \texttt{julia} at an interactive session. The analogy isn't exact, though, because at an interactive session it is one (1) command in, one (1) result out. Multiple lines in an org SRC block in contrast have RESULTS which are lumped together. Like this: (do \texttt{C-c C-c})
\begin{verbatim}
2 + 3
print("hello")
sqrt(5)
\end{verbatim}
\begin{verbatim}
5
hello
2.23606797749979
\end{verbatim}
It is sometimes helpful to split up SRC blocks into smaller chunks so that buildup of RESULTS does not get out of hand. Also, specific to \texttt{julia} we can sometimes put a semicolon at the end of the command to suppress output, like this:
\begin{verbatim}
2 + 3;
print("hello");
sqrt(5);
\end{verbatim}
\begin{verbatim}
hello
\end{verbatim}
Notice the outer two results were suppressed, but not the middle one.
\section[Graphics]{Graphics} \section[Graphics]{Graphics}
\label{sec-3} \label{sec-3}
...@@ -243,6 +286,8 @@ mode}. Assuming you've done that, evaluate the following code block. ...@@ -243,6 +286,8 @@ mode}. Assuming you've done that, evaluate the following code block.
file(p, "example1.png") file(p, "example1.png")
\end{verbatim} \end{verbatim}
\includegraphics[width=.9\linewidth]{example1.png}
The code block evaluates the command \texttt{file(p, "example1.png")}, which 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 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 \texttt{.pdf}, \texttt{.svg}, and \texttt{.eps}, though none of those can be inserted in
......
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