-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path02-simples.Rmd
144 lines (101 loc) · 8.45 KB
/
02-simples.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Simple LaTeX Documents {#simples}
Let's start by creating a simple LaTeX document.
## A very short document {#shortest}
Open up your favourite text editor^[it is worth configuring your editor so that it is LaTeX aware, and can do [syntax highlighting](https://en.wikipedia.org/wiki/Syntax_highlighting), suggest auto-completions and spell-check for you. Tools like [VS Code](https://code.visualstudio.com/) and [sublimetext](https://www.sublimetext.com/) and many others will do this for you], enter the following text, then save it as a file called `turing.tex`:
```tex
\documentclass[a4paper]{article}
\begin{document}
Computational excursions
\end{document}
```
To turn this into a pdf we need to use a LaTeX compiler, we're going to use `pdflatex`, though several other compilers are available.^[https://www.overleaf.com/learn/latex/Choosing_a_LaTeX_Compiler] On Linux the `pdflatex` compiler is already installed and can be used from the command line.^[for example the Linux VM image for VirtualBox https://wiki.cs.manchester.ac.uk/index.php/CSImage_VM] If you're not using Linux, you'll need to explore the options at [latex-project.org/get](https://www.latex-project.org/get/).
```{r eval=FALSE}
# compile turing.tex
pdflatex turing.tex
# open the pdf output
xdg-open turing.pdf
# or just open turing.pdf on a mac
```
The first command outputs a pdf file from your `turing.tex` input using the `pdflatex` compiler. The second command opens the file you've created. If you list the directory contents, you'll see that the compiler has also created an auxillary `*.aux` file and a `*.log` file which can be helpful when you're debugging the compilation:
```{r eval=FALSE}
# files created on compilation
turing.tex
turing.pdf
turing.aux
turing.log
```
## A longer LaTeX document {#longer}
Our `turing.tex` file is a very simple document, so let's add some sections and fill them out a bit:
```tex
\documentclass[a4paper]{article}
\begin{document}
\section{Algorithms: Cooking Up Programs}
A program specifies in the \textbf{exact syntax} of some programming language the computation one expects a computer to perform. The syntax is precise and unforgiving. The slightest error in the program as written may cause the computation to be in error or may halt altogether. The reason for this situation seems paradoxical on the surface: It is relatively easy to design a system that converts rigid syntax to computations; it is much harder to design a system that tolerates mistakes or accepts a broader range of program descriptions.
\section{Finite automata: The Black Box}
It occasionally happens in industrial, military or educational settings that one is presented with a piece of electronic hardware whose exact function is uncertain or unknown. One way of discovering how the device works is to take it apart, piece by piece, and deduce its function by analysing the components and their interconnections. This is not always possible, however, nor is it always necessary. Given that the mystery machine has both input and output facilities, it may be possible to discover what it does without ever taking it apart. Since its appearance gives no clue about its function, we call it a \textit{black box}.
\section{Systems of Logic: Boolean Bases}
In an age of computers and automation, almost every electronic device one can name incorporates at least one boolean function. For example, many current models of automobile will emit a high-pitched whine, buzz or other disturbing noise until their drivers fasten their seat belts. Such a device realises a boolean function of two variables.
\section{Simulation: The Monte Carlo method}
In the quest to understand the many systems that comprise the modern world we turn increasingly to computer simulation. Whether the system is natural or artificial, frequently one or more of its components have such complex behaviour that the only feasible approach to approximating such behaviour is to assume that it is random.
\section{Gödel's Theorem: Limits on Logic}
In the early 1930's, Kurt Gödel, a German mathematician, attempted to show that predicate calculus was complete - that one can obtain mechanically (in principle, at least) a proof of any true formula expressed in that calculus. His failure to do this was crowned by the discovery that the task was impossible.
\section{Can machines think?}
Turing addressed the question ``Can machines think?'' in his 1950 paper \textit{Computing machinery and intelligence}.
\section{But what is LaTeX good for?}
We're using this \LaTeX\ document to demonstrate some of its key strengths that you will find useful during and after University:
\begin{enumerate}
\item LaTeX can quickly create pdf files
\item LaTeX uses professional typesetting
\item LaTeX documents can be more legible, clear, and visually appealing to the reader than those created with word processing software
\end{enumerate}
\end{document}
```
The text here is excerpted from *The New Turing Omnibus: 66 excursions in Computer Science* [@turingomnibus]. The Omnibus is a lovely introduction to the fundamentals of Computer Science that you might enjoy. In his book review, the software engineer [Jeff Atwood](https://en.wikipedia.org/wiki/Jeff_Atwood) calls the omnibus an “incredibly fun little book”. [@codinghorror]
## Exercise one: documentum {#ex1}
In your file `turing.tex` either cut-and-paste this longer text into your document or make your own sections and text. You could use text from [Lorem ipsum](https://en.wikipedia.org/wiki/Lorem_ipsum) at [lipsum.com](https://www.lipsum.com) to fill out the page.
Now, at the top of your document after the `\begin{document}` line and before first `\section`, add the following commands, each on their own line:
```tex
\title{The New Turing Omnibus}
\author{A. K. Dewdney}
\maketitle
\tableofcontents
\newpage
```
The `title`, `author`, `tableofcontents` and `newpage` commands are self-explanatory. The `maketitle` automatically inserts today's date. Your table of contents won't be created until you run pdflatex **twice** because on the first run, LaTeX gathers and stores information about what to put in the table of contents, and only creates it on the second run.
```{r eval=FALSE}
# remember to run pdflatex twice for the table of contents
pdlfatex turing.tex
pdflatex turing.tex
```
## Bold, italic and lists
Here's a few points to note about the text above:
* Notice how **bold** and *italic* formatting are created using `\textbf{}` and `\textit{}`
* Notice how lists are created with `\item`s inside either `\begin{enumerate}` for numbered lists or `\begin{itemize}` for bulleted lists.
## Quotation marks
Typographic or “curly” quotation marks are different characters and *not* the same as straight quotes. They look nicer, but you have to remember that unlike straight quotes, open and close quotation marks are different characters:
* open quote **“** which looks a bit like a miniature `66`
* close quote **”** which looks a bit like a miniature `99`
Look carefully at the quotation marks in the text below:
* Turing addressed the question “Can machines think“... ❎
* Turing addressed the question “Can machines think”... ✅
In your `*.tex` file the correct version looks like this
```tex
Turing addressed the question ``Can machines think''
```
not
```tex
Turing addressed the question ``Can machines think``
```
or
```tex
Turing addressed the question ''Can machines think''
```
You've probably never noticed these details because most word processing software^[Microsoft Word, Google Docs etc] tends to auto-correct quotations marks for you. Since LaTeX isn't a word processor (see section \@ref(notword)) it leaves your mistakes on the page for all to see. These mistakes are really noticeable in a pdf file and/or printed, so they are worth paying attention to.
<!--Historically, web browsers have had poor typography, although its getting better all the time, see [fonts.google.com](https://fonts.google.com/) for example-->
## Summary {#concsimple}
You've created a basic document in LaTeX and we've introduced some of its advantages:
* LaTeX can quickly create pdf files
* LaTeX uses professional typesetting
* LaTeX can create pdf files that look better than those created with conventional word processing software packages
<!-- need the graph of word vs latex pain-->
Next we'll look at adding some cross-references, figures and citations. This is one thing that LaTeX does much better than your average word processing software which makes it great for editing larger and longer documents, such as your Bachelors, Masters or PhD thesis.