LaTeX is a typesetting system based on TeX. Before use, you need to install a TeX distribution and an editor.
\nThis chapter introduces LaTeX installation and configuration, applicable to Windows, macOS, and Linux systems.
\n\n
LaTeX Installation
\n1. Windows System
\nOn Windows systems, it is recommended to use MiKTeX or TeX Live to install LaTeX.
\nInstalling MiKTeX
\n- \n
- Download MiKTeX: Visit the MiKTeX official website and download the installer suitable for your system. \n
- Run the Installer: Double-click the downloaded installer and follow the prompts. It is recommended to select "Full Installation" to ensure all common packages are installed. \n
- Configure Environment Variables: After installation, ensure that the MiKTeX
bindirectory has been added to the system's PATH environment variable. This allows you to use LaTeX commands directly from the command line. \n
Installing TeX Live
\n- \n
- Download TeX Live: Visit the TeX Live official website and download the installer suitable for your system. \n
- Run the Installer: Double-click the downloaded installer and follow the prompts. The TeX Live installation process can be time-consuming as it includes a large number of packages and tools. \n
- Configure Environment Variables: After installation, ensure that the TeX Live
bindirectory has been added to the system's PATH environment variable. \n
2. macOS System
\nOn macOS systems, it is recommended to use MacTeX to install LaTeX.
\nInstalling MacTeX
\n- \n
- Download MacTeX: Visit the MacTeX official website and download the installer suitable for your system. \n
- Run the Installer: Double-click the downloaded
.pkgfile and follow the prompts. MacTeX includes TeX Live along with related GUI tools. \n - Configure Environment Variables: After installation, ensure that the TeX Live
bindirectory has been added to the system's PATH environment variable. \n
3. Linux System
\nOn Linux systems, it is recommended to use TeX Live to install LaTeX.
\n3.3.1 Installing TeX Live
\n- \n
- Install using Package Manager: Most Linux distributions provide TeX Live packages. You can use your package manager to install it. For example, on Ubuntu, you can use the following command:
sudo apt-get install texlive-full. This will install the complete TeX Live distribution, including all common packages and tools. \n - Manual Installation: If you need the latest version of TeX Live, you can download the installation script from the TeX Live official website and install it manually. \n
\n
LaTeX Configuration
\nEditor Selection
\nLaTeX documents are plain text files, so you can use any text editor to write LaTeX code. However, using a dedicated LaTeX editor can improve efficiency. Here are some commonly used LaTeX editors:
\n- \n
- TeXstudio: A cross-platform LaTeX editor with powerful features, suitable for both beginners and advanced users. \n
- Overleaf: An online LaTeX editor that requires no installation, ideal for collaboration and quick editing. \n
- VS Code: A general-purpose code editor that supports LaTeX editing and compilation through plugins (such as LaTeX Workshop). \n
Compiling LaTeX Documents
\nLaTeX documents need to be compiled to generate the final PDF file. Common compilation commands include:
\n- \n
pdflatex: Generates a PDF file, suitable for most documents. \nxelatex: Supports Unicode and TrueType fonts, suitable for processing Chinese documents. \nlualatex: A Lua-based compilation engine that supports modern fonts and advanced features. \n
The usage of compilation commands is as follows:
\npdflatex mydocument.tex\nThis will generate the mydocument.pdf file.
Handling Chinese Documents
\nIf you need to handle Chinese documents, it is recommended to use the xelatex or lualatex compilation engines, along with the ctex package. Below is a simple LaTeX Chinese document example:
Example
\n\\documentclass{ctexart}\n\\begin{document}\n Hello, world!\n\\end{document}\nTo compile this document using xelatex:
Example
\nxelatex mydocument.tex\nInstalling and Managing Packages
\nLaTeX packages can be installed and managed via a package manager. In MiKTeX and TeX Live, you can use the following commands to install packages:
\n- \n
- MiKTeX: Use
MiKTeX Consoleto search for and install packages. \n - TeX Live: Use the
tlmgrcommand to install packages. For example:tlmgr install <package-name>\n
YouTip