Documents with Markup
2024-10-29
(in chronological order)
Think of it as the digital version of a printing press.
You will use tags to control the formatting of your document, and then compile it to PDF.
\emph{}
for italic text\textbf{}
for bold text{\HUGE }
, {\footnotesize }
The LaTeX system lays out your document according to a set of rules for spacing, margins, figure captions, cross-references, …
Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do.
— Donald E. Knuth, Literate Programming, 1984
useR! 2016 was celebrating the markdown systems as epic milestones for literate programming: https://www.r-project.org/conferences/useR-2016/keynotes.html
While a .tex file is just a text file, it can help to use a dedicated editor that will compile your document for you.
Some options:
Of these, Lyx and Rstudio support integrating your code with your document using knitr/Sweave.
\documentclass{article} % 1
\usepackage[utf8]{inputenc} % 2
\usepackage{natbib} % 3
\usepackage{graphicx} % 4
\title{Demo} % 5
\author{Susan VanderPlas}
\date{\today}
\begin{document} % 6
\maketitle % 7
\section{Introduction} % 8
\citet{adams1995hitchhiker}
\section{Conclusion}
\bibliographystyle{plain} % 9
\bibliography{refs}
\end{document}
type of document (article)
allow UTF-8 characters
use a bibliography
allow pictures
Document header information
Actual document content
Create document title/header
Create introduction section (with a citation)
Create the bibliography
One of the most wonderful parts of LaTeX is BibTeX, which handles your citations for you.
Bibtex does all of the hard work of cross-linking your references with the bibliography, formatting, etc.
There are various options for (free!) citation managers - personally, I love Zotero and Mendeley because they also integrate with RStudio.
Recent blog with comparison of these and a few other reference managers.
All these programs help to keep track of papers and associated notes and will export BibTeX automatically.
They also come with browser addins that will easily save papers to your library as you surf.
Inline math: $x + 2$
Centered math:
$$
x+2
$$
Systems of equations:
\begin
{align} x &= a + b\\
y &= c + d
\end{align}
Math characters:
\alpha, \beta, \gamma, \infty, \rightarrow, \int,\frac{a}{b}
\(x + 2\) is an inline equation.
We can also center equations within a paragraph, like this: \[x + 2\] The paragraph resumes after we’re done.
Systems of equations:
\(\begin{align} x &= a + b\\ y &= c + d\end{align}\)
Math characters:
\[\alpha,\beta,\gamma,\infty,\rightarrow,\int,\frac{a}{b}\]
Minimal LaTeX document:
\documentclass{article}
\begin{document}
Hello \LaTeX!
\end{document}
Add the quadratic formula and the PDF of a normal distribution to the document
In extremely large text, print LaTeX using the \LaTeX
command
In extremely small, italic text, print your name
LaTeX only creates PDF files (and PostScript files, but nevermind those).
Enter pandoc, which was supposed to be a “universal translator” of markup formats.
Markdown document ->
With pandoc, the goal is to transfer the content; the exact formatting is less of a priority. Thus, only a small set of formatting options are supported.
You can use the same BibTeX files in markdown with Pandoc!
Minimal markdown document:
---
title: "Demo"
author: "Me"
date: "October 2020"
output:
word_document: default
html_document: default
pdf_document: default
---
# Introduction
# Conclusion
# References
Add an image from the internet
Add the quadratic formula and the probability density function of a normal distribution to the document
Math mode works the same in markdown as in LaTeX (mostly)
Add a citation to the Hitchhiker’s Guide using this references file
Sweave
was the original document compilation system for combining LaTeX
and R
(created circa 2002)
knitr
: created in 2012 by Yihui Xie to be a better version of Sweave
Sweave
features + someTo add R code to your .tex file,
Change the file extension from .tex
to .Rnw
(Rnw = R no weave, a holdover from Sweave
)
Add R code chunks
Compile your document
R code chunks in .Rnw documents
<<chunk-name, chunk-options>>=
R code here
@
You’ve been using quarto for the entire semester, but it works essentially the same way as adding R to LaTeX:
Quarto is similar, but supports even more formats and allows you to use even more programming languages in code chunks.
eval = (T/F)
: whether the code is evaluated by R
include = (T/F)
: should code or output from the code be included in the document?
echo = (T/F)
: should code be printed in the document, or just the output?
fig.width, fig.height =
: size of the saved image, in inches
out.width =
: width of the output image IN THE DOCUMENT
fig.cap =
: Set a figure caption
cache = (T/F)
: Cache the chunk, so that it is only re-run if it changes?
All of these chunk options also work in rmarkdown
Turn your .tex file into an .Rnw file and add some more stuff!
\Sexpr{}
knitr::kable()
to print out the first 6 rows of the cars dataframe.Table Packages
Other packages
Both LaTeX and quarto/Rmarkdown make use of other libraries to expand the types of documents available.
Document Type | Library | Compiler | End Result | |
---|---|---|---|---|
Slides | Beamer | LaTeX or Markdown + LaTeX | ||
Reveal.js | Markdown | HTML | ||
IOSlides | Markdown | HTML | ||
Slidy | Markdown | HTML | ||
PowerPoint | Markdown | PowerPoint | ||
Xaringan | Markdown + JS | HTML/markdown hybrid | ||
Poster | Beamer | LaTeX | ||
Posterdown | Markdown | HTML | ||
Pagedown | Markdown | HTML |
These documents use the same basic markdown or LaTeX syntax, but render differently.