latex
Compile LaTeX documents into PDF or other formats
TLDR
Compile a DVI document
Compile a DVI document, specifying an output directory
Compile a DVI document, exiting on each error
SYNOPSIS
latex [options] file
PARAMETERS
-interaction=mode
Sets the interaction mode. Common modes include batchmode (no user input), nonstopmode (prints errors but doesn't stop), scrollmode (similar to nonstopmode but scrolls output), and errorstopmode (stops on first error).
-output-directory=dir
Specifies the directory where all output files (.dvi, .log, .aux, etc.) will be written. If not specified, files are written to the current working directory.
-jobname=name
Assigns a specific name to the output files (e.g., name.dvi, name.log) instead of using the input file's base name. Useful for multiple compilations from one source.
-halt-on-error
Causes latex to exit immediately upon encountering the first error, rather than attempting to continue processing.
-file-line-error
Prints error messages in the standard compiler error message format, including file name and line number, making them easier for editors to parse.
-shell-escape
Enables the execution of external commands from within the LaTeX document (e.g., via \write18). This is powerful but can pose a security risk.
-no-shell-escape
Disables the execution of external commands, overriding any enabled defaults. This is the default and recommended for security.
--version
Displays the version information of the latex program and its underlying TeX engine.
--help
Prints a summary of command-line usage and options.
DESCRIPTION
The latex command is a powerful typesetting program that processes .tex source files written in the LaTeX document preparation system. LaTeX, built upon Donald Knuth's TeX engine, is widely used for producing high-quality documents, especially in scientific, technical, and academic fields, due to its advanced capabilities for handling complex mathematical formulas, citations, cross-references, and structured content.
When you run latex on a .tex file, it compiles the source code, resolves macros, lays out the text, and generates a Device Independent file (.dvi). This .dvi file is an intermediate format that can then be converted into other formats like PostScript (using dvips) or PDF (using dvipdfm or dvipdfmx), or viewed directly with tools like xdvi. Unlike pdflatex, which directly produces PDF, latex's output requires an extra conversion step, which can be advantageous in workflows that require specific intermediate formats or custom post-processing.
CAVEATS
The latex command generates .dvi files, which are not directly viewable or printable without further conversion (e.g., to PostScript or PDF). Users accustomed to modern word processors might find LaTeX's error messages cryptic, requiring familiarity with the LaTeX syntax and log files. The -shell-escape option, while useful for advanced tasks (like generating graphs on the fly), introduces a significant security vulnerability if processing untrusted .tex files, as it allows arbitrary command execution.
TYPICAL WORKFLOW
A common workflow involves multiple passes for complex documents: first run latex on your .tex file to generate .aux files (for cross-references, citations); then run bibtex (if using bibliography) and/or makeindex (if using an index); finally, run latex one or two more times to resolve all references and update the table of contents/index. After that, convert the resulting .dvi file to a final format like PDF using dvipdfm or PostScript using dvips.
COMMON OUTPUT FILES
When latex processes a .tex file (e.g., document.tex), it generates several auxiliary files in addition to the .dvi output:
document.dvi: The Device Independent output file.
document.log: A detailed log of the compilation process, including errors, warnings, and statistics.
document.aux: An auxiliary file storing information for cross-references, table of contents, and bibliography.
document.toc: Stores table of contents data.
document.lof: Stores list of figures data.
document.lot: Stores list of tables data.
document.fls: A file list, useful for tracking included files.
HISTORY
LaTeX was originally created in the early 1980s by Leslie Lamport as a set of macros for the TeX typesetting program, developed by Donald Knuth. It aimed to simplify the process of writing documents by abstracting away the low-level typesetting commands, allowing authors to focus on content and logical structure rather than visual presentation. The most widely used version today is LaTeX2e (released in 1994), which standardized many features and provided a more robust and extensible framework. Its development has been community-driven, evolving with new packages and tools to meet the demands of diverse publishing needs, solidifying its position as a de-facto standard in academic and scientific publishing.