pdflatex
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| pdflatex [February 16, 2026 at 00:54] – yanevskiv | pdflatex [May 14, 2026 at 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # pdflatex | ||
| + | **pdflatex** is the most common [[latex|LaTeX]] compiler. | ||
| + | You compile latex source code by running `pdflatex main.tex`. This creates a PDF file `main.pdf`. It also creates a log file `main.log` and an auxiliary file `main.aux` used to build references. You can ignore these latter two and `rm -f *.aux *.log`. | ||
| + | |||
| + | The following is a minimal latex source code you can use to try it out. | ||
| + | ```latex | ||
| + | % Compile: pdflatex main.tex | ||
| + | % View: xdg-view main.pdf | ||
| + | \documentclass{article} | ||
| + | \begin{document} | ||
| + | Hello world | ||
| + | \end{document} | ||
| + | ``` | ||
| + | |||
| + | ## Install | ||
| + | On Debian GNU/Linux, you install latex by installing `texlive-latex-*` packages. At a minimum, you should install `texlive-latex-base` and `texlive-latex-extra`. If you want everything, you can install `texlive-full`. | ||
| + | ``` | ||
| + | $ apt install texlive-latex-base texlive-latex-extra | ||
| + | ``` | ||
| + | |||
| + | This will give you the `pdflatex` compiler + a myriad of useful packages. To give it a test, create a file `main.tex` with the following content, | ||
| + | ```latex | ||
| + | \documentclass[a4paper]{article} | ||
| + | \usepackage{lipsum} | ||
| + | \begin{document} | ||
| + | \section{Introduction} | ||
| + | \lipsum[1-5] | ||
| + | \end{document} | ||
| + | ``` | ||
| + | Compile the document with `pdflatex main.tex`. You should see something of the following: | ||
| + | ``` | ||
| + | $ pdflatex main.tex | ||
| + | This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2025/ | ||
| + | | ||
| + | entering extended mode | ||
| + | (./main.tex | ||
| + | LaTeX2e < | ||
| + | L3 programming layer < | ||
| + | (/ | ||
| + | Document Class: article 2024/06/29 v1.4n Standard LaTeX document class | ||
| + | (/ | ||
| + | (/ | ||
| + | (/ | ||
| + | (/ | ||
| + | (/ | ||
| + | (/ | ||
| + | |||
| + | Package lipsum Warning: Unknown language ' | ||
| + | (lipsum) | ||
| + | |||
| + | |||
| + | [1{/ | ||
| + | [2] (./ | ||
| + | / | ||
| + | .pfb> | ||
| + | Output written on main.pdf (2 pages, 34145 bytes). | ||
| + | Transcript written on main.log. | ||
| + | ``` | ||
| + | When you list files with `ls` you should see 4 files | ||
| + | ``` | ||
| + | $ ls | ||
| + | main.aux main.log main.pdf main.tex | ||
| + | ``` | ||
| + | |||
| + | - `main.tex` - This file contains your latex source code | ||
| + | - `main.log` - This file is contains more detailed logs than terminal output | ||
| + | - `main.aux` - This file is an " | ||
| + | - `main.pdf` - This is the resulting PDF document | ||
| + | |||
| + | At this point, you can safely ignore the `*.log` and `*.aux` files. | ||
| + | |||
| + | The resulting PDF contains 2 pages of random latin text. This text is [Lorem ipsum](https:// | ||
| + | |||
| + | ## Syntax error | ||
| + | When you make a syntax error, `pdflatex` shows you the error, but also expects you to fix the document interactively. | ||
| + | |||
| + | As an example, the following is a document that doesn' | ||
| + | ```latex | ||
| + | \documentclass{article} | ||
| + | \begin{document} | ||
| + | Hello \textbf{World... oh no! Dropped a closing brace | ||
| + | \end{document} | ||
| + | ``` | ||
| + | When you run `pdflatex main.tex` | ||
| + | ``` | ||
| + | $ pdflatex main.tex | ||
| + | This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2025/ | ||
| + | | ||
| + | entering extended mode | ||
| + | (./main.tex | ||
| + | LaTeX2e < | ||
| + | L3 programming layer < | ||
| + | (/ | ||
| + | Document Class: article 2024/06/29 v1.4n Standard LaTeX document class | ||
| + | (/ | ||
| + | (/ | ||
| + | (./ | ||
| + | Runaway argument? | ||
| + | {World.. oh no! Dropped a closing brace \end {document} | ||
| + | ! File ended while scanning use of \textbf . | ||
| + | < | ||
| + | \par | ||
| + | <*> main.tex | ||
| + | |||
| + | ? | ||
| + | ``` | ||
| + | At this point, `pdflatex` doesn' | ||
| + | |||
| + | The interactive mode is annoying and you can disable it with `-interaction=nonstopmode` option. | ||
| + | ``` | ||
| + | $ pdflatex -interaction=nonstopmode main.tex | ||
| + | ``` | ||
| + | |||
| + | ## Less output noise (texfot) | ||
| + | As you might have noticed `pdflatex` is extremely noisy. Most of its output is gibberish you probably don't care about. So a tool was created called `texfot` to cull the `pdflatex` clutter. | ||
| + | |||
| + | First, you have to install a package that provides it: | ||
| + | ``` | ||
| + | apt install texlive-extra-utils | ||
| + | ``` | ||
| + | Then you use it like so: | ||
| + | ``` | ||
| + | texfot pdflatex main.tex | ||
| + | ``` | ||
| + | |||
| + | ## Makefile | ||
| + | The following is a Makefile that compiles `main.tex` to `build/ | ||
| + | |||
| + | ```make | ||
| + | # Configuration | ||
| + | TARGET | ||
| + | SOURCE | ||
| + | OUTPUT | ||
| + | LATEX := pdflatex | ||
| + | LATEX_FLAGS := -interaction=nonstopmode -halt-on-error -file-line-error | ||
| + | BUILD_DIR | ||
| + | |||
| + | # Derived paths | ||
| + | BUILD_PDF | ||
| + | BUILD_TEX | ||
| + | |||
| + | # Phony targets | ||
| + | .PHONY: all clean view vars | ||
| + | |||
| + | # Default target | ||
| + | all: $(BUILD_PDF) | ||
| + | |||
| + | # Build rules | ||
| + | $(BUILD_DIR): | ||
| + | mkdir -p $(BUILD_DIR) | ||
| + | |||
| + | $(BUILD_TEX): | ||
| + | cp $(SOURCE) $(BUILD_TEX) | ||
| + | |||
| + | $(BUILD_PDF): | ||
| + | cd $(BUILD_DIR) && $(LATEX) $(LATEX_FLAGS) $(SOURCE) | ||
| + | cd $(BUILD_DIR) && $(LATEX) $(LATEX_FLAGS) $(SOURCE) | ||
| + | |||
| + | # Utility targets | ||
| + | clean: | ||
| + | rm -rf $(BUILD_DIR) | ||
| + | |||
| + | view: $(BUILD_PDF) | ||
| + | xdg-open $(BUILD_PDF) >/ | ||
| + | |||
| + | vars: | ||
| + | @echo " | ||
| + | @echo " | ||
| + | @echo " | ||
| + | @echo " | ||
| + | ``` | ||
| + | |||
| + | Usage: | ||
| + | |||
| + | - `make` to compile `main.tex` to `build/ | ||
| + | - `make clean` to remove the `build/` directory | ||
| + | - `make view` to open the PDF with default `application/ | ||
| + | - `make vars` to see the Makefile variables | ||
