Wiki: LaTex

Basic LaTex Syntax Reference
by Oliver; Jan. 13, 2014
   

Introduction

Microsoft Word sucks. LaTex, a markup language, is a more programmatic way of typesetting documents. It produces pretty results and it's free to download here. There's a great introduction to LaTex at: One thing to note about LaTex: it's rather finicky, at least for beginners like me. As markup languages go, I find it a lot harder to use than, say, HTML. If you're using it for the first time, writing something will involve scouring lots of chat forums.

This wiki is a collection of miscellaneous LaTex syntax I want to remember—so you know what to expect, it's more a reminder to myself than a carefully crafted article. I'm a firm believer in the basics and that's what you'll find here.

Document Classes

The documentclass command sets a template for your document. Quoting directly from http://en.wikibooks.org/wiki/LaTeX/Document_Structure, some document classes are:
articleFor articles in scientific journals, presentations, short reports, program documentation, invitations, ...
IEEEtranFor articles with the IEEE Transactions format.
procA class for proceedings based on the article class.
minimalIs as small as it can get. It only sets a page size and a base font. It is mainly used for debugging purposes.
reportFor longer reports containing several chapters, small books, thesis, ...
bookFor real books.
slidesFor slides. The class uses big sans serif letters.
memoirFor changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it [1]
letterFor writing letters.
beamerFor writing presentations (see LaTeX/Presentations).

Example Document: Hello World

This is a bare bones first document:
\documentclass[letterpaper,10pt]{report}
\usepackage[margin=0.75in]{geometry}
\begin{document}

Hello Word

\end{document}

LaTex Comments

This is a comment in LaTex:
% comment

Font Size

Font size from https://engineering.purdue.edu/ECN/Support/KB/Docs/LaTeXChangingTheFont:
  • \tiny
  • \scriptsize
  • \footnotesize
  • \small
  • \normalsize
  • \large
  • \Large
  • \LARGE
  • \huge
  • \Huge

Font Styling

To style fonts in bold and italic:
\textbf{This is bold}
\textit{This is italic}

Making Lists

To make a list:
\begin{itemize}
\itemsep -1.5em
  \item first\\
  \item second\\
  \item third\\
\end{itemize}

Indentation

Turn indentation on or off:
\noindent
\indent

Horizontal Line

Draw a horizontal line:
\noindent\rule{17cm}{0.4pt}\\

Page Numbering

Remove page numbers:
\pagenumbering{gobble}

Linking to URLs on the Web

You can link a URL from within your pdf:
\usepackage{hyperref}
\urlstyle{same} % keeps link style same as rest of document

\begin{document}

