%% This is file `stocksize.sty', %% %% Copyright (C) 2024 by João M. Lourenço %% %% This file may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3c of this license %% or (at your option) any later version. The latest version of this %% license is in: %% %% http://www.latex-project.org/lppl.txt %% %% and version 1.3c or later is part of all distributions of LaTeX %% version 2006/05/20 or later. %% \def\fileversion{1.0.2} \def\filedate {2024/11/13} \edef\filename {\@currname} \ProvidesPackage{stocksize}[% \filedate\ v\fileversion (João M. Lourenço) User defined PDF paper (stock) size.] % Load geometry if it was was not loaded by the user \AddToHook{begindocument/before}{ \@ifpackageloaded{geometry}{}{ \RequirePackage[reset]{geometry} } } % Change the physical paper (stock) size % Works with pdfLaTeX, XeLaTeX and LuaLaTeX \newcommand*{\@ss@setpdfpagesize}[2]{% \@ifundefined{pdfpageheight}{}{\pdfpageheight=#1}% \@ifundefined{pdfpagewidth}{}{\pdfpagewidth=#2}% \@ifundefined{pageheight}{}{\pageheight=#1}% \@ifundefined{pagewidth}{}{\pagewidth=#2}% \paperheight=#1\stockheight=#1% \paperwidth=#2\stockwidth=#2% } \newcounter{@ss@cnt} \newcommand*{\pdfsavegeometry}[1]{% \expandafter\edef\csname @sspw@\arabic{@ss@cnt}\endcsname% {\the\dimexpr\Gm@lmargin+\Gm@width+\Gm@rmargin\relax}% \expandafter\edef\csname @ssph@\arabic{@ss@cnt}\endcsname% {\the\dimexpr\Gm@tmargin+\Gm@height+\Gm@bmargin\relax}% \stepcounter{@ss@cnt}% \savegeometry{@ss@cnt@\arabic{@ss@cnt}}% \newdimen\@tempdimd% \@tempdima=\Gm@lmargin\@tempdimb=\Gm@rmargin% \@tempdimc=\Gm@tmargin\@tempdimd=\Gm@bmargin% \define@key{Gm}{keepmargins}[true]{\setkeys{Gm}{lmargin=\the\@tempdima, rmargin=\the\@tempdimb, tmargin=\the\@tempdimc, bmargin=\the\@tempdimd }}% \restoregeometry% \newgeometry{#1}% \edef\@sspw{\the\dimexpr\Gm@lmargin+\Gm@width+\Gm@rmargin\relax}% \edef\@ssph{\the\dimexpr\Gm@tmargin+\Gm@height+\Gm@bmargin\relax}% \@ss@setpdfpagesize{\@ssph}{\@sspw}% } \newcommand*{\pdfrestoregeometry}{% \loadgeometry{@ss@cnt@\arabic{@ss@cnt}}% \addtocounter{@ss@cnt}{-1}% \@ss@setpdfpagesize{\csname @ssph@\arabic{@ss@cnt}\endcsname}% {\csname @sspw@\arabic{@ss@cnt}\endcsname}% } \newcommand*{\newstocksize}{\pdfsavegeometry} \newcommand*{\restorestocksize}{\pdfrestoregeometry}