Choosing a LaTeX Compiler
The styles, contents and layout in a LaTeX document are defined by means of tags or commands in a plain .tex file, this file can be used to generate several types of "human-readable" versions of the document. The easiest way to generate this final output is to use Overleaf. Overleaf has a ready-to-use LaTeX distribution and final documents can be generated by simply clicking the "Recompile" button; if this is your case you can skip this article. Otherwise, if you need to learn how to compile documents in your computer, this article describes how to generate PS, DVI and PDF output from a LaTeX file.
LaTeX documents are plain documents with a .tex extension (see the Creating a document in LaTeX article for examples), this plain text file has some markup commands that are meant to format the document but, how do you actually generate the final output?. It depends on the type of document you want to generate.
Suppose you saved your document and named the file "mydocument.tex". To create a .PDF file just run this command in the system terminal.
And a file named "mydocument.pdf" will appear.
The set of programs that make possible to compile TeX and LaTeX documents is called a TeX typesetting or a TeX distribution. There are many TeX distributions available for different operating systems:
- MiKTeX for Windows
- TeX Live for Linux and other UNIX-like systems
- MacTeX redistribution of TeX Live for macOS
- teTeX for Linux and other UNIX-like systems; it is no longer actively maintained now
- proTeXt is based on MiKTeX
Of course, if you don't want to go through the process of installing a TeX distribution, you can use an on-line ready to use option like Overleaf.
There are many advanced text editors specifically dedicated to LaTeX for the most popular operating systems, some of them can be downloaded for free while others are proprietary software:
- Open source: AUCTEX, GNU TeXmacs, Gummi, Kile, LaTeXila, MeWa, TeXShop, TeXnicCenter, Texmaker, TeXstudio, TeXworks
- Freeware: LEd, WinShell
- Proprietary/Shareware: Inlage, Scientific WorkPlace, WinEdt
There are also general-purpose editors that add LaTeX-friendly options by means of plugins. For example the well known editors emacs and vim have both a LaTeX extension, as do Atom, VS Code and Sublime Text.
It's worth to mention that the editor in Overleaf can be customized to emulate the emacs or vim behaviour. It is also themeable, so you can choose the same syntax highlighting of some of the aforementioned editors. You can find these settings by clicking on the Overleaf menu icon, above the file list panel in your Overleaf project.
There are three output formats available in all TeX distributions. To generate a specific output the document has to be compiled by running a command in a terminal (Linux and macOS) or the command prompt (windows).
For example, if you want to compile a file named "mydocument.tex" you can use one of the next commands:
- This will create "mydocument.dvi", a DVI document
- This will generate "mydocument.pdf", a PDF document
There are some additional commands that allow conversion between formats, PS images are also supported. See the reference guide for a schematic description of commands and output formats.
A description of each output format is provided below:
- (DVI) Device independent file format consists of binary data describing the visual layout of a document in a manner not reliant on any specific image format, display hardware or printer.
- (PS) PostScript file format describes text and graphics on page and it is based on vector graphics. PostScript is, until now, a standard in desktop publishing areas.
- (PDF) Portable Document Format is a file format, based on PostScript, used to represent documents in a manner independent of application software, hardware, and operating systems. It is now widely used as a file format for printing and for distribution on the Web.
Note: Most of the editors nowadays include quick-access icons to compile to different output formats so you don't have to actually run the commands in a system prompt.
On Overleaf, the final compiled output is always a PDF document. If you are required to produce a DVI file from your Overleaf project, here's what you can do:
- Make sure you're using only .eps and .ps images in your project.
- Click on the Overleaf menu icon above the file list panel, and set the Compiler setting to 'LaTeX'.
- Recompile your project.
- Click on the "Logs and output files" button next to the Recompile button.
- Scroll right to the bottom, and click on "Other logs and output files".
- You should then able to download the generated .dvi file.
The other possible compiler settings are pdfLaTeX (the default), XeLaTeX and LuaLaTeX. You can usually go with pdfLaTeX, but choosing a compiler depends on each project's needs.
- LaTeX supports only .eps and .ps image formats for use with
\includegraphics. If all the images in your project are .eps files, then this compiler setting is recommended.
- pdfLaTeX supports .png, .jpg, .pdf image formats. It will convert .eps images to .pdf on-the-fly during compilation, which may prolong the compilation time required. (pdfLaTeX may not be able to handle
pstrickswell on Overleaf.)
- XeLaTeX and LuaLaTeX both supports UTF-8 robustly out of the box, as well as Truetype and OpenType. They are therefore recommended if you need to typeset non-Latin scripts on Overleaf, in conjunction with the
polyglossiapacakge. They also support all of the .png, .jpg, .pdf and .eps image formats.
- XeLaTeX supports
pstricks; but LuaLaTeX doesn't.
- You can extend LuaLaTeX's capabilities by embedding Lua code directly in your document.
Compiling documents with cross-references
In some cases, when your document includes cross-references, you must compile the source twice. It is necessary to include the correct numbers in the table of contents, list of images, reference numbers to theorems and so on.
During the first compilation the LaTeX compiler writes the .aux file for informations about different numbering and during the second one the compiler reads these informations in order to properly generate a table of contents, bibliography, etc.
This process can be automatized by the command
latexmk. For example, to create a pdf out of the "mydocument.tex" file, run
latexmk -pdf mydocument.tex
only once, even if the document has referenced images and bibliography. You can change -pdf to -dvi to set a different file type.
LaTeX compilation file flow
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning equations
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Management in a large project
- Multi-file LaTeX projects
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Margin notes
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Attribute Value Matrices
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class