First, some history.

In the beginning, Donald Knuth created TeX

TeX (1978)

  • beautiful typesetting!
  • beautiful fonts! (Metafont)
  • bibliographies! (BibTeX)
  • beautiful mathematics!

and he saw that it was good and wrote some books.

Knuth also developed the idea of literate programming (1981) (WEB, TANGLE, WEAVE).

Later, LaTeX was built on TeX, with better separation of formatting and content (1985).

For genius computer scientists, the document preparation problem was solved.

39 years later…

… the World Wide Web and HTML happen …

A menagerie of file types

Markup languages

  • LaTeX - great for paper documents
  • HTML - great for the web
  • Markdown - a popular simple format, less typing than either HTML or LaTeX

Literate programming (documents with markup and code)

  • Rmarkdown
  • Jupyter notebooks

Other formats

  • PDF
  • DOC

pandoc

Write in the markup format you like, convert to whatever formats you need.

  • Convert between markdown, HTML, LaTeX, etc.
  • Convert to PDF, DOC, etc.

Literate programming

Source code as literature.

Code and description are both given in the same source document.

A particular form of this knits text, code, and output into the final document.

(See also: Roxygen, pydoc as examples of a different type of literate programming. Neither of these types fully match Donald Knuth's initial vision.)

Literate programming

R

  • knitr package by Yihui Xie to run code, knit text, code, and output into a markdown document.
  • rmarkdown package from RStudio automates using knitr and pandoc.

Python

  • Documents are JSON files.
  • Write using jupyter notebook web-based environment.
  • Convert to other formats with jupyter nbconvert (uses pandoc).

When you press the "knit" button…

Rmarkdown package orchestrates all of this.