Learn to find, install, and manage LaTeX packages. Understand CTAN, package documentation, troubleshooting conflicts, and best practices.
Master LaTeX package management to extend your documents with powerful features. This guide covers package discovery, installation, usage, and troubleshooting.
Good news: LaTeX Cloud Studio includes all major packages pre-installed. You can focus on using packages rather than installing them!
Packages extend LaTeX’s core functionality by providing:
Additional commands and environments
New document classes
Enhanced formatting options
Specialized symbols and fonts
Integration with external tools
Copy
% Loading packages in the preamble\documentclass{article}% Essential packages\usepackage[utf8]{inputenc} % Input encoding\usepackage[T1]{fontenc} % Font encoding\usepackage[english]{babel} % Language support\usepackage{graphicx} % Graphics inclusion\usepackage{amsmath} % Enhanced mathematics% Packages with options\usepackage[margin=1in]{geometry} % Page layout\usepackage[style=authoryear]{biblatex} % Bibliography\usepackage[table,xcdraw]{xcolor} % Colors\begin{document}% Package commands now available\includegraphics{image.png} % From graphicx\textcolor{blue}{Blue text} % From xcolor\begin{align} % From amsmath E &= mc^2\end{align}\end{document}
% Essential mathematics\usepackage{amsmath} % Enhanced math environments\usepackage{amssymb} % Additional math symbols\usepackage{mathtools} % Extensions to amsmath% Graphics and figures\usepackage{graphicx} % Include graphics\usepackage{tikz} % Create graphics programmatically\usepackage{pgfplots} % Create plots and charts% Tables and arrays\usepackage{booktabs} % Professional table formatting\usepackage{array} % Enhanced column types\usepackage{longtable} % Multi-page tables% Text formatting\usepackage{microtype} % Improved typography\usepackage{enumitem} % Customizable lists\usepackage{fancyhdr} % Custom headers/footers% Colors and styling\usepackage{xcolor} % Color support\usepackage{listings} % Code listings\usepackage{hyperref} % Hyperlinks and PDF features% Bibliography and citations\usepackage{biblatex} % Modern bibliography (recommended)\usepackage{natbib} % Traditional bibliography
\documentclass{article}% 1. Input/Output encoding (first)\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}% 2. Language and fonts\usepackage[english]{babel}\usepackage{lmodern}% 3. Page layout\usepackage[margin=1in]{geometry}% 4. Mathematics (early for widespread use)\usepackage{amsmath,amssymb}% 5. Graphics and colors\usepackage{graphicx}\usepackage{xcolor}% 6. Tables and lists\usepackage{booktabs}\usepackage{enumitem}% 7. Bibliography (before hyperref)\usepackage[backend=biber]{biblatex}% 8. Hyperref (near the end)\usepackage{hyperref}% 9. Packages that must load after hyperref\usepackage{cleveref}\begin{document}% Content here\end{document}
% Packages often accept options to modify behavior% Geometry with specific margins\usepackage[ top=1in, bottom=1in, left=1.5in, right=1in, headheight=15pt]{geometry}% Babel with multiple languages\usepackage[english,spanish,french]{babel}% Biblatex with style and backend\usepackage[ backend=biber, style=authoryear, sorting=nyt, maxcitenames=2]{biblatex}% Hyperref with link colors\usepackage[ colorlinks=true, linkcolor=blue, citecolor=green, urlcolor=red]{hyperref}% Listings with default language\usepackage[language=Python]{listings}% Multiple options for xcolor\usepackage[table,xcdraw,dvipsnames]{xcolor}
% Check if package is available\IfPackageExists{microtype}{ \usepackage{microtype} \newcommand{\hasmicrotype}{true}}{ \newcommand{\hasmicrotype}{false}}% Load different packages based on compiler\usepackage{iftex}\ifPDFTeX \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}\else \usepackage{fontspec}\fi% Version-specific loading\@ifpackagelater{tikz}{2020/12/27}{ % TikZ version 3.1.8 or later \usetikzlibrary{new-features}}{ % Older TikZ version \usetikzlibrary{legacy-features}}% Global options vs package options\documentclass[12pt]{article} % Global option affects all packages\usepackage{geometry} % Inherits 12pt if relevant% Override global options\usepackage[10pt]{package} % This package uses 10pt regardless
hyperref conflicts: Load hyperref late, but before cleveref
Font conflicts: Don’t mix incompatible font packages
Math conflicts: amsmath and mathtools can conflict with some packages
Table conflicts: Some table packages don’t work together
Encoding conflicts: inputenc and fontspec are mutually exclusive
Copy
% Conflict: subfigure vs subcaption% DON'T DO THIS:% \usepackage{subfigure} % Obsolete% \usepackage{subcaption} % Modern% DO THIS:\usepackage{subcaption} % Use only the modern package% Conflict: times vs newtx% DON'T DO THIS:% \usepackage{times} % Obsolete% \usepackage{newtxtext} % Modern replacement% DO THIS:\usepackage{newtxtext,newtxmath} % Complete modern replacement% Conflict: hyperref positioning% WRONG ORDER:% \usepackage{cleveref}% \usepackage{hyperref}% CORRECT ORDER:\usepackage{hyperref}\usepackage{cleveref}% Resolving font encoding conflicts\usepackage{iftex}\ifPDFTeX \usepackage[utf8]{inputenc} % For pdflatex \usepackage[T1]{fontenc}\else \usepackage{fontspec} % For xelatex/lualatex\fi
% Method 1: Minimal example\documentclass{article}\usepackage{problematic-package}\begin{document}Test content\end{document}% Method 2: Load packages incrementally\documentclass{article}% \usepackage{package1} % Comment out packages one by one% \usepackage{package2} % to identify conflicts% \usepackage{package3}\usepackage{package4} % Until you find the problematic combination% Method 3: Check package versions\listfiles % Add this before \begin{document}% This will list all loaded packages and versions in the log% Method 4: Verbose error reporting\errorcontextlines=999 % Show more context in error messages\tracingmacros=1 % Trace macro expansions (very verbose!)