LaTeX
  • How I learn LaTeX?
  • Installation and Customization
    • Online
    • Offline
  • LaTeX Basics
  • Text Manipulation
    • Fonts, Size and Styles
  • Math Manipulation
  • Advanced Math Manipulation
  • Lists
  • Tables
  • Pictures, Figures
  • Unit in LaTeX
  • Document Structure
  • Document Formatting
    • Headers and Footers, Page Numbering
    • Spacing in Paragraphs
    • Page size, Margins
    • Coloring
    • Footnotes
  • Multi-file LaTeX project
Powered by GitBook
On this page

LaTeX Basics

Since the main usage of LaTeX is creating documents, let's learn how to create a basic document!

PreviousOfflineNextText Manipulation

Last updated 1 year ago

In order to start working with LaTeX\LaTeXLATE​X, you need to create a project on Overleaf, or a file ending with .tex on your local machine. I'll be more focusing on Overleaf since it's easier to use.

Here is a very sample piece of LaTeX\LaTeXLATE​Xcode:

\documentclass{article}
\begin{document}
Finally. I can get rid of Word and start "developing" documents!
\end{document}

The output:

First, we have \documentclass{article}. This line will declare the document type, known as its class, which controls the overall appearance of the document. There are many different types, each of them will have different settings to the layout, as well as have their own set of commands.

After that, we have the main content of the document, surrounded by the pair \begin{document} and \end{document}. You can change the content inside, which will be reflected after re-compiling the document.

Overall, there are 2 main parts in a LaTeX\LaTeXLATE​Xdocument: preamble and main document.

Everything in your .tex file that appearing before that \begin{document} is called the preamble, which acts as the document’s “setup” section. Within the preamble you define the document class (type) together with configuration such as languages to be used when writing the document; loading packages you would like to use (which will be talked later), and it is where you would apply other types of configuration.

Moreover, you can define information that are related to the document (author, title, date of publishing, institution..). With that knowledge in mind, let's make a descriptive preamble.

\documentclass[a4paper]{article}
\usepackage[utf8]{vietnam}
\usepackage{fancyhdr}
\title{Tài liệu \LaTeX\ đầu tiên của tôi}
\author{teebow1e}
\date{\today}

\begin{document}
\maketitle
Xin chào Gitbook. Tôi đã học \LaTeX\ như thế nào?
\end{document}

Let's analyze this preamble:

  • \documentclass[a4paper]{article} - declares a paper with the size A4 (there are many different sizes)

  • \usepackage[utf8]{vietnam} - usepackage is the keyword to import a library to the document, here I am importing a library that supports Vietnamese language. (by default LaTeX\LaTeXLATE​Xdoesn't support Vietnamese)

  • \usepackage{fancyhdr} - another imported library, this one's responsible for creating headers/footers for the document.

  • \title{} - the text inside the curly brackets will be the title of the page, same applied to \author and \date

  • \maketitle - create a beautiful title for your paper.

The result will be: