6.2 LaTeX Basics - Part 1
6.2 LaTeX Basics - Part 1
Software Tools
[NCSC101]
Slides 6.2
LaTeX Basics – Part 1
S AURA BH SRIVAS TAVA
A SS IS TANT PRO FESSOR
DE PARTME N T OF COMPU TE R S CIE N CE & E NG IN EE RIN G
IIT ( IS M) DHA NBA D
Last Time …
We discussed the distinction between Structured and Unstructured Documents
◦ For example, we discussed typical Word documents, as examples of Unstructured Documents …
◦ … and documents such as e-books, as examples of Structured documents
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Formatting Text in LaTeX
LaTeX provides simple commands to format text
Bold Text: Use \textbf{} to highlight important content
◦ Example: Meet the \textbf{Explorer}, who is bold and daring.
◦ Output: Meet the Explorer, who is bold and daring.
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Creating Ordered and Unordered Lists (1/2)
To create a list, you will need to put the content within a block
◦ Such blocks usually start with a \begin{} command and end with a \end{}
Ordered Lists use the enumerate environment to display items in a numbered sequence
◦ Ordered lists use a numbering system (e.g., 1-2-3 or a-b-c)
◦ Individual items in the list start with the \item command
◦ Example:
LaTeX code Output
\begin{enumerate} 1. A sturdy backpack
\item A sturdy backpack 2. A water bottle
\item A water bottle 3. A map and compass
\item A map and compass
4. A flashlight with extra batteries
\item A flashlight with extra batteries
\end{enumerate}
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Creating Ordered and Unordered Lists (2/2)
To create a list, you will need to put the content within a block
◦ Such blocks usually start with a \begin{} command and end with a \end{}
Unordered Lists use the itemize environment to display items with bullet points
◦ Unordered lists use different types of bullet symbols (e.g., □ or ⦿)
◦ Individual items in the list start with the \item command
◦ Example:
LaTeX code Output
\begin{itemize} o A fire pit for cooking
\item A fire pit for cooking o A tent and sleeping bag
\item A tent and sleeping bag o Snacks to share with the new friends
\item Snacks to share with the new friends
\end{itemize}
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Organisation with Chapters and Sections
LaTeX provides chapter and section commands to structure documents
A Chapter can be used to divide a document into large, meaningful parts
◦ You can start a new Chapter using the \chapter{} command
◦ Example: \chapter{The Beginning of the Journey}
◦ There is no “explicit” end defined for a Chapter – it ends when the next Chapter starts or the document ends
A Section can be used to divide the content of a Chapter into smaller parts
◦ You can start a new Section using the \section{} command
◦ Example: \section{The First Obstacle}
◦ Similar to chapters, sections also do not have any explicit endings
Usually, you should put a label for every Chapter or Section that you add in the document
◦ Labels are unique identifiers, which can be used for cross-referencing (we will see that in a short while)
◦ They can be added using the \label{} command – we will see an example next
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Referencing Sections and Chapters
Cross-referencing allows you to link sections and chapters easily
◦ However, to be able to create references, you need to assign the label to the section or chapter
◦ Example: \section{The First Obstacle} \label{sec:obstacle}
◦ Here, we create a label for the section titled The First Obstacle
◦ By convention, it is a good idea to prefix the type of the content, for which label is being created
◦ For instance, here, the label starts with “sec:”
To refer to a label (be it for a Chapter or a Section), you can use the \ref{} command
◦ Example: He remembers the **first obstacle** he faced on the trail (see Section \ref{sec:obstacle}).
◦ In the generated document you will see something like:
He remembers the **first obstacle** he faced on the trail (see Section 1.3).
◦ Here, 1.3 is the Section Number associated with the section titled The First Obstacle
◦ The actual Section Number allotted to the section is dynamically decided during the compilation
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Hyperlinks and Table of Contents
Before we move further, it is essential to know the concept of Preamble of a LaTeX document
◦ Preamble is the part of the LaTeX code, before the \begin{document} statement
◦ You can do things like adding a title to the document, or import packages in your document
◦ A LaTeX package can be considered as a collection of custom commands which you can use for your purpose
◦ You can import a package in your code, using the \usepackage{} command in the Preamble
LaTeX can also, automatically generate the Table of Contents (ToC) for you
◦ All you need is the \tableofcontents command – put it wherever you want the ToC to appear
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
A Complete Example (1/2)
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
A Complete Example – A short book (1/2)
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
A Complete Example – A short book (2/2)
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (1/4)
This is the Title page of our book
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (2/4)
This is the Table of Contents of our
book, generated automatically
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (3/4)
This is the first chapter of our book
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (4/4)
This is the second chapter of our book
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (4/4)
This is the second chapter of our book
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Homework !!
The problem with cross-referencing is that it requires more than one iterations to make it work
◦ Running pdflatex once, may not be enough to create the hyperlinks
◦ You may, thus, have to do it 2-3 times
◦ A solution to this is to install latexmk by the command:
sudo apt install latexmk
◦ After that, executing latexmk once is sufficient, e.g.,:
latexmk -pdf journey-through-forest.tex
The red/blue hyperlinks may be rather annoying if you had to actually read the book
◦ Try changing the line:
\usepackage{hyperref}
to
\usepackage[hidelinks]{hyperref}
and see if the problem is resolved !!
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD