| 1 |
# stocksize — Structured control of PDF page (stock) size in LaTeX |
| 2 |
|
| 3 |
[](https://ctan.org/pkg/stocksize) |
| 4 |
[](https://github.com/joaomlourenco/stocksize) |
| 5 |
[](https://github.com/joaomlourenco/stocksize) |
| 6 |
[](https://www.latex-project.org/lppl/lppl-1-3c/) |
| 7 |
[](https://www.latex-project.org/) |
| 8 |
|
| 9 |
--- |
| 10 |
|
| 11 |
## Purpose |
| 12 |
|
| 13 |
The **`stocksize`** package provides **robust control of the physical PDF page size** (the *stock size*) inside a LaTeX document. |
| 14 |
|
| 15 |
It complements the `geometry` package by managing **paper size transitions** reliably, including **nested changes**, while delegating margin and layout calculations to `geometry`. |
| 16 |
|
| 17 |
The package is designed for documents where the **physical page size itself must change mid-document**, such as appendices, inserts, or mixed-format publications. |
| 18 |
|
| 19 |
--- |
| 20 |
|
| 21 |
## Key Concepts |
| 22 |
|
| 23 |
- **Stock size** = physical PDF page dimensions |
| 24 |
- **Layout** = (logical) paper height and width, margins, text block, headers/footers (handled by `geometry`) |
| 25 |
- `stocksize` coordinates both, ensuring they remain synchronized |
| 26 |
|
| 27 |
--- |
| 28 |
|
| 29 |
## Typical Use Cases |
| 30 |
|
| 31 |
- Appendices with different paper formats |
| 32 |
- Mixed A4 / A5 / Letter documents |
| 33 |
- Landscape or square inserts |
| 34 |
- Print-ready PDFs with non-uniform stock |
| 35 |
- Publisher workflows requiring strict PDF page dimensions |
| 36 |
|
| 37 |
--- |
| 38 |
|
| 39 |
## Features |
| 40 |
|
| 41 |
- **Logical page size control** (via `geometry`) |
| 42 |
- **Physical page size control** (PDF page dimensions) |
| 43 |
- **Fully nested size changes** (LIFO stack semantics) |
| 44 |
- ***Optional margin preservation** |
| 45 |
- **Reliable restoration** of previous sizes |
| 46 |
- **Transparent integration with `geometry`** |
| 47 |
- **Engine-independent** (pdfLaTeX, XeLaTeX, LuaLaTeX) |
| 48 |
- **Documented design** with rationale and implementation notes |
| 49 |
|
| 50 |
--- |
| 51 |
|
| 52 |
## Installation |
| 53 |
|
| 54 |
Place `stocksize.sty` in your working directory or a LaTeX-visible path. |
| 55 |
|
| 56 |
Load the package in the preamble with: |
| 57 |
```latex |
| 58 |
\usepackage[OPTIONS]{stocksize} |
| 59 |
``` |
| 60 |
|
| 61 |
The package loads `geometry` automatically if needed. |
| 62 |
|
| 63 |
--- |
| 64 |
|
| 65 |
## User Interface |
| 66 |
|
| 67 |
### `\newstocksize{⟨options⟩}` |
| 68 |
|
| 69 |
Starts a new physical page with the specified stock size and geometry options. |
| 70 |
|
| 71 |
Internally: |
| 72 |
1. Saves the current page and layout state |
| 73 |
2. Applies `geometry` with the provided options |
| 74 |
3. Updates the PDF page dimensions |
| 75 |
|
| 76 |
**Options** |
| 77 |
|
| 78 |
All options are passed directly to `geometry`, except `keepmargins` which are processed by the package. |
| 79 |
|
| 80 |
Common examples: |
| 81 |
|
| 82 |
| Option | Meaning | |
| 83 |
|------|--------| |
| 84 |
| `layoutsize={w,h}` | Set physical page size | |
| 85 |
| `paperwidth=…` / `paperheight=…` | Alternative size specification | |
| 86 |
| `margin=…` | Uniform margins | |
| 87 |
| `keepmargins` | Preserve current margins | |
| 88 |
|
| 89 |
**Example** |
| 90 |
|
| 91 |
```latex |
| 92 |
\newstocksize{layoutsize={20cm,25cm}, margin=2cm} |
| 93 |
``` |
| 94 |
|
| 95 |
--- |
| 96 |
|
| 97 |
### `\restorestocksize` |
| 98 |
|
| 99 |
Restores the **previous** stock size and layout. |
| 100 |
|
| 101 |
- Operates in **Last-In-First-Out (stack) order** |
| 102 |
- Safe for arbitrarily deep nesting |
| 103 |
- Restores both geometry and PDF page size |
| 104 |
|
| 105 |
**Example** |
| 106 |
|
| 107 |
```latex |
| 108 |
\newstocksize{layoutsize={15cm,10cm}, margin=1.5cm} |
| 109 |
Content... |
| 110 |
|
| 111 |
\newstocksize{layoutsize={20cm,20cm}, keepmargins} |
| 112 |
Nested content in 20x20 cm stock and paper size... |
| 113 |
\restorestocksize |
| 114 |
|
| 115 |
Back to 15×10 cm stock and paper size... |
| 116 |
\restorestocksize |
| 117 |
|
| 118 |
Back to the initial stock and paper size... |
| 119 |
``` |
| 120 |
|
| 121 |
--- |
| 122 |
|
| 123 |
## Relation to `geometry` |
| 124 |
|
| 125 |
- `geometry` alone does **not** safely support nested page size changes |
| 126 |
- `stocksize` provides a **stack-based abstraction** on top of `geometry` |
| 127 |
- All layout computation remains delegated to `geometry` |
| 128 |
- `stocksize` ensures page size and layout state remain consistent |
| 129 |
|
| 130 |
--- |
| 131 |
|
| 132 |
## Technical Notes |
| 133 |
|
| 134 |
- PDF page size is set using: |
| 135 |
- `\pdfpagewidth` / `\pdfpageheight` (pdfLaTeX) |
| 136 |
- `\pagewidth` / `\pageheight` (XeLaTeX, LuaLaTeX) |
| 137 |
- Geometry states are saved and restored explicitly |
| 138 |
- No grouping tricks or output-routine hacks are used |
| 139 |
|
| 140 |
--- |
| 141 |
|
| 142 |
## Documentation |
| 143 |
|
| 144 |
The full technical documentation, including design rationale and edge-case discussion, is available in: |
| 145 |
|
| 146 |
``` |
| 147 |
stocksize-doc.pdf |
| 148 |
``` |
| 149 |
|
| 150 |
--- |
| 151 |
|
| 152 |
## Package Information |
| 153 |
|
| 154 |
- **Version**: 2.0.1 (2026-01-01) |
| 155 |
- **Author**: João M. Lourenço |
| 156 |
- **License**: LPPL v1.3c or later |
| 157 |
- **Dependencies**: `geometry` |
| 158 |
- **Engines**: pdfLaTeX, XeLaTeX, LuaLaTeX |
| 159 |
|
| 160 |
--- |
| 161 |
|
| 162 |
## Contributing |
| 163 |
|
| 164 |
Bug reports, tests, and design discussions are welcome via GitHub issues. |
| 165 |
|
| 166 |
--- |
| 167 |
|
| 168 |
Copyright © 2025-26 João M. Lourenço. |
| 169 |
Crafted with 🧡 for reproducible scientific writing. |