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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
% "30m" but took me 2h. Very informative. I've copy pasted the examples here
% to play with them. Reading this tutorial before starting big LaTeX projects
% (like my thesis) would've been very beneficial and safe me some time and
% headaches. I'm happy I've read it and completed it now, some concepts are
% now much clearer.
%
% Ref.: https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes
% preamble ("setup" section)
% ============================================================================
\documentclass[12pt, a4paper]{article}
% document class: article (other options include book and report)
% aditional options: 12pt font (default is 10pt), a4paper size
% Loading packages `\usepackage[options]{package}`
\usepackage{graphicx}
\graphicspath{{img/}}
\usepackage{amsmath} % For the "equation*" environment
\usepackage{parskip} % Used to typeset paragraphs with larger spacing
% \usepackage[
% total={6.5in,8.75in},
% top=1.2in, left=1.0in, includefoot
% ]{geometry}
\title{My first LaTeX document}
\author{Hubert Farnsworth\thanks{Funded by the Overleaf team.}}
\date{September 2023}
% \date{\today}
% actual content
% ============================================================================
\begin{document}
\maketitle
\tableofcontents
\begin{abstract}
This is a simple paragraph at the beginning of the document. A brief
introduction about the main subject.
\end{abstract}
% \part{Learn}
% \chapter{Learn \LaTeX}
\section{Basic typesetting}
First document. This is a simple example, with no extra parameters or packages
included.
We have now added a title, author and date to our first \LaTeX{} document!
Some of the \textbf{greatest}
discoveries in \underline{science}
were made by \textbf{\textit{accident}}. (\textit{italics}.)
% emphasize (toggles italics depending on context)
% (some packages, such as Beamer, change the behaviour of the \emph command.)
Some of the greatest \emph{discoveries} in science were made by accident.
\textit{Some of the greatest \emph{discoveries} in science were made by accident.}
% "starred version" of the appropriate command
\section*{Unnumbered section}
% unnumbered sections aren't added to the TOC by default
\addcontentsline{toc}{section}{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et
neque pharetra sollicitudin. Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...
\section{Figures}
% images
% The \includegraphcs command is provided (implemented) by the graphicx package
Lorem Ipsum Lorem Ipsum Lorem Ipsum
How is text rendered just before an image?
\includegraphics[width=0.25\textwidth]{rocas}
How is text rendered right after an image?
% figures: captions, labels, references
\begin{figure}[h]
% Code here is encapsulated by the "figure" environment
\centering
\includegraphics[width=0.15\textwidth]{rocas}
\includegraphics[width=0.30\textwidth]{rocas}
\includegraphics[width=0.60\textwidth]{rocas}
\caption{From the top left, clockwise: Unas roquitas relajandose, unas rocas
relajandose, unas rocotas relajandose.}
% Caption can be placed above or below the list of figures
\label{fig:rocas}
\end{figure}
As you can see in figure \ref{fig:rocas}, the rocks are happyto see their owner.
(This example is on page \pageref{fig:rocas}.)
\section{Lists}
% lists
\begin{itemize}
\item The individual entries are indicated with a black dot, a so-called bullet.
\item The text in the entries may be of any length.
\end{itemize}
\begin{enumerate}
\item This is the first entry in our list.
\begin{enumerate}
\item This is the 1.1 entry in our list.
\begin{enumerate}
\item This is the 1.1.1 entry in our list. Things begin to look messy
\begin{enumerate}
\item This is the 1.1.1.1 entry in our list. Things begin to look messy
in the source code.
% Maximum default depth (4) reached, further is invalid
% \begin{enumerate}
% \item This is the 1.1.1.1 entry in our list. Things begin to look messy
% in the source code.
% \item The list numbers increase with each entry we add.
% \end{enumerate}
\item The list numbers increase with each entry we add.
\end{enumerate}
in the source code.
\item The list numbers increase with each entry we add.
\end{enumerate}
\item The list numbers increase with each entry we add.
\end{enumerate}
\item The list numbers increase with each entry we add.
\end{enumerate}
\section{Math}
% math
% inline math uses the "math" environemnt
\begin{math} E=mc^2 \end{math} is typeset in a paragraph using inline math
mode---as is $E=mc^2$, and so too is \(E=mc^2\).
% display math uses the "displaymath" or the "equation" environment
% (usage of $$ is no longer recommended).
The mass-energy equivalence is described by the famous equation
\[ E=mc^2 \] discovered in 1905 by Albert Einstein.
In natural units ($c = 1$), the formula expresses the identity
\begin{equation} E=m \end{equation}
% more examples
Subscripts in math mode are written as $a_b$ and superscripts are written as
$a^b$. These can be combined and nested to write expressions such as
\[ T^{i_1 i_2 \dots i_p}_{j_1 j_2 \dots j_q} =
T(x^{i_1},\dots,x^{i_p},e_{j_1},\dots,e_{j_q}) \]
We write integrals using $\int$ and fractions using $\frac{a}{b}$. Limits are
placed on integrals using superscripts and subscripts:
\[ \int_0^1 \frac{dx}{e^x} = \frac{e-1}{e} \]
Lower case Greek letters are written as $\omega$ $\delta$ etc. while upper case
Greek letters are written as $\Omega$ $\Delta$.
Mathematical operators are prefixed with a backslash as $\sin(\beta)$,
$\cos(\alpha)$, $\log(x)$ etc.
% amsmath package:
\begin{equation*}
\sqrt{x^2+1}
\end{equation*}
% manual newline
I will start the third paragraph and then add \verb`\\`\\ a manual line break which
causes this text to start on a new line but remains part of the same paragraph.
Alternatively, I can use the \verb|\newline|\newline command to start a new
line, which is also part of the same paragraph.
% Longer documents, irrespective of authoring software, are usually partitioned
% into parts, chapters, sections, subsections and so forth.
\section{Document Structure}
Collectively, LaTeX document classes provide the following sectioning commands,
with specific classes each supporting a relevant subset:
\begin{verbatim}
\part{part}
\chapter{chapter}
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\paragraph{paragraph}
\subparagraph{subparagraph}
In particular, the \part and \chapter commands are only
available in the report and book document classes.
\end{verbatim}
\section{Tables}
TIP: Creating tables in LaTeX can be time-consuming so you may want to use the
https://tablesgenerator.com online tool to export LaTeX code for tabulars.
\begin{center}
\begin{tabular}{c c c}
% alignment: Center, Right, Left
% &: alignment symbol
% \\: newline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
% adding borders (rules)
\begin{tabular}{||c l c r||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex] % control extra spacing
\hline\hline
1 & hola & 87837 & 787 \\
\hline
2 & mundo & 78 & 5415 \\
\hline
% 3 & 世界、 & 778 & 7507 \\
% \hline
% 4 & こんにちは & 18744 & 7560 \\
% \hline
5 & hello world! & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\end{center}
% To add captions, labels, and references use the Table environment
Table \ref{table:data} shows how to add a table caption and reference a table.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||}
\hline
Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
\hline\hline
1 & 6 & 87837 & 787 \\
2 & 7 & 78 & 5415 \\
3 & 545 & 778 & 7507 \\
4 & 545 & 18744 & 7560 \\
5 & 88 & 788 & 6344 \\ [1ex]
\hline
\end{tabular}
\caption{Table to test captions and labels.}
\label{table:data}
\end{table}
\section{Finding and using LaTeX packages}
Documentation (in pdf format) in
\begin{verbatim}
~/code/tex-live-native/build/texmf-dist/doc/latex
\end{verbatim}
\LaTeX packages usually have ".sty" extension.
Packages are distributed through the Comprehensive TeX Archive Network
(https://www.ctan.org/), usually referred to as CTAN.
Once per year a (large) subset of packages hosted on CTAN, plus LaTeX-related
fonts and other software, is collated and distributed as a system called TeX
Live (https://tug.org/texlive/), which can be used to install your own (local)
LaTeX setup.
Overleaf (https://www.overleaf.com) makes available thousands of templates in
their gallery (https://www.overleaf.com/gallery).
Some nice packages like https://ctan.org/pkg/igo?lang=en are hosted on CTAN
but not distributed by TeX Live due to a variety of reasons: perhaps a package
is obsolete, has licensing problems, is extremely new (recently uploaded) or has
platform dependencies, such as working on Windows but not Linux.
\end{document}
|