Skip to Main Content

Quick Introduction to LaTeX

A quick guide to install and start using LaTeX

Introduction

Before reading this section you should have a basic understanding of how to create a LaTeX document, as well as, the basic structure of a document.  This section is about creating templates for LaTeX documents.  Templates are meant to speed up the initial creation of a LaTeX document.  Often, the same packages and document structure will be applicable to many of the documents you are working on.  Using a template will save you the time of having to input all of this information every time you create a new document.

Using and Creating Templates

A good front end LaTeX software package will contain at least some standard templates for different document types such as articles, beamers (slides for a presentation), and books.  A great one will also let you create your own template.  Templates can be very useful when there are certain documents types you need to create often such as class notes, homework assignments, and lab reports.  In these cases, a template will create consistency between documents and greatly simplify the creation of the document.

Using Templates

How to use a template depends on what program you are using to write your LaTeX code.  If you are not using any front end software, a template would simply be an already written .tex file you used to start your document.  It is important to make sure that you do not save over the template as you create the new document as this would destroy the template file.  Different front end software has different methods for using templates.  In TexStudio for example under "File" there is a "new from template" option.  TexStudio comes with a number of preprogrammed templates but also allows you to add your own.  TexMaker on the other hand, under file, has the option "new by copying an existing file".  In this case you would need to create your own template file,  but you would not have to worry that you might accidentally save over it.

If the template you are looking for is not built into the software you are using there are online resources such as LaTeX Templates where you can download templates for a variety of purposes.  A more advanced LaTeX user may also want to consider creating their own template. 

Creating Templates

When creating a template there are several important questions to ask yourself:

  1.  What document class will I need and will this ever change?  
    • It doesn't make sense to have a template if you will need to change the document class often.  It is also important to recognize which document best suits your needs (i.e. if you want sections use article but if you want chapters use book).
  2.  What packages will I need for the documents I am making?  
    • One of the best reasons to have a template is that you won't have write the preamble every time you start a new document, therefore it is very important to include all the packages you will need.  Its better to have extra packages than not enough.
  3.  How do I want the document to be structured?  
    • You can save time by incorporating certain common elements into you preamble such as title, author, and date.  You may also want include certain structures in the document, for example if you were making a lab report you may already include all the sections the report requires (Introduction, Experimental Setup, Results, Conclusions, etc...).  
  4.   Are there any new commands that I will want to create?
    • Perhaps you are using your template for a certain class that often uses matrices or a mathematical symbol with a long name.  Creating a new command as part of the template can help simplify the writing process.

Sample Template Code

% This is a template for doing homework assignments in LaTeX

\documentclass{article} % This command is used to set the type of document you are working on such as an article, book, or presenation

\usepackage{geometry} % This package allows the editing of the page layout
\usepackage{amsmath}  % This package allows the use of a large range of mathematical formula, commands, and symbols
\usepackage{graphicx}  % This package allows the importing of images

\newcommand{\question}[2][]{\begin{flushleft}
        \textbf{Question #1}: \textit{#2}

\end{flushleft}}
\newcommand{\sol}{\textbf{Solution}:} %Use if you want a boldface solution line
\newcommand{\maketitletwo}[2][]{\begin{center}
        \Large{\textbf{Assignment #1}
            
            Course Title} % Name of course here
        \vspace{5pt}
        
        \normalsize{Matthew Frenkel  % Your name here
        
        \today}        % Change to due date if preferred
        \vspace{15pt}
        
\end{center}}
\begin{document}
    \maketitletwo[5]  % Optional argument is assignment number
    %Keep a blank space between maketitletwo and \question[1]

    
    \question[1]{Here is my first question} 
    
    YOUR SOLUTION HERE
    
    \question[2]{Here is my second question}
    
    YOUR SOLUTION HERE
    
    \question[3]{What is the \Large{$\int_0^2 x^2 \, dx $}\normalsize{. Show all steps}}
    
    \begin{align*}
    \int_0^2 x^2 &= \left. \frac{x^3}{3} \right|_0^2 \\
                 &= \frac{2^3}{3}-\frac{0^3}{3}\\
                 &= \frac{8}{3}
    \end{align*}
\end{document}

 

Sample Template Output