-
Notifications
You must be signed in to change notification settings - Fork 6
/
exercises.tex
224 lines (196 loc) · 11.1 KB
/
exercises.tex
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
\documentclass[titlepage,colorlinks=true,urlcolor=blue,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.85]{beramono}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage[type={CC},modifier={by-sa},version={4.0}]{doclicense}
\usepackage{listings}
\lstset{language=[LaTeX]TeX,breaklines=true,basicstyle=\tt\normalsize,keywordstyle=\color{blue},commentstyle=\color{gray},tabsize=4}
\title{Introduction to \LaTeX{} --- Exercises}
\author{Dr Gerard Capes}
\date{\today}
\begin{document}
\maketitle
\section{Hello World!}
\begin{enumerate}
\item Create a new document.
\item In the editor window, \emph{type} the following lines:
\begin{lstlisting}[gobble=16]
\documentclass{article}
\begin{document}
Hello World
\end{document}
\end{lstlisting}
\item Save the file.
\item Compile your document and view the output.
\end{enumerate}
\section{My first latex document}
\begin{enumerate}
\item Open \href{first_latex_example.tex}{first\_latex\_example.tex} in your \LaTeX{} editor
\item Read through the file, taking note of whitespace and special characters -- these are described in the document
\item Compile the document to check your understanding of what you have just read
\item Try adding another section or subsection, then recompiling
\item Add a table of contents using the \lstinline|\tableofcontents| command
\item Change the font size used for the whole document by changing the options given to the \lstinline|\documentclass| command e.g. \lstinline|\documentclass[12pt]{article}|
\item Open the \href{https://mirror.ox.ac.uk/sites/ctan.org/info/latex2e-help-texinfo/latex2e.html#Document-class-options}{documentation} for the latex-document package. \\
Locate the section on ``document class options'', find out what the default paper size is, and how to change the paper size to a4.
If you are using \TeX{studio} the documentation can be found via: \\
\texttt{Help menu > Packages help\ldots{} > latex2e} or \\
right-click on \lstinline|\documentclass| \texttt{> Open package documentation}
\item Make a numbered list using the following code as a basis
\begin{lstlisting}[gobble=12]
\begin{enumerate}
\item first item
\end{enumerate}
\end{lstlisting}
\item Start a new section called `Science!'. Use inline math mode to describe the famous equation $e = mc^2$, from Einstein's mass-energy equivalence paper.
\end{enumerate}
If you get stuck, talk to the person next to you, ask the instructor, or look at \href{first_latex_solutions.tex}{first\_latex\_solutions.tex}.
\section{Equations and citations and cross-references}
For this exercise, continue to modify the \texttt{first\_latex\_example.tex} file.
\begin{enumerate}
\item Use the natbib package in combination with the physics.bib file to cite Einstein's mass-energy equivalence paper, which contains the equation $e=mc^2$. Use the `agu' bibliography style. Refer back to the slides for guidance on which commands to use, and where to use them.
\item Use an equation environment to typeset the Schr\"{o}dinger equation:
\begin{equation}
i\hbar \frac{\partial{}} {\partial{t}} \Psi(r,t) = \left[\frac{-\hbar^2}{2 \mu} \nabla ^2 + V(r,t)\right] \Psi(r,t)
\end{equation}
Search online for how to typeset the various characters, and feel free to experiment typesetting your own equations. Give the equation a label in order to refer back to it, then cite Schr\"{o}dinger's 1926 paper when you refer to this equation in the text - the citation is already in the physics.bib file.
If you get stuck, look at the source file \texttt{exercises.tex} and identify which command typesets which part of the equation.
\end{enumerate}
\section{Figures}
For this exercise, continue to modify the \texttt{first\_latex\_example.tex} file.
\begin{enumerate}
\item Add a figure using \href{https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions}{this page} as a guide. Use the \texttt{showers.png} file in this repository, or a file of your own. Note that you will need to add the following line to the \href{http://latex.wikia.com/wiki/LaTeX_preamble}{preamble} of your document in order to use the figure environment: \verb|\usepackage{graphicx}|. Experiment with different options such as \verb|\includegraphics[width=0.75\textwidth,angle=270]{showers}|
\item Add a label to your figure and use it to cross-reference (refer back to) the figure in the text. Use the example on \href{https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing}{this page} as a guide.
\end{enumerate}
\pagebreak
\section{Download the University Thesis Document}
\begin{enumerate}
\item A zip file containing the current version of the University Thesis Document can be downloaded from the Github repository, \url{https://github.com/gcapes/latex-thesis-template}, using the \texttt{Clone or download} button. Ensure you have the correct branch selected --- this version of the course requires the \texttt{bibtex} branch to be selected.
\item If you're following this course using overleaf.com, you will need upload the zip file to a new project. If you're using \TeX{studio}, find the downloaded zip file in Windows explorer, then \texttt{right click > extract all}. A good choice of location to extract the zip archive to would be your P drive.
\end{enumerate}
\section{Customise the University Thesis Document}
For the following exercises, recompile the \texttt{thesis.tex} document after you have completed each set of changes.
\begin{enumerate}
\item Open \texttt{thesis.tex} in your editor. Find and modify the following lines, using your details:
\begin{lstlisting}[gobble=20]
\begin{document}
...
\title{The University Thesis File}
\author{The Author's name}
% Faculty of Life Sciences people should comment the next line out
\school{The Author's school}
\faculty{The Author's faculty}
\end{lstlisting}
\item Find and modify the contents of the abstract (the abstract is located between \lstinline|\beforeabstract| and \lstinline|\afterabstract|).
\item In the section immediately after \lstinline|\prefacesection{Acknowledgements}|, add some acknowledgements.
\end{enumerate}
\section{Adding a Chapter}
\begin{enumerate}
\item In your \LaTeX{} editor, create a new file for your chapter and save it as \texttt{mychapter.tex}
\item Type \lstinline|\chapter{Methodology}| in the editor window to define it as the start of a chapter.
\item Include your new chapter file in the main \texttt{thesis.tex} file after the other included \texttt{*.tex} files (near the end of the file). Start a new line and use the command \lstinline|\include{mychapter}|. This will include the file \texttt{mychapter.tex}.
\item In your new chapter file, try some different writing commands, using the following examples:
\begin{lstlisting}[upquote=true,gobble=16]
This is going to include some ``quoted text''.
Some characters are reserved (i.e. they have a special purpose)
but can be accessed by escaping with a backslash, e.g. \%.
To use italics, try \textit{using this command!}.
Math mode is contained within dollars, e.g. $\delta$.
\end{lstlisting}
\item Save the changes to your chapter file, then recompile the \texttt{thesis.tex} file.
\end{enumerate}
\section{Referencing}
\begin{enumerate}
\item Open the thesis document and ensure the \lstinline|\bibliography{}| command points to the bibliography database (the \texttt{library.bib} file). The \texttt{.bib} file extension is not needed.
\item Open your new chapter file, start a new paragraph (insert a blank line) and include some referencing commands in the text using references from the bibliography file. Some examples are given below:
\begin{lstlisting}[gobble=12]
\citep{Payne2011}
\citealp{Porinchu2003,Payne2011}
\citet{Payne2011}
\citealt{Payne2011}
\citep[e.g.][]{Porinchu2003}
\citep[][p.245]{Porinchu2003}
\end{lstlisting}
\end{enumerate}
\section{Cross-referencing}
\begin{enumerate}
\item Add a reference label to the new chapter, using the command \lstinline|\label{ch:mychapter}|.
\item Cross reference the chapter in the \texttt{thesis.tex} file, e.g.
\begin{lstlisting}[gobble=16]
As described in chapter \ref{ch:mychapter}, this document is written in \LaTeX.
\end{lstlisting}
\item Remember you'll need to use a unique name inside the curly braces for each section, chapter, figure etc.
\item Commit your changes
\begin{lstlisting}[language=bash,showstringspaces=false,gobble=12]
git commit -am "Add cross-reference to mychapter"
\end{lstlisting}
\end{enumerate}
\section{Adding Figures}
\begin{enumerate}
\item Use the following code to add a figure in \texttt{mychapter.tex}:
\begin{lstlisting}[gobble=16]
\begin{figure}[htbp]
\centering
\includegraphics[width=1\textwidth]{example-image-a}
\caption[Short caption]{Long caption}
\label{labeltexthere}
\end{figure}
\end{lstlisting}
\item Try modifying the terms in the square brackets after \lstinline!\includegraphics!; experiment with \lstinline!\pageheight! or \lstinline!keepaspectratio!. Try using multiple terms separated with a comma (\lstinline!,!).
\item Now try the \lstinline!sidewaysfigure! environment. This uses the \texttt{rotating} package, so check whether you already have it in the preamble!
\end{enumerate}
\section{Drawing Tables}
\begin{enumerate}
\item Create a table using the following lines of code:
\begin{lstlisting}[gobble=16]
\begin{table}[htbp]
\centering
\begin{tabular}{lcc}
\toprule
Name & Age & Gender \\ \midrule
Tom & 26 & Male \\
James & 22 & Male \\
Eleanor & 25 & Female \\
\bottomrule
\end{tabular}
\caption[Short caption]{Long caption}
\label{}
\end{table}
\end{lstlisting}
\item Try adding a column for attendance by adding \lstinline!c! to the \lstinline!\begin{tabular}{lcc}! and some data to each row.
\item Remember cells are separated with an ampersand (\lstinline!&!), so you'll need to add this to each row.
\end{enumerate}
\section{Writing Equations}
\begin{enumerate}
\item Create an equation using the following code as an example:
\begin{lstlisting}[gobble=16]
\begin{equation}
e=mc^{2}
\label{massenergyequiv}
\end{equation}
\end{lstlisting}
\item Reference the equation in the text using \lstinline!\ref{massenergyequiv}!.
\end{enumerate}
\section{Inserting a quote}
Try inserting a quote using the \lstinline!quote! environment:
\begin{lstlisting}[gobble=12]
\begin{quote}
I think therefore I use \LaTeX{} for typesetting.
\end{quote}
\end{lstlisting}
\section{Escaped \& Special Characters}
Try using reserved characters like \&, \textbackslash, and \%, and you'll run into difficulty. Try writing the following:
\begin{lstlisting}[gobble=12]
If you need to write an ampersand (\&), use the slash to escape
or it will not render.
Similarly, if you wanted to use a slash or backslash (\backslash),
you must use a command.
If you need accents, they are often produced l\'ike this.
\end{lstlisting}
\begin{figure}[b]
\doclicenseThis
\end{figure}
\end{document}