Keywords: LaTeX | Linux | TeX Live | PDF Generation | Typesetting System
Abstract: This comprehensive guide details the complete workflow for using LaTeX on Linux systems, covering TeX Live installation, editor selection, basic document creation, compilation commands, and PDF generation. Through practical examples, it demonstrates the process of creating LaTeX documents and provides advanced usage techniques and tool recommendations to facilitate the transition from traditional word processors to professional typesetting systems.
LaTeX System Installation
Deploying a LaTeX system in the Linux environment is the first step toward utilizing this professional typesetting tool. Most mainstream Linux distributions provide complete LaTeX distribution packages, allowing users to easily install them through package managers. TeX Live, as the current mainstream LaTeX distribution, has gradually replaced traditional teTeX and become the preferred choice for most distributions.
For Debian-based Ubuntu systems, the installation command is:
sudo apt install texlive
For Red Hat series CentOS systems, use:
sudo yum install tetex
It's important to note that these installation commands require administrator privileges. Users can execute them using the sudo command or by switching to the root user. TeX Live is a complete TeX system distribution that includes not only the LaTeX core but also integrates numerous commonly used packages and tools, providing an out-of-the-box experience.
Editor Selection and Configuration
While any text editor can be used to write LaTeX documents, choosing the right editor can significantly improve work efficiency. Basic editors like Gedit and Kate can meet simple requirements, while advanced editors like Emacs and Vim offer powerful features such as syntax highlighting, auto-completion, and error checking.
Emacs, when combined with the AUCTeX extension, provides a professional LaTeX editing environment capable of real-time mathematical formula preview, automatic reference and bibliography handling, and integrated compilation and error debugging. Similarly, Vim with the vimtex plugin can also offer comprehensive LaTeX support. Although these tools may have a steeper learning curve, they provide substantial efficiency improvements for long-term use.
Your First LaTeX Document
Create a file named test.tex and input the following basic document structure:
\documentclass[a4paper,12pt]{article}
\begin{document}
The foundations of the rigorous study of \emph{analysis}
were laid in the nineteenth century, notably by the
mathematicians Cauchy and Weierstrass. Central to the
study of this subject are the formal definitions of
\emph{limits} and \emph{continuity}.
Let $D$ be a subset of $\bf R$ and let
$f \colon D \to \mathbf{R}$ be a real-valued function on
$D$. The function $f$ is said to be \emph{continuous} on
$D$ if, for all $\epsilon > 0$ and for all $x \in D$,
there exists some $\delta > 0$ (which may depend on $x$)
such that if $y \in D$ satisfies
\[ |y - x| < \delta \]
then
\[ |f(y) - f(x)| < \epsilon. \]
One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.
\end{document}
This example demonstrates core LaTeX features: document class definition, mathematical environments, text emphasis, and logical structure. The document begins with the \documentclass command, specifying the document type and basic format parameters. \begin{document} and \end{document} mark the boundaries of the document content, within which arbitrarily complex typesetting content can be included.
Document Compilation and Output
After completing the document writing, the LaTeX compiler needs to process the source file. The basic compilation command is:
latex test.tex
This command generates a DVI (Device Independent) format intermediate file, which is the native output format of the TeX system. The compilation process displays detailed processing information, including loaded packages and generated auxiliary files. The success indicator is the appearance of the "Output written on test.dvi" prompt.
To view the generated document, use a DVI viewer:
xdvi test.dvi &
This command launches the viewer window in the background, displaying the typesetting results in real-time. The viewer supports automatic updates, refreshing the display content when the source file is modified and recompiled.
PDF Generation and Optimization
In modern LaTeX usage, PDF has become the standard output format. The command to directly generate PDF is:
pdflatex test.tex
Unlike the traditional latex command, pdflatex directly generates PDF files, skipping the DVI intermediate format. This method is more suitable for modern document exchange needs while supporting richer features such as hyperlinks, embedded fonts, and advanced graphics support.
For documents containing complex bibliographies, cross-references, or tables of contents, multiple compilations are typically required to ensure all references are correctly resolved. In such cases, creating a simple Makefile can automate the compilation process:
all:
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex
Advanced Features and Tool Integration
As document complexity increases, users may need to integrate more tools to enhance work efficiency. Diagram creation tools like xfig and dia can generate high-quality vector graphics that can be seamlessly integrated into LaTeX documents through the \includegraphics command.
For PDF output, it's recommended to prioritize PDF format graphic files to avoid compatibility issues that may arise with EPS format. If EPS files must be used, automatic format conversion can be achieved through the epstopdf package.
Version control systems like Git are crucial for large document projects. Through version control, users can track document modification history, collaborate on editing, and revert to previous versions when needed. Incorporating LaTeX projects into version control represents best practice in modern academic writing.
Continuous Learning and Resource Recommendations
After mastering LaTeX basics, systematic learning of its advanced features is recommended. LaTeX Primer provides comprehensive introductory tutorials covering everything from basic typesetting to complex mathematical formulas, table design, and bibliography management.
For specific document types, LaTeX provides specialized document classes. For example, the Beamer class is specifically designed for creating presentations, offering rich themes and animation effects. Users can find numerous excellent example codes and learning resources through platforms like GitHub.
The active development of the LaTeX community ensures continuous tool improvement. Users can obtain the latest packages and tools through CTAN (Comprehensive TeX Archive Network), most of which are open-source and free, reflecting the open spirit of the LaTeX ecosystem.