0% found this document useful (0 votes)
12 views

6.2 LaTeX Basics - Part 1

Uploaded by

shubhomoy365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

6.2 LaTeX Basics - Part 1

Uploaded by

shubhomoy365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction to Unix and

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

We also had a brief look at some LaTeX code


◦ It wasn’t much, but you saw the process – including writing the “LaTeX code” and compiling it

We will see some more LaTeX code today


◦ For instance, we will start with basic text editing (like making the text bold, italicised or underlined) …
◦ … and creating ordered and unordered lists
◦ We will then see how content can be placed under chapters and sections, and how they can be cross-referenced

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.

Italics Text: Use \textit{} to emphasize words or represent dialogue


◦ Example: He keeps reminding himself, \textit{"Courage is not the absence of fear, but the triumph over it."}
◦ Output: He keeps reminding himself, "Courage is not the absence of fear, but the triumph over it.”

Underlined Text: Use \underline{} to underline specific content


◦ Example: He takes a deep breath and recalls the mantra \underline{"Patience is the key"}.
◦ Output: He takes a deep breath and recalls the mantra "Patience is the key".

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

To add hyperlinks in a document, LaTeX provides the hyperref package


◦ For example, to use the hyperref package, you should write: \usepackage{hyperref}
◦ After doing so, you can add a hyperlink in the document using \href{<url>}{<text>} command
◦ For example: Written with Assistance from \href{https://chat.openai.com}{ChatGPT}
◦ It generates a hyperlink to the URL https://chat.openai.com showing the text ChatGPT

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

This text with red rectangles, are


actually hyperlinks (for example,
you can go to a particular Section
or Chapter by clicking on these
hyperlinks)

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Generated PDF (3/4)
This is the first chapter of our book

You can see the bold, italicised and


underlined text

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

Notice that there is a hyperlink to a


part of the same Document

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

You might also like