Directory macros/latex/contrib/stocksize
stocksize — A flexible LaTeX package for dynamic paper size management in PDF documents
Overview
The stocksize package provides commands to query, modify, and restore the physical stock (paper) size within a LaTeX document. It supports nested page size changes, automatic margin preservation, and integrates seamlessly with the geometry package. This package is ideal for workflows requiring adaptive page formats, multi-format printing, or dynamic layouts.
Use Cases
- Mixed-format documents: Combine A4, A5, and custom sizes in one PDF.
- Design layouts: Create brochures, flyers, or booklets with varying page sizes.
- Reports with appendices: Different page sizes for different sections.
- International documents: Mix different paper standards (A4, Letter, etc.)
Features
- ✨ Dynamic page sizing: Change paper dimensions mid-document.
- 🪆 Nested sizes: Stack multiple page sizes with automatic LIFO restoration.
- 🧮 Margin preservation: Optionally keep and restore existing margins when resizing.
- ⚙️ Compatible: Minimal dependencies and easy integration.
- 🔍 Debugging support: Provides macros for easy querying of paper width and height.
- 🧰 Simple API: Minimal commands to master.
- 🧩 Geometry integration: Works with standard LaTeX classes and geometry setups.
- 🧠 Multi-engine support: Works with pdfLaTeX, XeLaTeX, and LuaLaTeX.
- 🧾 Documented: Companion documentation (
stocksize-doc.tex) included.
Quick Start
Installation
Place stocksize.sty in your project directory or LaTeX package path.
📖 Commands
=> \newstocksize{options}
Starts a new page with the given paper (stock) size. The subsequent pages will keep this new paper size.
Options:
| Option | Description |
|---|---|
layoutsize={width,height} |
Sets the page dimensions. |
margin=value |
Sets uniform margins on all sides. |
keepmargins |
Preserves current margins in the new layout. |
| Any other option | Passed to \newgeometry from the geometry package. |
Example:
\newstocksize{layoutsize={20cm,25cm}, margin=2cm} \newstocksize{a5paper, margin=1cm} % Using preset sizes \newstocksize{layoutsize={10cm,15cm}, keepmargins} % Keep current margins
=> \restorestocksize
Restores the previous page size. Works in Last In First Out (LIFO) fashion, allowing nested size changes to be unwound correctly.
Example:
\newstocksize{layoutsize={15cm,10cm}, margin=1.5cm} Content here... \newstocksize{layoutsize={20cm,20cm}, margin=4cm} Content here... \restorestocksize Back to 15cm×10cm \restorestocksize Back to default size
How It Works
The stocksize package modifies the actual PDF page size using engine-specific commands:
- pdfLaTeX: changes
\pdfpageheightand\pdfpagewidth. - XeLaTeX/LuaLaTeX: changes
\pageheightand\pagewidth.
When you use \newstocksize, the package:
- Saves the current layout configuration.
- Applies your new geometry settings via the
geometrypackage. - Updates the physical PDF page dimensions accordingly.
When you use \restorestocksize, it reverses these steps in order.
Package Information
- Version: 1.0.4 (2025/11/05)
- Author: João M. Lourenço
- License: LaTeX Project Public License (LPPL) v1.3c or later
- Dependencies:
geometrypackage (automatically loaded if needed) - Compatibility: pdfLaTeX, XeLaTeX, LuaLaTeX
Documentation
For detailed examples and advanced usage, see stocksize-doc.tex in the repository.
Contributing
Found a bug or have a feature request? Please open an issue on the GitHub repository.
License
This package is distributed under the LaTeX Project Public License (LPPL) v1.3c or later.
Made with ❤️ by João M. Lourenço
Download the contents of this package in one zip archive (167.6k).
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 | 1.0.4 2025-11-05 |
| Licenses | The LaTeX Project Public License 1.3c |
| Copyright | 2024–2025 João Lourenço |
| Maintainer | João M. Lourenço |
| Contained in | TeX Live as stocksize MiKTeX as stocksize |
| Topics | Geometry |