Skip to main content

LaTeX: Simple Example

An Example of a Simple Document

%This is the preamble of the document - a percent sign is the delimiter for a comment.

%A command begins with a '\' then is a sequence of characters. The first non-character (including a space) ends the command, so this is the documentclass command.
\documentclass[twopage]{article}

%A required argument is in curly brackets. One option must be specified. Sometimes you can specify more than one as in this example.
\usepackage{graphicx,alltt,ifthen,amsthm}

%Arguments can be a value or key=value. An optional argument is in square brackets.
%If an option is not specified, some default is used. Often, there are multiple arguments separated by commas.
\usepackage[pdfpagemode=UseNone,pdfstartview=FitB]{hyperref}

%Add half of the vertical space of a line when a paragraph ends. This line is considered a declaration.
\setlength{\parskip}{0.5\baselineskip}

%An environment uses the begin command. If you begin a command, you must end it using the end command.
%The document environment is very important. Think of it as where you actually write to the document.
\begin{document}

%Optional and required arguments can appear in a different order.
%There can be more than one [] containing optional arguments for one command
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\section{First Section}
%This line uses the command version to make text boldface.
This is my first paragraph. If I want to write a second one, there \textbf{MUST} be a blank line between them.

%Special characters need a \ to notify the engine to typeset the character. In this case, the engine should print % instead of ignoring the rest of the line because it is a comment.
Here is my second paragraph. Several spaces                                are translated as one. A large \% of users have experienced an issue when displaying a percent sign.

%The * uses an alternate version of the command, where this one suppresses the numbering.
\section*{This section has no number}

%The indentation is not necessary. It just shows visibly what belongs to the environment.
\begin{theorem}
   This is my first theorem.
\end{theorem}

\begin{lemma}
   This is my first lemma.
\end{lemma}

%Environments can have optional and required arguments and alternate versions * too
\noindent\begin{tabular}[t]{lcr}

  %Commands can have multiple {} containing required or [] containing optional arguments
   \multicolumn{3}{c}{\bfseries Identity}\\

  %bfseries is the declaration version for boldface. It is useful when creating a table because this declaration will be scoped to the cell.
   \multicolumn{3}{c}{\bfseries Matrix}\\
   1&0&0\\
   0&1&0\\
   0&0&1
\end{tabular}

\end{document}