Clement Lee (Newcastle University)
2024-06-14
The source file (.tex)
\documentclass[a4paper]{article}
\usepackage{amsmath}
\title{MATH9999 Practical 1 Questions}
\date{2024-06-14}
\begin{document}
\maketitle
\noindent
\begin{enumerate}
\item Plot the \texttt{cars} dataset in \verb^R^.
\item Find the numerical value of $2\pi$, to $4$ decimal places.
\item Show that $e^{i\pi}+1=0$.
\end{enumerate}
% A comment that won't appear in the output.
\end{document}
The output (.pdf)
MATH9999 Practical 1 Questions
2024-06-14
cars
dataset in R
.The source file (.tex)
\documentclass[a4paper]{article}
\usepackage{amsmath,graphicx,enumitem}
\title{MATH9999 Practical 1 Solutions}
\date{2024-06-14}
\begin{document}
\maketitle
\noindent
\begin{enumerate}
\item Plot the \texttt{cars} dataset in \verb^R^.
\begin{verbatim}
plot(cars)
\end{verbatim}
\begin{center}
\includegraphics[width=\textwidth]{cars.pdf}
\end{center}
\item Find the numerical value of $2\pi$, to $4$ decimal places.
\begin{verbatim}
round(2 * pi, 4)
## [1] 6.2832
\end{verbatim}
\item Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
\end{enumerate}
% A comment that won't appear in the output.
\end{document}
The output (.pdf)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rnw)
\documentclass[a4paper]{article}
\usepackage{amsmath,graphicx,enumitem}
\title{MATH9999 Practical 1 Solutions}
\date{2024-06-14}
\begin{document}
\maketitle
\noindent
\begin{enumerate}
\item Plot the \texttt{cars} dataset in \verb^R^.
<<cars>>=
plot(cars)
@
\item Find the numerical value of $2\pi$, to $4$ decimal places.
<<two-pi>>=
round(2 * pi, 4)
@
\item Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
\end{enumerate}
% A comment that won't appear in the output.
\end{document}
The output (.pdf)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 Solutions"
date: "2024-06-14"
output: pdf_document
---
1. Plot the `cars` dataset in `R`.
```{r cars}
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.pdf)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 Solutions"
date: "2024-06-14"
output: html_document
---
1. Plot the `cars` dataset in `R`.
```{r cars}
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 Solutions"
date: "2024-06-14"
output: html_document
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: true
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: true
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 Solutions"
date: "2024-06-14"
output: html_document
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: false
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: false
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: html_document
params:
solution: false
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Questions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: html_document
params:
solution: true
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: html_document
params:
solution: true
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## [1] 6.2832
The source file (.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: html_document
params:
solution: false
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Questions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
Show that \(e^{i\pi}+1=0\).
\[~\] \[~\] \[~\]
The source file (Practical1.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: ""
params:
solution: ""
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The R command
rmarkdown::render(
"Practical1.Rmd", params = list(solution = FALSE),
output_format = "html_document",
output_file = "Practical1_questions.html"
)
\[~\] \[~\] \[\Downarrow\Downarrow\Downarrow\] \[~\] \[~\]
The output (Practical1_questions.html)
MATH9999 Practical 1 Questions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
The source file (Practical1.Rmd)
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: ""
params:
solution: ""
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The R command
rmarkdown::render(
"Practical1.Rmd", params = list(solution = FALSE),
output_format = "pdf_document",
output_file = "Practical1_questions.pdf"
)
\[~\] \[~\] \[\Downarrow\Downarrow\Downarrow\] \[~\] \[~\]
The output (Practical1_questions.pdf)
MATH9999 Practical 1 Questions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
Practical1.Rmd
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: ""
params:
solution: ""
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The R script
library(rmarkdown)
render(
"Practical1.Rmd", params = list(solution = FALSE),
output_format = "pdf_document",
output_file = "Practical1_questions.pdf"
)
render(
"Practical1.Rmd", params = list(solution = FALSE),
output_format = "html_document",
output_file = "Practical1_questions.html"
)
render(
"Practical1.Rmd", params = list(solution = TRUE),
output_format = "pdf_document",
output_file = "Practical1_solutions.pdf"
)
render(
"Practical1.Rmd", params = list(solution = TRUE),
output_format = "html_document",
output_file = "Practical1_solutions.html"
)
The outputs
Practical1.Rmd
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: ""
params:
solution: ""
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{python two-pi}
#| include: !expr params$solution
import math
round(2 * math.pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The output (.html)
MATH9999 Practical 1 Solutions
2024-06-14
Plot the cars
dataset in R
.
Find the numerical value of \(2\pi\), to \(4\) decimal places.
## 6.2832
Lecture1.Rmd
---
classoption: a4paper
title: "MATH9999 Lecture 1 `r if (params$solution) 'Complete' else 'Gaps'` version"
date: "2024-06-14"
output: ""
params:
solution: ""
---
## Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
## Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
## Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
The R script
library(rmarkdown)
render(
"Lecture1.Rmd", params = list(solution = FALSE),
output_format = "pdf_document",
output_file = "Lecture1_gaps.pdf"
)
render(
"Lecture1.Rmd", params = list(solution = FALSE),
output_format = "html_document",
output_file = "Lecture1_gaps.html"
)
render(
"Lecture1.Rmd", params = list(solution = TRUE),
output_format = "pdf_document",
output_file = "Lecture1_complete.pdf"
)
render(
"Lecture1.Rmd", params = list(solution = TRUE),
output_format = "html_document",
output_file = "Lecture1_complete.html"
)
The outputs
01-preliminaries.Rmd
# Preliminaries
## Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
## Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
## Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
02-intermediate.Rmd, 03-advanced.Rmd, …
index.Rmd
---
title: "MATH9999"
date: Semester 2, 2023/2024
output: ""
documentclass: book
papersize: a4
geometry:
- margin=1in
fontsize: 12pt
bibliography: [references.bib]
biblio-style: apalike
link-citations: yes
params:
solution: ""
---
The R script
library(bookdown)
render_book(
"index.Rmd", param = list(solution = FALSE), # TRUE for complete version
output_format = c("bookdown::gitbook", "bookdown::pdf_book")
)
The outputs
Some work
equation
align
aligned
eqnarray
array
$$ $$
\[ \]
Some don’t (for HTML)
center
tabular
displaymath
\intertext
\textcolor
\medskip
\bigskip
\hfill
\newpage
Some have been taken care of
enumerate
: (R) Markdown can do listsitemize
: (R) Markdown can do listsquote
: (R) Markdown can do quotessolution
: The hack using strings in Rverbatim
: Backticks ``example
: Environment extended by bookdownexercise
: Environment extended by bookdownfigure
: Function knitr::include_graphics()
Practical1_solutions.tex
\documentclass[a4paper]{article}
\usepackage{amsmath,graphicx,enumitem}
\title{MATH9999 Practical 1 Solutions}
\date{2024-06-14}
\begin{document}
\maketitle
\noindent
\begin{enumerate}
\item Plot the \texttt{cars} dataset in \verb^R^.
\begin{verbatim}
plot(cars)
\end{verbatim}
\begin{center}
\includegraphics[width=\textwidth]{cars.pdf}
\end{center}
\item Find the numerical value of $2\pi$, to $4$ decimal places.
\begin{verbatim}
round(2 * pi, 4)
## [1] 6.2832
\end{verbatim}
\item Show that $e^{i\pi}+1=0$.
\begin{align*}
e^{i\pi}+1&=\cos\pi+i\sin\pi+1\\
&=-1+i\times0+1=0
\end{align*}
\end{enumerate}
% A comment that won't appear in the output.
\end{document}
And Practical1_questions.tex and some auxiliary files
Practical1.Rmd
---
classoption: a4paper
title: "MATH9999 Practical 1 `r if (params$solution) 'Solutions' else 'Questions'`"
date: "2024-06-14"
output: ""
params:
solution: ""
---
1. Plot the `cars` dataset in `R`.
```{r cars}
#| include: !expr params$solution
plot(cars)
```
2. Find the numerical value of $2\pi$, to $4$ decimal places.
```{r two-pi}
#| include: !expr params$solution
round(2 * pi, 4)
```
3. Show that $e^{i\pi}+1=0$.
```{r euler}
#| include: !expr params$solution
#| results: "asis"
#| echo: false
string0 <- "\\begin{align*}
e^{i\\pi}+1&=\\cos\\pi+i\\sin\\pi+1\\\\
&=-1+i\\times0+1=0
\\end{align*}"
cat(string0, "\n")
```
<!-- A comment that won't appear in the output. -->
And the R script / makefile
\label{}
outside (sub)(sub)section headings\textcolor
, \medskip
, \bigskip
, \hfill
, \newpage
, \intertext
\eqref{}
itemize
& enumerate
environmentsknitr::include_graphics()
(& convert .pdf to .png)knitr::kable()
(or markdown syntax for tables)dev
, out.width
Before | After | Remarks |
---|---|---|
\label{([^}]+)_([^}]+)_([^}]+)} |
{#\1-\2-\3} |
Similar for those with fewer "_" |
\ref{([^}]+)_([^}]+)_([^}]+)} |
\@ref(\1-\2-\3) |
Ditto |
\section{([^}]+)} |
## \1 |
One # fewer for single document |
\section*{([^}]+)} |
## \1 {-} |
Ditto; similar for (sub)(sub)sections |
\textit{([^}]+)} |
*\1* |
Same for \emph{([^}]+)} |
\textbf{([^}]+)} |
**\1** |
|
\texttt{([^}]+)} |
`\1` |
Same for \verb |
\Sexpr{([^}]+)} |
`r \1` |
|
\footnote{([^}]+)} |
^[\1] |
|
` `(.*)'' |
"\1" |
Before below replacments with ` |
^<<>>=$ |
```{r} |
|
^<<(.*)>>= |
```{r, \1} |
|
^@[\s]? |
``` |
|
^%(.*) |
<!-- \1 --> |
After fixing environments commented out |
(self-defined LaTeX commands) | (Markdown replacements) | (or just original LaTeX commands) |
Figure~ | Figure
|
Not regex; with space at the end; |
same for Chapter, Section, etc. | ||
\_ |
_ |
Not regex; same for \$ , \% and \& |
rmarkdown
(all lowercase)
bookdown
tinytex
(recommended)
tinytex::install_tinytex()
tinytex::tlmgr_install()
usefulreticulate
& Python (3)