Skip to main content
Every LaTeX document begins with \documentclass{...} and puts the text between \begin{document} and \end{document}. Save the four lines below as a .tex file, compile it, and you have a one-page PDF.

1. Write the minimal document

hello-world.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
  • \documentclass{article} picks the layout. article suits papers and short reports; report and book add chapters, and beamer makes slides.
  • \begin{document} and \end{document} enclose everything that is printed. LaTeX ignores anything after \end{document}.
  • The page number at the bottom comes from the article class.

2. Add a title and sections

Everything between \documentclass and \begin{document} is the preamble: settings and document information, but no printed text. Set the title, author and date there, then print them with \maketitle in the body. \section{...} adds a numbered heading.
title-sections.tex
Three rules from this example:
  • Paragraphs: a blank line starts a new paragraph. A single line break in the source is treated like a space.
  • Comments: % hides the rest of the line. To print a percent sign, write \%.
  • Page size: the geometry and \pagestyle{empty} lines only make the preview compact. Leave them out to get a normal page with page numbers.
\date{\today} prints the date of the compile. More heading levels and numbering options are on Sections and chapters.

3. Add math and a package

Inline math goes between $...$. The equation environment centers a numbered equation on its own line. Packages add features: \usepackage{amsmath} in the preamble provides \text and other math tools.
first-article.tex
To add an image, load graphicx the same way and see inserting images. Package management explains package options and loading order.

4. Compile and fix errors

Compiling turns main.tex into main.pdf. With a local TeX installation, run pdflatex main.tex; pdfLaTeX is the usual default, and Choosing a compiler explains when to use XeLaTeX or LuaLaTeX instead. Run it a second time when the document has a table of contents or cross-references. If the compile stops, read the first error in the log: the number after l. is the line to look at. The most common beginner errors are text in the preamble (Missing \begin{document}), a missing }, and _ or ^ outside math (Missing $ inserted). Common LaTeX errors explains each message. A larger project keeps main.tex in a folder with its images and bibliography files; Your first LaTeX project shows that layout.

Next steps

To write your own document without installing TeX, start from the Basic Article template in LaTeX Cloud Studio.