Skip to content

Instantly share code, notes, and snippets.

Last active September 7, 2015 21:53
What would you like to do?
Example.Rmd showing executable Elixir code in Tufte Handout RMarkdown format
title: "Executable Elixir in Tufte Handout"
author: "Wendy Smoak"
date: "September 1, 2015"
output: rmarkdown::tufte_handout
```{r setup, echo=FALSE}
# Adapted from
# Licensed CC-BY-SA
# As required by
eng_elixir <- function(options) {
# create a temporary file
f <- basename(tempfile("temp", '.', paste('.', "exs", sep = '')))
on.exit(unlink(f)) # cleanup temp file on function exit
writeLines(options$code, f)
out <- ''
# if eval != FALSE compile/run the code, preserving output
if (options$eval) {
out <- system(sprintf('elixir %s', paste(f, options$engine.opts)), intern=TRUE)
# spit back stuff to the user
engine_output(options, options$code, out)
# Introduction
This is an example document in Tufte Handout Format. It is edited in RStudio in RMarkdown format and transformed into a PDF with File -> Knit from the menu, or Cmd-Shift-K.
# Tufte Handout
> Tufte Handouts[^tufte-handout] are documents formatted[^tufte-latex] in the style that Edward Tufte uses in his books and handouts. Tufte’s style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography:
The format has the usual `#` and `##` headings. Also margin figures (see the equation --> over there, with a caption even,) as well as full-width and main-column figures.
$$ x^2 + y^2 = 1 $$
\caption{An equation}
# Elixir Code
Here is some Elixir code *and the output*, which was produced by executing the code at the time the PDF was created:
\marginnote{This is a margin note.}
defmodule Math do
def sum(a, b) do
a + b
IO.puts "The answer is #{ Math.sum(4,3) }"
In the source[^source] of this document, you will find the code that makes this possible, adapted from an article on running Go snippets in RMarkdown files[^go-rmd].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment