% This file is automatically generated by
% python latex-papersize.py --texhelp
\documentclass[12pt]{article}
\usepackage[extrabottom=15pt]{latex-papersize}\setlength{\emergencystretch}{3em}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\begin{document}\title{latex-papersize\\\large Calculate \LaTeX{} paper and margin settings for arbitrary magnification}
\author{Silas S. Brown}
\date{2005--2009, 2016, 2019--20, 2025--26.  Version~1.71}
\maketitle
Licensed under the Apache License, Version 2.0 (the ``License'');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    \url{http://www.apache.org/licenses/LICENSE-2.0}

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an ``AS IS'' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\section*{Introduction}
When producing enlarged material in \LaTeX{} for people with
low vision, it's often not enough to simply add such
things as \texttt{\textbackslash Large} because that doesn't enlarge
{\em everything} and it can be difficult to achieve the exact
desired size, especially if unusual packages are being
used as well.

It's more effective to change the \LaTeX{} paper size and
margin settings to simulate {\em small paper} and then magnify
the result up to the desired physical paper size.  This
magnifies everything, and also adds some clarity for
low-vision users because fonts like Computer Modern Roman
have different versions at different sizes and the small-sized
versions are often meant to be clearer.

latex-papersize calculates the necessary settings for
arbitrary font and page sizes.  There are two ways to run it:
a modern \texttt{.sty} that works in \texttt{pdflatex}, \texttt{xelatex} and
\texttt{lualatex}, and a legacy Python script that works with
\texttt{pdflatex} or plain old \texttt{latex} / \texttt{dvips}.  The legacy Python
script requires Python (works in both Python 2 and Python 3)
but the \texttt{.sty} file can be used as-is.
\section*{Modern usage}
In the following instructions, base-size is the point size
that the \TeX{} file is based on---quick reference: if the \texttt{documentclass}
parameters say \texttt{12pt} then (within 1\%) \texttt{\textbackslash small}=11 \texttt{\textbackslash normalsize}=12
\texttt{\textbackslash large}=14 \texttt{\textbackslash Large}=17 \texttt{\textbackslash LARGE}=20 \texttt{\textbackslash huge}=25---and desired-size is the
point size that you want to produce.

For the modern \texttt{.sty} file, simply use

\texttt{\textbackslash usepackage [basesize=12, desiredsize=26] \{latex-papersize\}}

(The default is to enlarge from 10 point to 26 point, but
you should ideally check with individual readers which point
size they work with best.)

Other parameters are the dimensions \texttt{paperwidth} and
\texttt{paperheight} (defaults to A4), \texttt{marginleft} and \texttt{margintop}
(defaults to 10mm), and \texttt{extrabottom} for how much space to
leave for page numbers at the bottom of each page: try
\texttt{extrabottom=15pt} for plain pagestyle.  If it is left at its
default of 0, \texttt{\textbackslash pagestyle\{empty\}} will be set automatically.
\section*{Legacy usage}
If you need to use the legacy Python script, its
command-line parameters depend on whether you are using
\texttt{latex}/\texttt{dvips} or \texttt{pdflatex}.
On most systems, you can begin by typing
\texttt{python latex-papersize.py}.  On some systems you
will need to type \texttt{python3} instead of \texttt{python}, and/or you may need
to specify the full path of \texttt{latex-papersize.py} depending on your
distribution.  If you've installed it using \texttt{pip}, you can try
\texttt{python -m latex-papersize} or \texttt{python3 -m latex-papersize}.  You
may also be able to copy \texttt{latex-papersize.py} to a directory on your
PATH such as \texttt{/usr/local/bin} and then just type \texttt{latex-papersize}.

The instructions below assume you will be typing

\texttt{python latex-papersize.py}

but you should change this to suit your
system as described in the above paragraph.
\section*{Legacy usage with \texttt{latex} and \texttt{dvips}}
To print the geometry settings:

\texttt{python latex-papersize.py} base-size desired-size \texttt{tex}

e.g.: \texttt{python latex-papersize.py 12 26 tex}

The output of this command should then be placed after
\texttt{\textbackslash documentclass} in your \texttt{.tex} file.

Then run \texttt{latex} to make a DVI file, and then do:

\texttt{python latex-papersize.py} base-size desired-size dvi-file

e.g.: \texttt{python latex-papersize.py 12 26 myfile.dvi}

which will print the appropriate \texttt{dvips} command.
\section*{Legacy usage with \texttt{pdflatex}}
It should no longer be necessary to use the Python script with
\texttt{pdflatex}, since the modern \texttt{.sty} file is compatible with \texttt{pdflatex}.
But if for some reason you need to use the Python script instead, you
need only one command:

\texttt{python latex-papersize.py} base-size desired-size \texttt{pdftex}

the output of this command should go just before \texttt{\textbackslash begin\{document\}}.
NB if using \texttt{hyperref} package, put \texttt{hyperref} {\em after} these
settings (and if also using \texttt{pinyin} package then put \texttt{pinyin}
package after that again)
\section*{Page numbers in legacy usage}
When invoking latex-papersize.py with the \texttt{tex} or \texttt{pdftex}
options, you can optionally add a fourth parameter to
specify how many points to leave for page numbers at the
bottom of each page.  Normally 15 is a good idea.  Leaving
this out causes no room to be left for page numbers and
\texttt{\textbackslash pagestyle\{empty\}} to be added.  This does not affect the
\texttt{dvips} command.
\section*{Paper sizes and margins in legacy usage}
It is assumed that the final physical printout will be on
A4 portrait with 10mm margins.  You can override this by
setting the \texttt{paper\_width} and \texttt{paper\_height} environment
variables (in millimetres) before running, e.g.:
\texttt{paper\_width=297 paper\_height=210 python latex-papersize.py} \ldots{}
You can also set the environment variables margin\_left and
margin\_top (the right and bottom margins are assumed to be
mirrors of these).

If using with non-PDF latex, remember to set the
environment variables again when asking latex-papersize.py for
the dvips command.  Or ``export'' them so they remain set.
\section*{Poster printing}
If you want to print on a physical paper size that is
larger than your printer can handle, you can make up the
larger size by sticking together smaller pieces of paper.
Perhaps the best way to do this is to use a separate
utility that knows about printable areas, cut margins,
etc, such as Jos van Eijndhoven's \texttt{poster} utility at
\url{https://ctan.org/pkg/poster}

In this case you can give latex-papersize.py a \texttt{margin\_left} and
\texttt{margin\_top} of 0 (because \texttt{poster} will handle the
margins), set the paper size and desired point size
appropriate for the final poster, use \texttt{latex}/\texttt{dvips}, and run
the resulting \texttt{.ps} through \texttt{poster} with \texttt{-s 1}.  This is
better than getting \texttt{poster} to scale, because if any of
your fonts are rendered into bitmaps by Metafont (as some
CJK fonts are) then you will likely get a better
resolution if the final size is given to latex-papersize.py
rather than to \texttt{poster}.

If you're aiming for a specific number of sheets of paper,
don't pick a physical size that's an exact multiple of
your printer's paper size, because \texttt{poster} accounts for
unprintable areas and overlaps slightly.  Multiply the
printer paper's height and width by 0.88 (or 0.86 if you
want a visual margin added to the finished poster besides
the cutting margins) and try a multiple of that size.
\section*{Example legacy usage in a script}
To typeset a \LaTeX{} file \texttt{file.tex} and magnify from
12-point to 26-point, type a line such as the following
(after adjusting the documentclass it specifies, and
removing or commenting out the documentclass in \texttt{file.tex}):

\texttt{latex "\textbackslash \textbackslash documentclass [12pt] \{article\}}

\texttt{\$(python latex-papersize.py 12 26 tex) \textbackslash \textbackslash input \{file.tex\}" \&\& mv article.dvi file.dvi}

Or in \texttt{pdflatex} (slightly more complex because we need to
put the settings just before \texttt{\textbackslash begin\{document\}}):
\texttt{cat file.tex \textbar{} awk -- "/\textasciicircum{} *\textbackslash \textbackslash \textbackslash \textbackslash begin *\textbackslash \textbackslash \{document\textbackslash \textbackslash \}[\textasciicircum{}\#-\textasciitilde{}]*\textbackslash \$/ \{ print \textbackslash "\$(python latex-papersize.py 12 26 pdftex \textbar{} sed -e 's/\textbackslash \textbackslash /\textbackslash \textbackslash \textbackslash \textbackslash /g')\textbackslash " \} \{ print \}" > /tmp/tmp.tex}
then
\texttt{pdflatex "\textbackslash documentclass [12pt] \{article\} \textbackslash \textbackslash input \{/tmp/tmp.tex\}" \&\& mv article.pdf file.pdf}

To run \texttt{dvips} on the \texttt{.dvi} file (not needed for \texttt{pdflatex}):

\texttt{\$(python latex-papersize.py 12 26 file.dvi)}

It is recommended to use the newer \texttt{.sty} file with a PDF backend
instead of doing all this.
\section*{Where to find history}You shouldn't need this, but old versions of this utility (along
with some non-\LaTeX{} utilities for handling scans and reflowing
documents for giant print) may be found
on GitHub at \url{https://github.com/ssb22/scan-reflow}
and on GitLab at \url{https://gitlab.com/ssb22/scan-reflow}
and on BitBucket \url{https://bitbucket.org/ssb22/scan-reflow}
and at \url{https://gitlab.developers.cam.ac.uk/ssb22/scan-reflow}
and in China: \url{https://gitee.com/ssb22/scan-reflow}
The current version is also on the author's home page
at \url{https://ssb22.user.srcf.net/notes/\#latex}
\end{document}
