-
Notifications
You must be signed in to change notification settings - Fork 2
/
03-figref.Rmd
154 lines (119 loc) · 7.57 KB
/
03-figref.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
145
146
147
148
149
150
151
152
153
154
# Cross-referencing, Illustrating and Citing {#figref}
LaTeX has simple but powerful tools to allow you to cross-reference, illustrate and `cite` sources in your documents, see figure \@ref(fig:wikipedian-fig).
```{r wikipedian-fig, echo = FALSE, fig.align = "center", out.width = "70%", fig.cap='(ref:captionwikipedian)'}
knitr::include_graphics("images/wikipedian_protester.png")
```
(ref:captionwikipedian) It has always been important to cite your sources and LaTeX gives you the tools to cite properly. _Wikipedian Protester_ cartoon by [Randall Munroe](https://en.wikipedia.org/wiki/Randall_Munroe) at [xkcd.com/285](https://xkcd.com/285/) published under a [Creative Commons Attribution-NonCommercial 2.5 License](https://creativecommons.org/licenses/by-nc/2.5/)
## Cross-referencing
LaTeX allows you to cross-reference almost anything in your document, including sections, sub-sections, tables and figures. To use the cross-referencing feature you simply insert the command:
```tex
\label{mymarker}
```
at the point in the document you want to refer to, and then use the command:
```tex
\ref{mymarker}
```
when you want to refer to it. Obviously you replace the text `mymarker` with something more meaningful. An important tip here is to call the marker something that refers to the content of that part of the document, and to avoid the temptation to use numbers in case you re-order your document. For example, lets say we wanted to cross reference between sections:
```tex
\documentclass[a4paper]{article}
\begin{document}
\section{Turing Machines: The Simplest Computers}
\label{sec:simplest}
Turing machines are the simplest and most widely used theoretical models of computing. Far too slow and unwieldy ever to be embodied in a real device, these conceptual machines nevertheless seem to capture everything we mean by the term \textit{computation}. Not only do Turing machines occupy the top level of the Chomsky hierarchy, but they also seem capable of computing any function which is computable by any other conceptual scheme.
\section{Alan Turing}
The Turing machines described in section \ref{sec:simplest} are named after Alan Turing.
\end{document}
```
## Illustrating your documents
Documents without figures, images, pictures and graphs are pretty dull, so you'll want to illustrate your document with figures such as the one in Figure \@ref(fig:turing-fig), for example.
```{r turing-fig, echo = FALSE, fig.align = "center", out.width = "40%", fig.cap='(ref:captionturing)'}
knitr::include_graphics("images/Alan_Turing_Aged_16.jpg")
```
(ref:captionturing) [Alan Turing](https://en.wikipedia.org/wiki/Alan_Turing) at the age of sixteen, portrait by unknown author, public domain, via Wikimedia Commons [w.wiki/oZx](https://w.wiki/oZx)
Including figures and pictures in your document is straightforward. You do it like this:
```tex
\begin{figure}
\includegraphics[width=10cm]{images/turing.jpg}
\caption{Turing machines are named after Alan Turing}
\label{figure:turing}
\end{figure}
```
The command `\includegraphics{}` gets your image, which can be PDF, PNG, JPG, GIF or PostScript. The `\begin{figure}` and `\end{figure}` code wraps up whatever picture you’re including, and allows LaTeX to treat it as an unbreakable floating thing that it will position for you as best it can in the document, while maintaining an overall nice typographical layout. This “floating” of figures can sometimes result in the figure ending up in a place you didn’t expect, but in most cases LaTeX will make the most sensible choice. It’s possible to employ finer control over figure placement, but that’s beyond the scope of this guide.
The `\includegraphics` command is not built in to core LaTeX but is in an additional package, which needs to be explicitly loaded. You can load this package by using the command `usepackage` in the document preamble, in between the `\documentclass` and the `\begin{document}`.
```tex
\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
```
## Exercise two: picture this {#ex2}
Create a document `image.tex`, that contains some text (maybe from Lorem Ipsum), together with a figure containing an image of your choice. Create a cross reference to the figure in the text.
## Citations and footnotes
Footnotes^[This is a footnote about footnotes. Very meta.] can be added to a document with `\footnote{}`
```tex
\footnote{This is a footnote about footnotes}
```
You can cite sources such as websites, books or journal articles in your document using the `\cite` command.
```tex
\cite{alanturing}
```
The metadata for the citations can be stored in a separate `*.bib file` using a format called BibTeX, in this case we'll use `turing.bib`. BibTeX provides citation types so books are described using the `@book` type like this:
```tex
@Book{turingomnibus,
title = {The New Turing Omnibus: Sixty-six excursions in Computer Science},
author = {A. K. Dewdney},
publisher = {Henry Holt},
address = {New York},
year = {2001},
isbn = {9780805071665},
url = {https://en.wikipedia.org/wiki/Special:BookSources?isbn=978-0805071665}
}
```
and articles^[BibTeX entries for journal articles can be automatically generated from persistent identifiers known as [digital object identifiers](https://en.wikipedia.org/wiki/Digital_object_identifier) or doi's, such as https://doi2bib.org for example. This saves you the unpleasant, time consuming and error prone task of typing them in by hand.] use the `@article` type like this:
```tex
@article{alanturing,
doi = {10.1112/plms/s2-42.1.230},
url = {https://doi.org/10.1112/plms/s2-42.1.230},
year = {1937},
publisher = {Wiley},
volume = {s2-42},
number = {1},
pages = {230--265},
author = {Alan Turing},
title = {On Computable Numbers, with an Application to the Entscheidungsproblem},
journal = {Proceedings of the London Mathematical Society}
}
```
For everything else^[There are many other types of BibTeX entries besides articles, books and misc. See https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management#BibTeX] you can use the `@misc` type:
```tex
@misc{googlescholar,
author = {Anon},
title = {Alan Turing Google Scholar page},
url = {https://scholar.google.co.uk/citations?user=VWCHlwkAAAAJ},
year = {2022},
}
```
So to create the text:
“*You can find Turing's publications in Google scholar. [@googlescholar]
His paper on the Entscheidungsproblem was published in 1937. [@turing]
He wrote about thinking machines in 1950. [@turing50]*”
You add this to your tex file:
```tex
You can find Turing's publications in Google scholar. \cite{googlescholar}
His paper on the Entscheidungsproblem was published in 1937. \cite{alanturing}
He wrote about thinking machines in 1950. \cite{turing50}
```
To generate your bibliography you'll need to specify what style of bibliography you're using with `\bibliographystyle{stylename}` and where to find the metadata with `\bibliography{bibfile}`. The example below uses a style called `unsrt` and uses a bib file called `turing.bib` which might contain many articles and books. You don't need to specific the file extension `.bib`:
```tex
\bibliographystyle{unsrt}
\bibliography{turing}
```
When you compile you need to run `pdflatex` before and after running `bibtex` like this:
```tex
pdflatex turing.tex
bibtex turing
pdflatex turing.tex
pdflatex turing.tex
```
If you find all the typing at the command line tedious, you could write a little bash script to automate this simple workflow including opening the pdf when it is created.
## Summary {#fingconc}
You have cross-referenced, illustrated, added citations and footnotes to your document. Next we'll look at doing some maths.