6.1 Introduction To LaTeX

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Introduction to Unix and

Software Tools
[NCSC101]
Slides 6.1
Introduction to LaTeX
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
Document Processors
One of the most common Document Processing tools in Microsoft Word
◦ Yes, I know I have been a critic of Windows all this while, but it is true that Word is quite popular :D
◦ Probably one of main the reason Word is popular is the ability to create a wide range of documents
◦ The documents can have headings, regular text, images as well as tables

However, have you ever faced one of the most annoying aspect of Word?
◦ Change the margins slightly, move an image by a small increment, and the whole document becomes ugly !!

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Just a few examples of
what you get if you
Google “word
formatting meme”
:D
SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Document Processors
One of the most common Document Processing tools in Microsoft Word
◦ Yes, I know I have been a critic of Windows all this while, but it is true that Word is quite popular :D
◦ Probably one of main the reason Word is popular is the ability to create a wide range of documents
◦ The documents can have headings, regular text, images as well as tables

However, have you ever faced one of the most annoying aspect of Word?
◦ Change the margins slightly, move an image by a small increment, and the whole document becomes ugly !!

There is another problem when you use Word, to write something like a Book
◦ A book is usually “structured” – there is a Title Page, followed by a Preface, a Table of Contents, …
◦ … followed by some chapters, and may be ending with Appendices, Indices, etc.
◦ While you can certainly write it in Word, creating a hyperlinked, structured PDF out of it, is not straightforward

The core issue is that Word is not primarily meant to produce Structured Documents
◦ In fact, it is also not its primary objective to produce highly formatted texts either !!

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Structured Documents to the Rescue
Most Document processors can be called What You See Is What You Get (WYSIWYG) Editors
◦ It means you can type and style text in a flow, and see what you get

Structured documents separate content from presentation


◦ The content of such documents is written in plaintext (similar to the C/C++ code files)
◦ Formatting happens automatically based on the document’s metadata
◦ This metadata can be considered as a template (e.g., the “book” template will differ from the “article” template)
◦ Such documents can be usually converted to a PDF version directly (e.g., the “e-books”)

A well-structured, well-formatted Document, might require additional efforts to produce


◦ Usually, it involves following a strict discipline, defining a lot of format settings and writing code (phew… )
◦ Reports/Articles, Books and Research Papers are some common examples of Structured Documents

We will now have a look at LaTeX – a platform used to create highly formatted, structured documents
◦ By the way, I am not developing any cognitive problems, this is how we usually write it – LaTeX :D

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
What is LaTeX?
LaTeX is a document preparation system focused on high-quality “typesetting”
◦ Typesetting refers to the process of precisely deciding upon the formatting details of any part of the document

Unlike common document processors, LaTeX uses commands to describe content


◦ Most commands in LaTeX follow the following pattern:
\<command>{<content>}
◦ For instance, the title of a document is provided as:
\title{My Document}

LaTeX is particularly useful when you building structured documents that contain ample amounts of
◦ Mathematical equations
◦ Tables, Charts and Images
◦ References and Citations

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Basic LaTeX Workflow
You may find the experience of creating documents significantly different from that using Word
◦ In fact, the experience with LaTeX may be closer to what you experience during programming !!

A basic LaTeX workflow can be explained as follows:


1. Write your content in a .tex file using plaintext and LaTeX commands
2. Compile the .tex file with a LaTeX engine to generate a PDF
3. View the PDF to analyse the text formatting, if required, change the .tex file and repeat the process

As mentioned before, this flow is very similar to how programs are written, debugged and executed
◦ On Linux/Mac environments, you can download and install Tex Live as the LaTeX engine
◦ A minimal version of the same on Ubuntu can be installed using the command:
sudo apt install texlive –y
◦ The full version (which may take up several GBs of space) can be installed using the command:
sudo apt install texlive-full –y
◦ On Windows, there is an option too – MiKTeX (we will not cover that though, in the lecture)

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
The Hello World Document
I bet the term “Hello World Document” itself is quite weird to hear the first time
◦ But let us write LaTeX code to produce the document

Use any text editor (like vi) to create a .tex file containing the following lines of LaTeX code:
1. \documentclass{article}
2. \title{Hello LaTeX}
3. \author{Your Name}
4. \date{\today}
5. \begin{document}
6. \maketitle
7. Hello, LaTeX World!
8. \end{document}

You can now, compile the code with the simple command: pdflatex <file name>
◦ If everything goes well, the final output of the command will be a PDF file

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Notice how this
looks very similar
to a program …

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
… and this looks
similar to the
output of a
compilation
process !!

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
We have the
document
produced by
running the
command –
hello.pdf
(plus some other
files)

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Notice that the
Date has
appeared in the
document, even
though we did
not provide it (it
is, in fact, the
system date)

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Knowing the Hello World Document
Line# Code Explanation
1 \documentclass{article} Specifies the document class as 'article'. This defines the structure
and formatting rules for the document.
2 \title{My First LaTeX Document} Sets the title of the document to 'My First LaTeX Document'.
3 \author{Your Name} Defines the author of the document. Replace Your Name with your
name.
4 \date{\today} Adds the current date to the document. The \today command
automatically inserts today’s date.
5 \begin{document} Marks the beginning of the content that will appear in the output PDF.
6 \maketitle Generates the title, author, and date as defined earlier in the
document.
7 Hello, LaTeX World! This is the main body of the document, containing the text 'Hello,
LaTeX World!'.
8 \end{document} Marks the end of the document. LaTeX will ignore any content written
after this line.

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD
Homework !!
Install Tex Live (or MiKTeX) on your machines (or Virtual Machines)

SAURABH SRIVASTAVA | DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING | IIT (ISM) DHANBAD

You might also like