Guide
Enable and Verify the microtype Package for Better LaTeX Typography
Learn how to add the microtype package to your LaTeX document, configure protrusion and font expansion, compile with pdfLaTeX/LuaLaTeX/XeLaTeX, and verify improved spacing by checking the log and comparing PDFs.
Published by Tasadduq Burney
07 Oct 2026, 08:16 UTC
2 min13.5K views0

Desired outcome
Make your LaTeX document’s justification tighter and reduce ragged edges by activating character protrusion and font expansion with the microtype package.
Necessary prerequisites
- A TeX distribution that includes
microtype(TeX Live 2023+ or recent MiKTeX). - A source file (
mydoc.tex) compiled with pdfLaTeX, LuaLaTeX, or XeLaTeX. - If using XeLaTeX or LuaLaTeX, the
fontspecpackage must be loaded beforemicrotype.
Focused procedure
- Open the preamble of your
.texfile and add the package: - Optional tuning – adjust protrusion and expansion for the default Latin Modern font:
- Compile the document twice (needed when microtype changes spacing):
- pdfLaTeX:
pdflatex mydoc.tex - LuaLaTeX:
lualatex mydoc.tex - XeLaTeX:
xelatex mydoc.tex
- pdfLaTeX:
- Check the log for confirmation lines such as:
- Produce a reference PDF without microtype by commenting the
\usepackage{microtype}line and recompiling once. - Compare the two PDFs with a visual diff tool (e.g.,
diffpdf mydoc_microtype.pdf mydoc_nomicrotype.pdf) to see tighter justification and fewer overfull boxes.
\usepackage{microtype}
\SetExtraExpansion{stretch}{factor=1000}
microtype adjustment enabled
Expected checks
- The
.logshould contain nomicrotype warningmessages. - Overfull/underfull box counts in the log should be equal or lower than in the reference build.
- Visually, lines should appear more evenly spaced and the right margin less ragged.
Recovery / rollback
If layout problems arise (new overfull boxes or unexpected spacing):
- Comment out
\usepackage{microtype}or add\microtypesetup{disable}after the package load. - Recompile the document (two passes if you changed other settings).
- Verify the log returns to the baseline box counts.
Limitations
- Some OpenType fonts ignore protrusion or expansion, giving inconsistent results.
- Microtype requires two compilation passes when its settings affect layout; a single run may show outdated spacing.
- When using XeLaTeX/LuaLaTeX, loading
fontspecaftermicrotypetriggers an “undefined control sequence” error.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.