\url{http://www.nytimes.com}
\href{http://www.nytimes.com}{New York Times}

\end{document}

Compiling LaTex Documents from the Command Line

Compile a .tex file from the command line to produce a .pdf:
$ pdflatex mydoc.tex
# produces mydoc.pdf
pdflatex should be in your PATH after you install it.

How to Print Chinese in LaTex

As outlined here:
% for Chinese:
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\begin{document}
中文
\end{document}
Then compile as:
xelatex mydoc.tex 

Example Document: A Resume (Complete Source Code)

Here's the full source code for a resume, sample_resume.tex, I wrote in LaTex:
\documentclass[letterpaper,10pt]{report}
\usepackage[margin=0.5in]{geometry}

% for making links to the web
\usepackage{hyperref}
\urlstyle{same}

\usepackage{titlesec}
\titleformat*{\section}{\small\bfseries}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\begin{document}

% remove page numbers:
\pagenumbering{gobble}

\title{Resume}
\author{You}
\date{January 2014}

{\raggedleft
{\Large Full Name\\}
email@univeristy.edu\\
\textit{\href{http://www.mywebsite.com}{mywebsite.com}}\\
}

\section*{Education}       
\noindent\rule{17cm}{0.4pt}\\
\noindent
\textbf{My University}, New York, NY - \textit{2000-2002}
\vspace{-2mm}
\renewcommand\labelitemi{\tiny$\bullet$}
\begin{itemize}
\itemsep -1.5em
  \item Ph.D. in personality\\
  \item Significant coursework: x and y\\
\end{itemize}

\vspace{-5mm}

\noindent
\textbf{My College}, Boston, MA - \textit{1990-1994}\\
\vspace{-6mm}
\begin{itemize}
\itemsep -1.5em
  \item B.A. in philosophy\\
  \item GPA: 4.0\\
  \item GRE: Verbal-100 Quantitative-100\\
\end{itemize}

\vspace{-3mm}

\section*{Employment}       
\noindent\rule{17cm}{0.4pt}\\
\noindent
\textbf{My Job}, New York, NY - \textit{2005-present}
\vspace{-2mm}
\renewcommand\labelitemi{\tiny$\bullet$}
\begin{itemize}
\itemsep -1.5em
  \item Specializing in something. Including:
	\vspace{-2mm}
	\begin{itemize}
	\itemsep -1.5em
	  \item AAA\\
	  \item BBB\\
	  \item CCC\\
	\end{itemize}
  \vspace{-1mm}
  \item homepage: \textit{\href{http://uni.edu}{job web site}}\\
\end{itemize}

\vspace{-5mm}

\noindent
\textbf{My Job 2}, Paris, France - \textit{August, 2004-March, 2005}\\
\vspace{-6mm}
\begin{itemize}
\itemsep -1.5em
  \item what i did\\
\end{itemize}

\vspace{-5mm}

\noindent
\textbf{My Job 3}, Mexico City, Mexico - \textit{2002-2003}\\
\vspace{-6mm}
\begin{itemize}
\itemsep -1.5em
  \item what i did\\
\end{itemize}

\vspace{-3mm}

\section*{Computers}       
\noindent\rule{17cm}{0.4pt}\\
\noindent
\textbf{Skillz}
\vspace{-2mm}
\renewcommand\labelitemi{\tiny$\bullet$}
\begin{itemize}
\itemsep -1.5em
  \item Programs: Excel, Word, Powerpoint\\
  \item Social Media: Twitter, Tinder\\
\end{itemize}

\vspace{-3mm}

\section*{Selected Publications}       
\noindent\rule{17cm}{0.4pt}\\
\noindent
\textbf{Article 1.}\\
Joe et al.
\textit{Some Journal} 2001 May 21; 544(34):13-15.\\

\noindent
\textbf{Article 2.}\\
Jane et al.
\textit{Some Journal} 2014 Sept 01; 88(8):1-7.\\

\section*{Languages}       
\noindent\rule{17cm}{0.4pt}\\
\noindent
\textbf{French}
\vspace{-2mm}
\renewcommand\labelitemi{\tiny$\bullet$}
\begin{itemize}
\itemsep -1.5em
  \item Fluent in the present tense\\
\end{itemize}

\end{document}
It produces:

image

Example Document: A Book of Lyrics

Here's some partial code for a book of musical lyrics typeset in LaTex:
\documentclass[letterpaper,10pt,twocolumn]{report}
\usepackage[margin=0.75in]{geometry}
\usepackage{multicol}
\usepackage{graphicx}
\setlength{\columnsep}{1in}
\begin{document}
\noindent
\title{Lyrics}
\maketitle
\newpage
\tableofcontents
\clearpage

\raggedright

\section*{Adele}
\addcontentsline{toc}{section}{Adele}

\subsection*{Someone Like You}
\addcontentsline{toc}{subsection}{Someone Like You}

\textbf{Chords G G/F\# Em C}\\

\includegraphics[scale=0.75]{G_adele.png}

I heard that you're settled down\\
That you found a girl and you're married now.\\
I heard that your dreams came true.\\
Guess she gave you things I didn't give to you.\linebreak

...\newpage

\section*{Etta James}
\addcontentsline{toc}{section}{Etta James}

\subsection*{I Just Want To Make Love To You}
\addcontentsline{toc}{subsection}{I Just Want To Make Love To You}

I don't want you to be no slave\\
I don't want you to work all day\\
But I want you to be true\\
And I just wanna make love to you\linebreak
Note: the asterisk in \section*{ } suppresses the default section numbering.
Advertising

image


image


image