1% All comment lines start with %
2% There are no multi-line comments
3
4% LaTeX is NOT a "What You See Is What You Get" word processing software like
5% MS Word, or OpenOffice Writer
6
7% Every LaTeX command starts with a backslash (\)
8
9% LaTeX documents start with a defining the type of document it's compiling
10% Other document types include book, report, presentations, etc.
11% The options for the document appear in the [] brackets. In this case
12% it specifies we want to use 12pt font.
13\documentclass[12pt]{article}
14
15% Next we define the packages the document uses.
16% If you want to include graphics, colored text, or
17% source code from another language file into your document,
18% you need to enhance the capabilities of LaTeX. This is done by adding packages.
19% I'm going to include the float and caption packages for figures
20% and hyperref package for hyperlinks
21\usepackage{caption}
22\usepackage{float}
23\usepackage{hyperref}
24
25% We can define some other document properties too!
26\author{Chaitanya Krishna Ande, Colton Kohnke, Sricharan Chiruvolu \& \\
27Svetlana Golubeva}
28\date{\today}
29\title{Learn \LaTeX{} in Y Minutes!}
30
31% Now we're ready to begin the document
32% Everything before this line is called "The Preamble"
33\begin{document}
34% if we set the author, date, title fields, we can have LaTeX
35% create a title page for us.
36\maketitle
37
38% If we have sections, we can create table of contents. We have to compile our
39% document twice to make it appear in right order.
40% It is a good practice to separate the table of contents form the body of the
41% document. To do so we use \newpage command
42\newpage
43\tableofcontents
44
45\newpage
46
47% Most research papers have abstract, you can use the predefined commands for this.
48% This should appear in its logical order, therefore, after the top matter,
49% but before the main sections of the body.
50% This command is available in the document classes article and report.
51\begin{abstract}
52 \LaTeX{} documentation written as \LaTeX! How novel and totally not
53 my idea!
54\end{abstract}
55
56% Section commands are intuitive.
57% All the titles of the sections are added automatically to the table of contents.
58\section{Introduction}
59Hello, my name is Colton and together we're going to explore \LaTeX!
60
61\section{Another section}
62This is the text for another section. I think it needs a subsection.
63
64\subsection{This is a subsection} % Subsections are also intuitive.
65I think we need another one.
66
67\subsubsection{Pythagoras}
68Much better now.
69\label{subsec:pythagoras}
70
71% By using the asterisk we can suppress LaTeX's inbuilt numbering.
72% This works for other LaTeX commands as well.
73\section*{This is an unnumbered section}
74However not all sections have to be numbered!
75
76\section{Some Text notes}
77%\section{Spacing} % Need to add more information about space intervals
78\LaTeX{} is generally pretty good about placing text where it should
79go. If
80a line \\ needs \\ to \\ break \\ you add \textbackslash\textbackslash{}
81to the source code.
82
83Separate paragraphs by empty lines.
84
85You need to add a tilde after abbreviations (if not followed by a comma) for a
86non-breaking space, because otherwise the spacing after the dot is too large:
87E.g., i.e., etc.~are such abbreviations.
88
89\section{Lists}
90Lists are one of the easiest things to create in \LaTeX! I need to go shopping
91tomorrow, so let's make a grocery list.
92\begin{enumerate} % This creates an "enumerate" environment.
93 % \item tells the enumerate to increment
94 \item Salad.
95 \item 27 watermelon.
96 \item A single jackrabbit.
97 % we can even override the item number by using []
98 \item[how many?] Medium sized squirt guns.
99
100 Not a list item, but still part of the enumerate.
101
102\end{enumerate} % All environments must have an end.
103
104\section{Math}
105
106One of the primary uses for \LaTeX{} is to produce academic articles
107or technical papers. Usually in the realm of math and science. As such,
108we need to be able to add special symbols to our paper!
109
110Math has many symbols, far beyond what you can find on a keyboard;
111Set and relation symbols, arrows, operators, and Greek letters to name a few.
112
113Sets and relations play a vital role in many mathematical research papers.
114Here's how you state all x that belong to X, $\forall x \in X$.
115% Notice how I needed to add $ signs before and after the symbols. This is
116% because when writing, we are in text-mode.
117% However, the math symbols only exist in math-mode.
118% We can enter math-mode from text mode with the $ signs.
119% The opposite also holds true. Variable can also be rendered in math-mode.
120% We can also enter math mode with \[\]
121
122\[a^2 + b^2 = c^2 \]
123
124My favorite Greek letter is $\xi$. I also like $\beta$, $\gamma$ and $\sigma$.
125I haven't found a Greek letter yet that \LaTeX{} doesn't know
126about!
127
128Operators are essential parts of a mathematical document:
129trigonometric functions ($\sin$, $\cos$, $\tan$),
130logarithms and exponentials ($\log$, $\exp$),
131limits ($\lim$), etc.~have pre-defined LaTeX commands.
132Let's write an equation to see how it's done:
133$\cos(2\theta) = \cos^{2}(\theta) - \sin^{2}(\theta)$
134
135Fractions (Numerator-denominators) can be written in these forms:
136
137% 10 / 7
138$$ ^{10}/_{7} $$
139
140% Relatively complex fractions can be written as
141% \frac{numerator}{denominator}
142$$ \frac{n!}{k!(n - k)!} $$
143
144We can also insert equations in an ``equation environment''.
145
146% Display math with the equation 'environment'
147\begin{equation} % enters math-mode
148 c^2 = a^2 + b^2.
149 \label{eq:pythagoras} % for referencing
150\end{equation} % all \begin statements must have an end statement
151
152We can then reference our new equation!
153Eqn.~\ref{eq:pythagoras} is also known as the Pythagoras Theorem which is also
154the subject of Sec.~\ref{subsec:pythagoras}. A lot of things can be labeled:
155figures, equations, sections, etc.
156
157Summations and Integrals are written with sum and int commands:
158
159% Some LaTeX compilers will complain if there are blank lines
160% In an equation environment.
161\begin{equation}
162 \sum_{i=0}^{5} f_{i}
163\end{equation}
164\begin{equation}
165 \int_{0}^{\infty} \mathrm{e}^{-x} \mathrm{d}x
166\end{equation}
167
168\section{Figures}
169
170Let's insert a figure. Figure placement can get a little tricky.
171Basic options are [t] for top, [b] for bottom, [h] for here (approximately).
172I definitely have to lookup the placement options each time.
173% See https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions for more details
174
175\begin{figure}[H] % H here denoted the placement option.
176 \centering % centers the figure on the page
177 % Inserts a figure scaled to 0.8 the width of the page.
178 %\includegraphics[width=0.8\linewidth]{right-triangle.png}
179 % Commented out for compilation purposes. Please use your imagination.
180 \caption{Right triangle with sides $a$, $b$, $c$}
181 \label{fig:right-triangle}
182\end{figure}
183
184\subsection{Table}
185We can also insert Tables in the same way as figures.
186
187\begin{table}[H]
188 \caption{Caption for the Table.}
189 % the {} arguments below describe how each row of the table is drawn.
190 % The basics are simple: one letter for each column, to control alignment:
191 % basic options are: c, l, r and p for centered, left, right and paragraph
192 % optionally, you can add a | for a vertical line
193 % See https://en.wikibooks.org/wiki/LaTeX/Tables for more details
194 \begin{tabular}{c|cc} % here it means "centered | vertical line, centered centered"
195 Number & First Name & Last Name \\ % Column rows are separated by &
196 \hline % a horizontal line
197 1 & Biggus & Dickus \\
198 2 & Monty & Python
199 \end{tabular}
200 % it will approximately be displayed like this
201 % Number | First Name Last Name
202 % -------|--------------------------- % because of \hline
203 % 1 | Biggus Dickus
204 % 2 | Monty Python
205\end{table}
206
207\section{Getting \LaTeX{} to not compile something (i.e.~Source Code)}
208Let's say we want to include some code into our \LaTeX{} document,
209we would then need \LaTeX{} to not try and interpret that text and
210instead just print it to the document. We do this with a verbatim
211environment.
212
213% There are other packages that exist (i.e. minty, lstlisting, etc.)
214% but verbatim is the bare-bones basic one.
215\begin{verbatim}
216 print("Hello World!")
217 a%b; % look! We can use % signs in verbatim.
218 random = 4; #decided by fair random dice roll, https://www.xkcd.com/221/
219 See https://www.explainxkcd.com/wiki/index.php/221:_Random_Number
220\end{verbatim}
221
222\section{Compiling}
223
224By now you're probably wondering how to compile this fabulous document
225and look at the glorious glory that is a \LaTeX{} pdf.
226(Yes, this document actually does compile).
227
228Getting to the final document using \LaTeX{} consists of the following
229steps:
230 \begin{enumerate}
231 \item Write the document in plain text (the ``source code'').
232 \item Compile source code to produce a pdf.
233 The compilation step looks like this (in Linux): \\
234 \begin{verbatim}
235 > pdflatex learn-latex.tex
236 \end{verbatim}
237 \end{enumerate}
238
239A number of \LaTeX{} editors combine both Step 1 and Step 2 in the
240same piece of software. So, you get to see Step 1, but not Step 2 completely.
241Step 2 is still happening behind the scenes\footnote{In cases, where you use
242references (like Eqn.~\ref{eq:pythagoras}), you may need to run Step 2
243multiple times, to generate an intermediary *.aux file.}.
244% Also, this is how you add footnotes to your document!
245% with a simple \footnote{...} command. They are numbered ¹, ², ... by default.
246
247You write all your formatting information in plain text in Step 1.
248The compilation part in Step 2 takes care of producing the document in the
249format you defined in Step 1.
250
251\section{Hyperlinks}
252We can also insert hyperlinks in our document. To do so we need to include the
253package hyperref into preamble with the command:
254\begin{verbatim}
255 \usepackage{hyperref}
256\end{verbatim}
257
258There exists two main types of links: visible URL \\
259\url{https://learnxinyminutes.com/latex/}, or
260\href{https://learnxinyminutes.com/latex/}{shadowed by text}
261% You can not add extra-spaces or special symbols into shadowing text since it
262% will cause mistakes during the compilation
263
264This package also produces list of thumbnails in the output PDF document and
265active links in the table of contents.
266
267\section{Writing in ASCII or other encodings}
268
269By default, historically LaTeX accepts inputs which are pure ASCII (128),
270but not extended ASCII, meaning without accents (à, è etc.) and non-Latin symbols.
271
272It is easy to insert accents and basic Latin symbols, with backslash shortcuts
273Like \,c, \'e, \`A, \ae and \oe etc. % for ç, é, À, etc
274% See https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes for more
275
276To write directly in UTF-8, when compiling with pdflatex, use
277\begin{verbatim}
278 \usepackage[utf8]{inputenc}
279\end{verbatim}
280The selected font has to support the glyphs used for your document, you have to add
281\begin{verbatim}
282 \usepackage[T1]{fontenc}
283\end{verbatim}
284
285Since LuaTeX and XeLaTeX were designed with built-in support for UTF-8, making
286life easier for writing in non-Latin alphabets.
287
288\section{End}
289
290That's all for now!
291
292% Most often, you would want to have a references section in your document.
293% The easiest way to set this up would be by using the bibliography section
294\begin{thebibliography}{1}
295 % similar to other lists, the \bibitem command can be used to list items
296 % each entry can then be cited directly in the body of the text
297 \bibitem{latexwiki} The amazing \LaTeX{} wikibook: \emph{https://en.wikibooks.org/wiki/LaTeX}
298 \bibitem{latextutorial} An actual tutorial: \emph{http://www.latex-tutorial.com}
299\end{thebibliography}
300
301% end the document
302\end{document}
More on LaTeX ¶
- The amazing LaTeX Wikibook: https://en.wikibooks.org/wiki/LaTeX
- An actual tutorial: http://www.latex-tutorial.com/
- A quick guide for learning LaTeX: Learn LaTeX in 30 minutes
- An interactive platform to learn LaTeX (installationfree) learnlatex.org/
- Stack Exchange’s question and answer site about TeX, LaTeX, ConTeXt, etc. tex.stackexchange.com