LaTeX is a typesetting system, specifically designed for scientific report writing. It is freely available and has many editors, both downloadable and online, which come ready-to-use and even include document templates. There is an active community and several forum sites from which you can get help online; as well as a large development community creating additional packages which add to the functionality of $\LaTeX$ itself.
Unlike other document creation and editing programs, like MS Word or iOS Pages, $\LaTeX$ (or more specifically TeX) doesn't let you use a Graphical User Interface to manipulate your document.
That means that you can't "drag-and-drop" text and images around a page, instead what you do is write a plain text file (saved as a .tex
file) which contains commands for $\LaTeX$ to read to assemble your document!
Losing the ability to interact graphically with your document is a scary prospect for some people, and might sound like you're loosing a lot of functionality - but as you'll see over the course of these lessons working from a plain text file and having $\LaTeX$ interpret it provides us with much more power and control over our document. One of the main advantages of $\LaTeX$ is the way it seemlessly combines text (prose), images, equations, tables and the like; all of which are generated through commands and can have their properties controlled directly and precisely. Contrast this to a problem that I'm sure we have all experienced before:
Let's firstly create a new project for this session. To do so, you should register an account in order to use the online $\LaTeX$ service. You can also use your own $\LaTeX$ editor but things may look different to any screenshots in the lessons.
You should see an interface like the following.
There are three coloums: the left-end coloum shows all the files/folder under your current project; the middle column is where you type your source $\LaTeX$ code; the column on the right shows you the output of your document.
As you go through this introcution course, you can type/copy the provided code to the input pane (the middle coloumn) and click the Recompile
button on the top of the output pane (the right coloum) to see the result.
Now empty your input pane and place in the following code instead. This is an example of a (really) small $\LaTeX$ document; commonly called a "minimum working example".
\documentclass{article}
%you can type some commands before the document begins here. This section is called the preamble and we will talk about what it can be used for later.
\begin{document}
%all the content for your document goes in here
Hello World!
\end{document}
You should end up with a document that contains the phrase "Hello world!".
You can start writing your document by typing text between \begin{document} ... \end{document}
.
This is also where you will include commands for placing images into your document, breaking the document into sections, creating title pages and contents, amongst other things.
Some common characters have special meanings in $\LaTeX$:
%
percent sign (for comments, as we have seen)#
hash sign (technical use in user-defined commands)&
ampersand (used to align mathematical equations and tables)$
dollar sign (used to begin mathematical equations)If you want these to appear in the output you need to put a backslash before them as shown below, otherwise you'll get an error and your document won't be created.
%%pdflatex
\$ %produces a dollar sign
\% %produces a percent sign and doesn't start a comment!
\& %produces an ampersand
\# %produces a hash sign
Environments are used to format blocks of text in a $\LaTeX$ documents.
Environments are delimited by an opening tag \begin
and a closing tag \end
.
Everything inside those tags will be formatted in a special manner depending on the type of the environment.
For example, the itemize
and enumerate
environments generate lists:
%%pdflatex
This first environment will create a bullet-point list:
\begin{itemize} %for bulleted lists
\item Biscuits
\item Tea
\end{itemize}
This environment will create a numbered list:
\begin{enumerate} % for numbered lists
\item Biscuits
\item Tea
\end{enumerate}
Within an environment, additional commands are made available that won't work outside the environment.
For example you can't use a \item
command outside an enumerate
or itemize
environment; and most mathematical symbols cannot be used outside of math
environments, which we will see in lesson 2.
All of the commands and environments we've used so far are built into $\LaTeX$.
Packages are libraries of extra commands and environments for different purposes.
We have to load each the packages we want to use with a \usepackage{}
command in the preamble of the source file - this is the part of your .tex
file before the \begin{document}
command.
In the preamble, you define the type of document you are writing and the language, load extra packages that you need, and set several parameters like the font and text size.
You can also use style files to load some of the information that would go in a preamble.
For example, the amsmath
package is a suppliment for the existing mathematical capabilities of $\LaTeX$.
In the following code, we create an equation environment which is defined in the amsmath
package.
We will a more in-depth discussion of writing equations in the next lesson.
Your $\LaTeX$ file should look like this:
\documentclass{article}
\usepackage{amsmath} % preamble, in which we load the amsmath package. If you don't have this package installed on your machine, your editor will prompt you to download it.
\begin{document}
\begin{equation}
-u'' = -\omega^2 u
\end{equation}
\end{document}
And below is the document output.
%%pdflatex
\begin{equation}
-u'' = -\omega^2 u
\end{equation}