index

{Intro} {Setup} {Hello World} {Examples} {Links}

Intro

I started submitting assignments in LaTeX recently, and have built a few templates I like to use. LaTeX is an open-source typesetting format that is highly customizable and widely implemented in academia. The user has full control over what appears where on the page, equations render beautifully, and references to figures and bibliographies update as you would want them to. The final output is usually .pdf form, and thus easily viewable on any device.

Here’s a taste of what a LaTeX equation looks like, and the text that made it (Fourier expansion of a periodic function in n dimensions):

  • Compiled Equation:

     n(\vec{r}) = \sum_{\mathbf{G}}n_{\mathbf{G}}exp(i{\mathbf{G}}\cdot {\mathbf{r}}) \qquad \qquad (1)
  • Plain text of the above (what you’ll find in the .tex file):

    n(\vec{r}) = \sum_{\mathbf{G}}n_{\mathbf{G}}exp(i{\mathbf{G}}\cdot {\mathbf{r}}) \qquad \qquad (1)

Setup

My LaTeX stack (on a PC) consists of the following:

  • TeXStudio – Main editor. This is where .tex and .bib files are edited and compiled. Most all the work is done here. I’m very happy with TeXStudio as it offers some really helpful tools like autocompletion, lots of shortcuts and template wizards, and maybe best of all, the debugger, which highlights just what part of your LaTeX code needs changing when you have a compile error.
  • Mendeley – Free reference tracker and pdf viewer/editor. This is only needed if you are going to be using citations in your work, but if you are, its highly suggested. (Think End-Note for those who are still enchained to Microsoft Word). In my undergrad, I used a Firefox addon ‘Zotero’, but it seems most research groups at Stanford used a shared Mendeley folder for research, so all can contribute, organize petinent journal articles for the group. You don’t actually need this program to build bibliographies, google scholar will build .bib citations for you. For that route, search a paper (or anything) on google scholar, and under any result, click “Cite”, and then “BibTeX”. This returns the text of the citation in BibTeX format. You can then use any text editor (notepad or else), copy paste these citations in, and save as a .bib file in the same directory as your .tex master file.

Hello World

Here’s a very simple document, with comments (%%) explaining each part. This text can be copy/pasted into a .tex document and rendered:

\documentclass{article}  
%% Basic formatting of the document type.  
%% This will be by far the most common type you use.

\usepackage{amsmath}  
%% imports a package.  There are many packages that help 
%% to do different things (like code syntax highlighting 
%% I import many packages - see example 1 below.

\begin{document}  
%% \begin{text} ... \end{text} encapsulates many structures 
%% in LaTeX.  Here, everything in between these tags is 
%% to be published on the page.

Hello World  
%% Text that will print to the page.

$\beta = e^{3}$  
%% One way to render an equation inline.

\end{document}

Examples

Each item link below has a link to both the raw text of the .tex file and a .zip of the .tex file, the figures that file pulls in, and any other needed files to compile. Feel free to copy the text and modify as needed, or download the .zip and and compile in your favorite LaTeX environment to see how it looks in final form / was made.

Note the goal is not to understand the content; these are homework assignments while at Stanford, and I haven’t included the questions themselves in the spirit of preventing future class-men from being able to find these ‘solutions’ online.

  • Example 1: This is a pretty simple file that implements a matlab syntax highlighter to show the solution code and the inserts the matlab resultant figures into the document as well (figures not referenced).
    Example_1 (contents of .tex file)
    Example_1.zip
  • Example 2: This example is more of a paper, and makes an example of using a bibliography (.bib file) and references in the final document that pull from that bibliography. Find the \cite{…} flags in the raw .tex file and note how they become reference numbers in the final rendering. These references are ordered at compile time, which means you can add a reference to the beginning of your document, and upon recompiling, the reference numbers of all following citations will shift automatically. Note! the references in this example document are pulled somewhat randomly and do not necessarily reference the work they point to. (I deleted my original bibliography and threw this one together). This example is only for learning LaTeX, not the content therein.
    Example_2 (contents of .tex file)
    Example_2.zip

  • Example 3: This final example shows the use of referenced tables, referenced figures, and nested lists.
    Example_3 (contents of .tex file)
    Example_3.zip

Links

I used the following tutorials, references when getting started in LaTeX, in roughly this order:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.