Latex Practicals
Latex Practicals
• Practical 1:
Question: Hello World!
Create a document with the title Hello World! your name, and today’s date. Include
in the document the following text "Hello World! Today I am learning LaTeX." The solution
should look like this (but with today’s date):
Hints:
• Remember the first part of any document is the preamble and it must begin
with \documentclass{} an article is a good document class for this exercise.
• To make the title look nice use the command \maketitle, but make sure you put it in
the body of the document
• For \maketitle to work correctly you will want to use \title{}, \author{}, and \date{},
but they don't belong in the document body.
• What happens if you don't include \date{}? What happens if you use \date{} with no
argument? What if you use \date{\today}?
• To start the body of your document use the command \begin{document}. To end
your document use the command \end{document}
• Try the command \LaTeX
Solution:
\documentclass{article}
\title{HelloWorld!}
\author{YourName}
\date{January 1, 1831}
\begin{document}
\maketitle
\textbf{Hello World!} Today I am learning \LaTeX.
\end{document}
• Practical 2:
Question: Adding some simple math
Add to the document you created in exercise 1 the following text:
"LaTeX is a great program for writing math. I can write in line math such as a^2 + b^2 = c^2. I
can also give equations their own space: gamma^2 +theta^2 = omega^2"
Your final document should look like this:
Hints:
• Is there a problem with the spacing after the second \LaTeX? Try using \LaTeX{} an
empty argument can improve spacing with some commands.
• To write in line math mode you need to include a $ before and after the text that
should be written as math.
• $$ before and after an equation or \[ and \] will cause LaTeX to entire a display
environment
• If you don't know how to create Greek letters check out the resources tab.
• Use ^ for superscripts. Use _ for subscripts.
Solution:
\documentclass{article}
\title{Hello World!}
\author{Your Name}
\date{January 1, 1831}
\begin{document}
\maketitle
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space: \[ \gamma^2+\theta^2=\omega^2\]
\end{document}
• Practical 3:
Question: More Difficult Math
In this exercise you will build onto the document created in exercises 1 and 2 with more
complicated math and structures. This is a much more difficult exercise so take your time.
First give the display environment equation from exercise 2 an equation number. Second
add the following line of text (make sure there it is not indented as a new paragraph:
"Maxwell's equations" are named for James Clark Maxwell and are as follow:
Now write Maxwell's equations (as seen below), use an align environment and align the
equations at the = signs and at the equations names.
Hints:
• Did you include the amsmath package command, \usepackage{amsmath}? Some
symbols and advanced math environments such as align will not work with out it!
• The equation environment, \begin{equation}, automatically puts you in display
mode and includes equations numbers. If you want to use this mode but don't want
equation numbers use equation*
• To create quotation marks in LaTeX use the symbol ` (the ~ key) twice on the left and
use the ' key twice on the right. Using " on the left and right will not work properly.
• In the align environment you use the & to denote points of alignment. If you want a
second alignment point use &&.
• If you are having trouble with spacing use around = use the command \quad this
adds extra horizontal space.
• When adding text in math mode you need to use the command \text{} where the text
you want added is the argument. This command tells LaTeX to use regular text at that
location.
• \vec{} will create vector notation. \partial will give you partial derivatives, and
remember for fractions use \frac{numerator}{denomonator}.
• If you are having trouble getting your parenthesis to look right use the
command \left( and \right) this will automatically fit the parenthesis to the equation
within. This also works with \left[, \left{, and \left|, but you always need a \right to
go with it.
Solution:
\documentclass{article}
\usepackage{amsmath}
\title{Hello World!}
\author{Your Name}
\date{January 1, 1831}
\begin{document}
\maketitle
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space:
\begin{equation}
\gamma^2+\theta^2=\omega^2
\end{equation}
``Maxwell's equations'' are named for James Clark Maxwell and are as follow:
\begin{align}
\vec{\nabla} \cdot \vec{E} \quad &=\quad\frac{\rho}{\epsilon_0} &&\text{Gauss's Law}
\\
\vec{\nabla} \cdot \vec{B} \quad &=\quad 0 &&\text{Gauss's Law for Magnetism}\\
\vec{\nabla} \times \vec{E} \quad &=\hspace{10pt}-\frac{\partial{\vec{B}}}{\partial{t}}
&&\text{Faraday's Law of Induction} \\
\vec{\nabla} \times \vec{B} \quad &=\quad \mu_0\left(
\epsilon_0\frac{\partial{\vec{E}}}{\partial{t}}+\vec{J}\right) &&\text{Ampere's Circuital Law}
\end{align}
\end{document}
• Practical 4:
Question: Creating Sections and Referencing Equation
Labels and reference are very simple to execute in LaTeX, can be used with any numbered
object such as figures, equations, and sections, and are automatically updated whenever
the document is complied. If, for example, you realized you forgot an equation somewhere
in the middle of your document, between 10 other equations, all the equations after the
newly inserted equation would automatically be renumbered and proper references to them
will reflect this new numbering!
For this exercise take the document made in the previous exercise and create two sections
one at the beginning (Getting Started) and one after all your texts (What about Matrix
Equations?). Also add to your document references to each of Maxwell's Equations, and
then write a sentence that references each equation. You will need to use the
commands \label{} and \ref{}.
It is common practice in LaTeX when labeling to use the
format eq:name, fig:name, tab:name, and so on depending on the type of object you are
labeling. If you are confused by this look at the labels in the solution
Also, if you would like your citations to act as hyperlinks you need to use the
package hyperref, \usepackage{hyperref}, remember with this package you can change
the default hyperlink settings with the command \hypersetup{} in the preamble
i.e. \hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}.
Hints:
\begin{document}
\maketitle
\section{Getting Started}
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space:
\begin{equation}
\gamma^2+\theta^2=\omega^2
\end{equation}
``Maxwell's equations'' are named for James Clark Maxwell and are as follow:
\begin{align}
\vec{\nabla} \cdot \vec{E} \quad &=\quad\frac{\rho}{\epsilon_0} &&\text{Gauss's
Law} \label{eq:GL}\\
\vec{\nabla} \cdot \vec{B} \quad &=\quad 0 &&\text{Gauss's Law for
Magnetism} \label{eq:GLM}\\
\vec{\nabla} \times \vec{E} \quad &=\hspace{10pt}-\frac{\partial{\vec{B}}}{\partial{t}}
&&\text{Faraday's Law of Induction} \label{eq:FL}\\
\vec{\nabla} \times \vec{B} \quad &=\quad \mu_0\left(
\epsilon_0\frac{\partial{\vec{E}}}{\partial{t}}+\vec{J}\right) &&\text{Ampere's Circuital
Law} \label{eq:ACL}
\end{align}
Equations \ref{eq:GL}, \ref{eq:GLM}, \ref{eq:FL}, and \ref{eq:ACL} are some of the most
important in Physics.
\section{What about Matrix Equations?}
\end{document}
Practical 5:
Question: Creating Matrix Equations
In this exercise add the matrix equation to your document as seen below:
Hints:
Solution:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}
\title{Hello World!}
\author{Your Name}
\date{January 1, 1831}
\begin{document}
\maketitle
\section{Getting Started}
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space:
\begin{equation}
\gamma^2+\theta^2=\omega^2
\end{equation}
``Maxwell's equations'' are named for James Clark Maxwell and are as follow:
\begin{align}
\vec{\nabla} \cdot \vec{E} \quad &=\quad\frac{\rho}{\epsilon_0} &&\text{Gauss's Law}
\label{eq:GL}\\
\vec{\nabla} \cdot \vec{B} \quad &=\quad 0 &&\text{Gauss's Law for Magnetism}
\label{eq:GLM}\\
\vec{\nabla} \times \vec{E} \quad &=\hspace{10pt}-\frac{\partial{\vec{B}}}{\partial{t}}
&&\text{Faraday's Law of Induction} \label{eq:FL}\\
\vec{\nabla} \times \vec{B} \quad &=\quad \mu_0\left(
\epsilon_0\frac{\partial{\vec{E}}}{\partial{t}}+\vec{J}\right) &&\text{Ampere's Circuital Law}
\label{eq:ACL}
\end{align}
Equations \ref{eq:GL}, \ref{eq:GLM}, \ref{eq:FL}, and \ref{eq:ACL} are some of the most
important in Physics.
\section{What about Matrix Equations?}
\begin{equation*}
\begin{pmatrix}
a_{11}&a_{12}&\dots&a_{1n}\\
a_{21}&a_{22}&\dots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{n1}&a_{n2}&\dots&a_{nn}
\end{pmatrix}
\begin{bmatrix}
v_{1}\\
v_{2}\\
\vdots\\
v_{n}
\end{bmatrix}
=
\begin{matrix}
w_{1}\\
w_{2}\\
\vdots\\
w_{n}
\end{matrix}
\end{equation*}
\end{document}
Practical 6:
Question: Tables and Figures
For this exercise create a new section to your document for figures and tables. In that
section create a table and a figure. Give each object a caption, try putting the table caption
above the table and the figure caption below. Try this with a figure of your choice.
Hints:
• To include a caption with your table use the environment table, \begin{table}.
• To create the table itself you need to use the environment tabular, \begin{tabular}{}.
o In the second argument of tabular you will define the number of columns in
the table, the justification of each column, as well as if you would like any lines
between the columns. In the table used in this question the
command \begin{tabular}{|l||c|c|r|} was used. This creates a 4 column
matrix, the first column is left justified, l, the middle two are center justified, c,
and the last column is right justified, r. The table also has borders on the
outside as well as between the columns using the | (shift
backslash key). Notice there is a double || after the first column.
• Entering values into your table works much like a matrix. use the & character to
separate columns and the \\ command to start working on a new row. Use $ if you
want to write in math mode.
• If you want to create a horizontal line at the top, bottom, or between rows of your
table use the command \hline at the start of the row and after the last \\.
• Placing the command \centering at the start of the table of figure environment will
center the object.
• For figures you need to include the graphicx package, \usepackage{graphicx}.
• Using the graphicx package you can create an environment figure, \begin{figure}.
• To insert your figure use the command \includegraphics[]{}.
o The optional argument of \includegraphics can be used to resize the figure
try [width=\textwidth] and [width=.5\textwidth] and see the difference it
makes.
o The required argument of \includegraphics is the name of the file, DO
NOT include the file type and make sure the file is located in the same
folder as the LaTeX document otherwise it is more complicated to include it.
For example the argument for file bern.jpg should just
be \includegraphics{bern}.
• When including a floating object in your document such as a figure or a table you can
follow the required argument with an additional optional argument to indicate the
preferred placement of the object. The letter h indicates here (current
location), b indicates bottom (bottom of a page), and t indicated top (top of
page). Using an ! stresses to LaTeX to make this placement. So you may see
commands for figures of tables that look like this \begin{figure}[hbt!].
Solution:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}
\usepackage{graphicx}
\title{Hello World!}
\author{Your Name}
\date{January 1, 1831}
\begin{document}
\maketitle
\section{Getting Started}
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space:
\begin{equation}
\gamma^2+\theta^2=\omega^2
\end{equation}
``Maxwell's equations'' are named for James Clark Maxwell and are as follow:
\begin{align}
\vec{\nabla} \cdot \vec{E} \quad &=\quad\frac{\rho}{\epsilon_0} &&\text{Gauss's Law}
\label{eq:GL}\\
\vec{\nabla} \cdot \vec{B} \quad &=\quad 0 &&\text{Gauss's Law for Magnetism}
\label{eq:GLM}\\
\vec{\nabla} \times \vec{E} \quad &=\hspace{10pt}-\frac{\partial{\vec{B}}}{\partial{t}}
&&\text{Faraday's Law of Induction} \label{eq:FL}\\
\vec{\nabla} \times \vec{B} \quad &=\quad \mu_0\left(
\epsilon_0\frac{\partial{\vec{E}}}{\partial{t}}+\vec{J}\right) &&\text{Ampere's Circuital Law}
\label{eq:ACL}
\end{align}
Equations \ref{eq:GL}, \ref{eq:GLM}, \ref{eq:FL}, and \ref{eq:ACL} are some of the most
important in Physics.
\section{What about Matrix Equations?}
\begin{equation*}
\begin{pmatrix}
a_{11}&a_{12}&\dots&a_{1n}\\
a_{21}&a_{22}&\dots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{n1}&a_{n2}&\dots&a_{nn}
\end{pmatrix}
\begin{bmatrix}
v_{1}\\
v_{2}\\
\vdots\\
v_{n}
\end{bmatrix}
=
\begin{matrix}
w_{1}\\
w_{2}\\
\vdots\\
w_{n}
\end{matrix}
\end{equation*}
\section{Tables and Figures}
Creating a Table is not unlike creating a matrix:
\begin{table}[hbt!]
\centering
\caption{This is a table that shows how to create different lines as well as different
justifications}
\begin{tabular}{|l||c|c|r|}
\hline
$x$&1&2&3\\
\hline
$f(x)$&4&8&12\\
f(x)&4&8&12\\
\hline
\end{tabular}
\end{table}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{bern}
\caption{Bern Dibner Library}
\end{figure}
\end{document}
• Practical 7:
Question: Bibliography
Before attempting this exercise make sure you have read through the BibTex tab of this
guide.
Create a BibTex file with a few citations in it. Add a sentence that contains these citations
and then add a bibliography to your document.
Hint:
• It is much easier to create a BibTex file using a citation management tool like Zotero
or Mendeley.
• Use the \cite{} command where the argument is bibID for the citation in the .bib file.
o If you are citing multiple items at the same location you can
use \cite{} command and separate the bibIDs with commas.
• Make sure use the command \bibliographystyle{} to tell LaTeX which bibliographic
style to use.
o Some common styles are plain, ieeetr, acm, and apalike.
• To create your bibliography use the command \biblography{} where the argument is
the name of the bib file. DO NOT include .bib and MAKE SURE the .bib file is located
in the same folder as the LaTeX document.
• You may need to compile your document twice in order to get cross references to
work correctly
Solution:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}
\usepackage{graphicx}
\title{Hello World!}
\author{Your Name}
\date{January 1, 1831}
\begin{document}
\maketitle
\section{Getting Started}
\textbf{Hello World!} Today I am learning \LaTeX. \LaTeX{} is a great program for writing
math. I can write in line math such as $a^2+b^2=c^2$. I can also give equations their own
space:
\begin{equation}
\gamma^2+\theta^2=\omega^2
\end{equation}
``Maxwell's equations'' are named for James Clark Maxwell and are as follow:
\begin{align}
\vec{\nabla} \cdot \vec{E} \quad &=\quad\frac{\rho}{\epsilon_0} &&\text{Gauss's Law}
\label{eq:GL}\\
\vec{\nabla} \cdot \vec{B} \quad &=\quad 0 &&\text{Gauss's Law for Magnetism}
\label{eq:GLM}\\
\vec{\nabla} \times \vec{E} \quad &=\hspace{10pt}-\frac{\partial{\vec{B}}}{\partial{t}}
&&\text{Faraday's Law of Induction} \label{eq:FL}\\
\vec{\nabla} \times \vec{B} \quad &=\quad \mu_0\left(
\epsilon_0\frac{\partial{\vec{E}}}{\partial{t}}+\vec{J}\right) &&\text{Ampere's Circuital Law}
\label{eq:ACL}
\end{align}
Equations \ref{eq:GL}, \ref{eq:GLM}, \ref{eq:FL}, and \ref{eq:ACL} are some of the most
important in Physics.
\section{What about Matrix Equations?}
\begin{equation*}
\begin{pmatrix}
a_{11}&a_{12}&\dots&a_{1n}\\
a_{21}&a_{22}&\dots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{n1}&a_{n2}&\dots&a_{nn}
\end{pmatrix}
\begin{bmatrix}
v_{1}\\
v_{2}\\
\vdots\\
v_{n}
\end{bmatrix}
=
\begin{matrix}
w_{1}\\
w_{2}\\
\vdots\\
w_{n}
\end{matrix}
\end{equation*}
\section{Tables and Figures}
Creating a Table is not unlike creating a matrix:
\begin{table}[h!]
\centering
\caption{This is a table that shows how to create different lines as well as different
justifications}
\begin{tabular}{|l||c|c|r|}
\hline
$x$&1&2&3\\
\hline
$f(x)$&4&8&12\\
f(x)&4&8&12\\
\hline
\end{tabular}
\end{table}
\begin{figure}[h!]
\centering
\includegraphics[width=\textwidth]{bern}
\caption{Bern Dibner Library}
\end{figure}
\section{Bibliography}
You will probably want references in your document so that you can cite articles like
\cite{frenkel_fine_2013, frenkel_optical_2013, frenkel_temperature_2012,
frenkel_whispering-gallery_2013,frenkel_-chip_2016}
\bibliographystyle{ieeetr}
\bibliography{bibl}
\end{document}
Practical 8:
Question:
(A) Trying creating the following calculus equation
Hint:
• To get the spacing right try using the command \, before dx on the left side of the
equation
• The command \limits helps position the integral limits where you want
them, \limits_a^b.
• To get the size of the line at the end of the equation try using the command \right|
o To use this equation without a command \left| creating lines on both sides of
the equation place the command \left. on the left side of the equation. This
technique can be used with any of the \right or \left commands if you only
want an object on one side of your equation.
Solution:
\[
\int\limits_a^b x\,dx = \left.\frac{x^2}{2} \right|_a^b
\]
(B) If you are feeling really good try your luck with these equations (no hints are given)
Solution:
\begin{equation}
\iiint\limits_V f(x,y,z)\,dV = F
\end{equation}
\begin{equation}
\frac{dx}{dy}=x'=\lim_{h \to 0}\frac{f(x+h)-f(x)}{h}
\end{equation}
\begin{equation}
|x|=\begin{cases}
-x, & \text{if $x < 0$}\\
x, & \text{if $x \geq 0$}
\end{cases}
\end{equation}
\begin{equation}
F(x)= A_0 + \sum_{n=1}^N\left[ A_n\cos{\left(\frac{2\pi nx}{P}\right)}+B_n\sin{\left(\frac{2\pi
nx}{P}\right)}\right]
\end{equation}
\begin{equation}
\sum_n \frac{1}{n^s}=\prod_p \frac{1}{1-\frac{1}{p^s}}
\end{equation}
\begin{align*}
f(x)\quad &=\quad x^2 + 3x + 5x^2 +8 +6x\\
&=\quad 6x^2 +9x +8\\
&=\quad x(6x+9)+8
\end{align*}
$$
X=\frac{F_0}{k}\frac{1}{\sqrt{(1-r^2)^2+(2\zeta r)^2}}
$$
\begin{equation}
G_{\mu\nu} \equiv R_{\mu\nu}-\frac{1}{2}Rg_{\mu\nu}=\frac{8\pi G}{c^4}T_{\mu\nu}
\end{equation}\\
$$\mathrm{6CO_2+6H_2O \to C_6H_{12}O_6+6O_2}$$
$$\mathrm{SO_4^{2-}+Ba^{2+} \to BaSO_4 }$$
\begin{equation}
\begin{pmatrix}
a_{11}&a_{12}&\dots&a_{1n}\\
a_{21}&a_{22}&\dots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{n1}&a_{n2}&\dots&a_{nn}
\end{pmatrix}
\begin{pmatrix}
v_{1}\\
v_{2}\\
\vdots\\
v_{n}
\end{pmatrix}
=
\begin{pmatrix}
w_{1}\\
w_{2}\\
\vdots\\
w_{n}
\end{pmatrix}
\end{equation}
\begin{equation}
\frac{\partial{\bf{u}}}{\partial{t}}+(\bf{u}\cdot\nabla)\bf{u}-\nu\nabla^2\bf(u)=-\nabla h
\end{equation}
\[ % This is preferred to the $$ environment
\alpha A \beta B \gamma \Gamma \delta \Delta \pi \Pi \omega \Omega
\]