CTAN Comprehensive TeX Archive Network

Directory macros/latex/contrib/stocksize

README.md

stocksize — A flexible package for dynamic paper size management in PDF documents

License: LPPL LaTeX Build Status


Overview

The stocksize package provides commands to query, modify, and restore the physical stock (paper) size within a 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 classes and geometry setups.
  • 🧠 Multi-engine support: Works with pdf, XeLaTeX, and Lua.
  • 🧾 Documented: Companion documentation (stocksize-doc.tex) included.

Quick Start

Installation

Place stocksize.sty in your project directory or 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:

  • pdf: changes \pdfpageheight and \pdfpagewidth.
  • XeLaTeX/Lua: changes \pageheight and \pagewidth.

When you use \newstocksize, the package:

  1. Saves the current layout configuration.
  2. Applies your new geometry settings via the geometry package.
  3. 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: Project Public License (LPPL) v1.3c or later
  • Dependencies: geometry package (automatically loaded if needed)
  • Compatibility: pdf, XeLaTeX, Lua

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 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.

Packagestocksize
Supporthttps://github.com/joaomlourenco/stocksize/discussions
Bug trackerhttps://github.com/joaomlourenco/stocksize/issues
Repositoryhttps://github.com/joaomlourenco/stocksize
Version1.0.4 2025-11-05
LicensesThe Project Public License 1.3c
Copyright2024–2025 João Lourenço
MaintainerJoão M. Lourenço
Contained inTeX Live as stocksize
MiKTeX as stocksize
TopicsGeometry
...
Guest Book Sitemap Contact Contact Author