Make a Document in LaTeX - Beginners Guide
by adamrees89 in Circuits > Software
10873 Views, 7 Favorites, 0 Comments
Make a Document in LaTeX - Beginners Guide
Ok, so you've decided to take the plunge and learn Latex (the typesetting language, not the plasticy stuff...) but how do you create a document that you can add to and publish pdf's until your heart is content?
So first things first, you're going to need some software, there are two cases I'm going to cover, Windows and Linux (Specifically Ubuntu).
Windows
Ok so Windows does not natively support latex like Linux does, so we need to install MikTex, and at the time of writing, it was at version 2.9.
After this you are pretty much set to go, but everything is controlled using the command line and old looking interfaces, so we'll install a nice front end. There are many to choose from, but I really like Texmaker, again at the time of writing version 4.0.2.
REMEMBER you need the windows version.
Linux (Ubuntu)
Now Ubuntu does natively support latex, so all we have to do is download and install Texmaker, either from that link or in the software centre.
Now that we have installed Texmaker and/or MikTex its time to actually start working!
Preamble
Now before we start writing, each document that you make should have its own folder on your computer, in this folder all the files associated with your document will be kept here, such as pictures and whatnot.
When writing in texmaker, its a good idea to seperate your code with comments. Comments are made in latex using the '%' symbol and only cover one line, for example;
%This is a comment
This is not
So then to start a document we need to tell latex what type of document it is by using the following command;
\documentclass[ ]{ }
This command and most of the commands in latex are initated using the backslash '\' character, and generally follow the same template: \command[Options]{Parameters}
latex built-in document classes are as follows;
*article
*report
*letter
*book
*proc
*slides
There are others such as a meeting minutes class, but these need googling to understand.
So we need to tell latex several things; paper size, font size, document class, and any other options such as double sided, two columns, etc.
For this instructable we will use a4paper, 11pt font, and report. These are inputted as follows;
\documentclass[11pt, a4paper]{report}
All the options go between the square brackets and the document class goes between the parentheses (curly) bracket.
After the document class comes the additional packages that you might need. There are loads of packages, and I'm not going to list any useful ones incase I start an arguement, however a general package I've found to be extremely useful is todo notes. To use a package we simply enter them in after the document class line;
\usepackage[options]{package name}
so for todo notes;
\usepackage{todonotes}
(todo notes is a bad example in hindsight as it doesn't have any options...) If the package you're using doesn't have any options associated with it you can safely delete the square brackets.
Finally the last piece of the preamble puzzle is the start of the document;
\begin{document}
this will add a \end{document} line underneath it, and your writing should be between these two.
See the picture for a sample preamble.
Main Body of the Document
So between the \begin{document} and \end{document} tags we need to actually start some writing.
How about a title page?
So we need to add the following to the preamble;
\author{Your name}
\date{\today}
\title{My title}
Where Your Name, and My Title are changed with whatever you want to add, and \today is a command that tells latex to print todays date.
After these are added to the preamble, we simply add the;
\maketitle
command between the document tags.
Table of Contents/Figures/Tables
These are easy to add and only require a few lines;
\tableofcontents
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
\newpage
So these commands create a table of contents and figures and tables, and adds the latter two to the table of contents.
Now we can actually start typing away,
New document part
To seperate your document into several parts such as beginning, middle, and end we type;
\part{Beginning}
which will create a big division between parts.
Chapters
These are easy like parts we simply type;
\chapter{My impressive chapter title}
Sections
Now we can further divide the chapters into sections using the following command;
\section{Subdivision of my impressive chapter}
subsections
This is getting ridiculous but we can make subsections, and even subsubsections by typing the following;
\subsection{A subdivision to my awesome section}
\subsubsection{A subsection to my subsection}
So there you go, under eas section/subsection/subsubsection you write your paragraph! Easy?
References and Figures
Now the situation may come about when writing a document where we need to refer to a section/figure etc, so we need to know how to do that. It is done by using labels, and then refering to them.
So in my text I need to refer to my awesome chapter, I'll add a label underneath the chapter line like so;
\chapter{Awesome Chapter}
\label{chp:awe_chp}
It doesn't really matter what you call your labels, but I find it helps to stick to the basic principle of saying what the label refers to, then adding a label name, for example;
chp: is for a chapter
sec: for a section
ssec: for a subsection
fig: for a figure
tab: for a table
eq: for an equation
Refering to a label
Now that we have defined our labels, lets refer to them, so in the text we write \ref{label name}, for example
The derivation and explanation of this super important equation can be seen in chapter \ref{chp:awe_chp}.
This will print the following;
The derivation and explanation of this super important equation can be seen in chapter 2.
Where the reference to a label is replaced by the chapter/section/whatever number.
Figures
Now adding pretty pictures and graphs to your document follows the same procedure, first we add the picture to your document folder.
Now call the picture something easy to remember, such as 'picture'
Back to latex, we add the following code;
\begin{figure}[!th]
\centering
\includegraphics[scale=1]{picture.png}
\caption{An awesome caption to go with my picture}
\label{fig:picture}
\end{figure}
So the \begin{figure} is self-explanatory, however the options in square brackets [!th] are not. These tell latex that I want to put my figure here, no really here. This is how I like to do my figures in latex, but other people like to leave latex to decide the best place to put a figure.
Next the \centering command, this centers the figure in the middle of the page width, include graphics is where we say which file to input, and the \caption command adds a line of text under the picture.
to refer to this in the text we simply type;
As can be seen in figure \ref{fig:picutre}.
Which will be output as;
As can be seen in figure 2.1.
So there ends the quick introduction to latex and how to make a document.
Maths
Further Reading/Help
In the coming months, I will be making more Latex instructables and will update the links here. But for now here are some external websites/references I find useful/have been suggested;
*My template Repository - Contains useful pre-made LaTeX templates
*Gitter chat, you can talk to me on gitter about the templates or getting latex set up
* ctan.org
* LaTeX Project
* LaTeX Manual
* TeX Blog
* LaTeX Wikibook