Directory macros/latex/contrib/stocksize
stocksize — Structured control of PDF page (stock) size in LaTeX
Purpose
The stocksize package provides robust control of the physical PDF page size (the stock size) inside a LaTeX document.
It complements the geometry package by managing paper size transitions reliably, including nested changes, while delegating margin and layout calculations to geometry.
The package is designed for documents where the physical page size itself must change mid-document, such as appendices, inserts, or mixed-format publications.
Key Concepts
- Stock size = physical PDF page dimensions
- Layout = (logical) paper height and width, margins, text block, headers/footers (handled by
geometry) stocksizecoordinates both, ensuring they remain synchronized
Typical Use Cases
- Appendices with different paper formats
- Mixed A4 / A5 / Letter documents
- Landscape or square inserts
- Print-ready PDFs with non-uniform stock
- Publisher workflows requiring strict PDF page dimensions
Features
- Logical page size control (via
geometry) - Physical page size control (PDF page dimensions)
- Fully nested size changes (LIFO stack semantics)
- Optional margin preservation
- Reliable restoration of previous sizes
- Transparent integration with
geometry - Engine-independent (pdfLaTeX, XeLaTeX, LuaLaTeX)
- Documented design with rationale and implementation notes
Installation
Place stocksize.sty in your working directory or a LaTeX-visible path.
Load the package in the preamble with:
\usepackage[OPTIONS]{stocksize}
The package loads geometry automatically if needed.
User Interface
\newstocksize{⟨options⟩}
Starts a new physical page with the specified stock size and geometry options.
Internally:
- Saves the current page and layout state
- Applies
geometrywith the provided options - Updates the PDF page dimensions
Options
All options are passed directly to geometry, except keepmargins which are processed by the package.
Common examples:
| Option | Meaning |
|---|---|
layoutsize={w,h} |
Set physical page size |
paperwidth=… / paperheight=… |
Alternative size specification |
margin=… |
Uniform margins |
keepmargins |
Preserve current margins |
Example
\newstocksize{layoutsize={20cm,25cm}, margin=2cm}
\restorestocksize
Restores the previous stock size and layout.
- Operates in Last-In-First-Out (stack) order
- Safe for arbitrarily deep nesting
- Restores both geometry and PDF page size
Example
\newstocksize{layoutsize={15cm,10cm}, margin=1.5cm} Content... \newstocksize{layoutsize={20cm,20cm}, keepmargins} Nested content in 20x20 cm stock and paper size... \restorestocksize Back to 15×10 cm stock and paper size... \restorestocksize Back to the initial stock and paper size...
Relation to geometry
geometryalone does not safely support nested page size changesstocksizeprovides a stack-based abstraction on top ofgeometry- All layout computation remains delegated to
geometry stocksizeensures page size and layout state remain consistent
Technical Notes
- PDF page size is set using:
\pdfpagewidth/\pdfpageheight(pdfLaTeX)\pagewidth/\pageheight(XeLaTeX, LuaLaTeX)
- Geometry states are saved and restored explicitly
- No grouping tricks or output-routine hacks are used
Documentation
The full technical documentation, including design rationale and edge-case discussion, is available in:
stocksize-doc.pdf
Package Information
- Version: 2.0.1 (2026-01-01)
- Author: João M. Lourenço
- License: LPPL v1.3c or later
- Dependencies:
geometry - Engines: pdfLaTeX, XeLaTeX, LuaLaTeX
Contributing
Bug reports, tests, and design discussions are welcome via GitHub issues.
Copyright © 2025-26 João M. Lourenço. Crafted with 🧡 for reproducible scientific writing.
Download the contents of this package in one zip archive (117.7k).
stocksize – A flexible and easy interface to paper (stock) dimensions
The package geometry is excellent for customizing the page layout. However, using the \newgeometry command to change the page size in the middle of the document only affects the typing area and does not affect the real paper (stock) size. This package circumvents this situation by resizing the paper (stock) size to the new page layout.
| Package | stocksize |
| Support | https://github.com/joaomlourenco/stocksize/discussions |
| Bug tracker | https://github.com/joaomlourenco/stocksize/issues |
| Repository | https://github.com/joaomlourenco/stocksize |
| Version | 2.0.1 2026-01-01 |
| Licenses | The LaTeX Project Public License 1.3c |
| Copyright | 2024–2026 João Lourenço |
| Maintainer | João M. Lourenço |
| Contained in | TeX Live as stocksize MiKTeX as stocksize |
| Topics | Geometry |