summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bxpapersize
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/bxpapersize
Initial commit
Diffstat (limited to 'macros/latex/contrib/bxpapersize')
-rw-r--r--macros/latex/contrib/bxpapersize/LICENSE21
-rw-r--r--macros/latex/contrib/bxpapersize/README.md154
-rw-r--r--macros/latex/contrib/bxpapersize/bxpapersize.sty547
3 files changed, 722 insertions, 0 deletions
diff --git a/macros/latex/contrib/bxpapersize/LICENSE b/macros/latex/contrib/bxpapersize/LICENSE
new file mode 100644
index 0000000000..8ada757fbc
--- /dev/null
+++ b/macros/latex/contrib/bxpapersize/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2017 Takayuki YATO (aka. "ZR")
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/macros/latex/contrib/bxpapersize/README.md b/macros/latex/contrib/bxpapersize/README.md
new file mode 100644
index 0000000000..97c65e5d8a
--- /dev/null
+++ b/macros/latex/contrib/bxpapersize/README.md
@@ -0,0 +1,154 @@
+BXpapersize Package
+===================
+
+LaTeX: To synchronize output paper size with layout paper size
+
+As is well known, in LaTeX processing layout paper size specified by
+document class options is not automatically applied to output paper
+size. By employing this package, authors can make output paper size
+be identical to layout paper size. They can also set output paper size
+to arbitrary values.
+
+It should be noted that there are many packages that try to synchronize
+paper sizes, possibly in a slightly different manner. This package
+allows authors to decide whether the setting made by this package
+should have higher or lower priority over the settings made by others.
+
+### System requirement
+
+ * TeX format: LaTeX.
+ * TeX engine: Anything.
+ * DVI driver (in DVI mode): dvips, dvipdfmx, or whatever supports
+ ‘papersize’ special.
+ * Dependent packages:
+ - ifpdf, ifxetex, ifluatex, ifvtex
+ - xkeyval
+ - atbegshi
+
+### Installation
+
+ - `*.sty` → $TEXMF/tex/latex/BXpapersize
+
+### License
+
+This package is distributed under the MIT License.
+
+The bxpapersize Package
+-----------------------
+
+### Package Loading
+
+ \usepackage[<option>,...]{bxpapersize}
+
+The available options are described hereafter.
+
+#### Annihilation
+
+ * `disabled`: Disables all functionality of this package. It may be
+ useful to resolve conflict caused by some packages depending on
+ the bxpapersize package. Note that once `disabled` is used there
+ is no way to enable the functionality.
+ * `nodvidriver`: A synonym for `disabled`.
+
+#### Priority
+
+ * `priority=<value>`: In DVI mode, this decides the priority of the
+ ‘papersize’ specials issued by this package relative to the
+ ‘papersize’ specials issued by others.
+ The set of valid values is:
+ - `low`: Priotizes specials by others.
+ - `middle`/`default` (default): Does not care about priority.
+ - `high`: Priotizes specials by this package.
+ * `olddvips`: Must be specified when you use dvips older than that
+ included in TeX Live 2017, so as to make the `priority` option
+ work correctly.
+
+#### Other options
+
+Any key-value pairs that are valid in `\papersizesetup` can be used
+as package options.
+
+ % to begin with deactivated state
+ \usepackage[active=false]{bxpapersize}
+
+Note that the default values of the `\papersizesetup` command are also
+applied when the package is loaded. For example, `size=real` will be
+in effect when this package is loaded without the `size` option key.
+
+### Usage
+
+Once the package is loaded, the output paper size will be adjusted,
+respecting the settings given by the package options. By default, the
+output papersize will be made identical to the layout paper size.
+
+ % For many cases, it's enough.
+ \usepackage{bxpapersize}
+
+You can change the settings of this package using `\papersizesetup`
+command, invoked as follows:
+
+ \bxpapersizesetup[<key>=<value>,...]
+
+The available keys are listed below:
+
+ * `active=true|false`: Temporarily activates/deactivates the function
+ of this package.
+ * `size=<value>`: Decides what the output paper size should be.
+ Available values are:
+ - `real`: The output should be equal to the layout paper size
+ given by `\paperwidth/height`, except that the stock paper size
+ given by `\stockwidth/height` will be employed instead when
+ it is available.
+ - `real*`: The output should be equal to the layout paper size,
+ even if the stock paper size is available.
+ - `{<width>,<height>}`: The output should be equal to the
+ specified values.
+ - `<width>*<height>`: The alternative form of `{<width>,<height>}`.
+ It is provided because option strings including braces are not
+ permitted in the package option list.
+ - `<papersize-name>`: The output should be equal to the given
+ size. The set pf available paper-size names is the same as the
+ [geometry package] and is listed below:
+ a0paper--a6paper, b0paper--b6paper, c0paper--c6paper, b0j--b6j,
+ ansiapaper--ansiepaper, letterpaper, legalpaper, executivepaper,
+ screen.
+ - `landscape`, `truedimen`: These are used in combination with
+ `<papersize-name>` options, and have the same meaning as in the
+ geometry package.
+ - `box`: The output should be the actual size of the TeX box
+ to be shipped out. It is provided for advanced users.
+
+[geometry package]: https://www.ctan.org/pkg/geometry
+
+Note that, however, what happens about output paper size when some
+settings are changed in the midst of pages differs among TeX engines
+and/or DVI drivers. Thus such usage should be employed only by advanced
+users.
+
+The comamnd `\bxpapersizesetup` is a synonym for `\papersizesetup`,
+so as to cope with command name conflict. Namely, `\papersizesetup`
+will be not (re)defined if the command of that name is already defined,
+but `\bxpapersizesetup` will be always provided.
+
+Revision History
+----------------
+
+ * Version 0.3b ‹2017/10/08›
+ - Support pTeX-ng (ApTeX) engine properly.
+ - (Experimental) Add `adjustmag` option.
+ * Version 0.3a ‹2017/05/02›
+ - Support format `size=<width>*<height>`
+ * Version 0.3 ‹2017/02/08›
+ - As to `size=real`, the stock size becomes taken into account,
+ and the new value `real*` is provided.
+ - Make `nodvidriver` synonym for `disabled`.
+ - Make `\papersizesetup` synonym for `\bxpapersizesetup`.
+ - Add `olddvips`.
+ - Support `size=<papersize-name>`. together with `landscape` and
+ `truedimen`.
+ * Version 0.2 ‹2016/03/26›
+ - The first public version.
+
+--------------------
+Takayuki YATO (aka. "ZR")
+https://github.com/zr-tex8r
diff --git a/macros/latex/contrib/bxpapersize/bxpapersize.sty b/macros/latex/contrib/bxpapersize/bxpapersize.sty
new file mode 100644
index 0000000000..1370314a8a
--- /dev/null
+++ b/macros/latex/contrib/bxpapersize/bxpapersize.sty
@@ -0,0 +1,547 @@
+%%
+%% This is file 'bxpapersize.sty'.
+%%
+%% Copyright (c) 2017 Takayuki YATO (aka. "ZR")
+%% GitHub: https://github.com/zr-tex8r
+%% Twitter: @zr_tex8r
+%%
+%% This package is distributed under the MIT License.
+%%
+
+%% package declaration
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{bxpapersize}[2017/10/08 v0.3b]
+
+%% preparation
+\def\bxpr@pkgname{bxpapersize}
+\providecommand\bxDebug[1]{}
+
+%--------------------------------------- options
+
+% Note: Only non-key-value global options should be picked.
+
+%% 'disabled' / 'nodvidriver'
+\chardef\bxpr@disabled=0
+\DeclareOption{disabled}{%
+ \chardef\bxpr@disabled=1 }
+\DeclareOption{nodvidriver}{%
+ \chardef\bxpr@disabled=1 }
+%% 'olddvips'
+\chardef\bxpr@olddvips=0
+\DeclareOption{olddvips}{%
+ \chardef\bxpr@olddvips=1 }
+%% keyval
+\@onlypreamble\bxpr@kvopt
+\let\bxpr@kvopt\@empty % key-value option list
+\DeclareOption*{%
+ \edef\bxpr@kvopt{\bxpr@kvopt,\CurrentOption}}
+\ProcessOptions*
+
+%% If 'disabled' is given, quit now.
+\ifnum\bxpr@disabled>\z@
+ \providecommand*\papersizesetup{\bxpapersizesetup}%
+ \newcommand*\bxpapersizesetup[1]{}%
+\expandafter\endinput\fi\relax
+
+%--------------------------------------- general
+
+%% load packages
+\RequirePackage{xkeyval}[2008/08/10]% v2.6
+\RequirePackage{atbegshi}
+\RequirePackage{ifpdf,ifxetex,ifluatex,ifvtex}
+
+%% variables
+\newdimen\bxpr@dima
+\let\bxpr@width\relax
+\let\bxpr@height\relax
+
+%% constants
+\chardef\bxpr@mode@@dvimode=0
+\chardef\bxpr@mode@@pdfmode=1
+
+%% unique tokens
+\def\bxpr@end{\bxpr@end@}
+
+%% \bxpr@ptexng
+\chardef\bxpr@ptexng=0
+\edef\bxpr@tmpa{\string\ngbanner}\edef\bxpr@tmpb{\meaning\ngbanner}
+\ifx\bxpr@tmpa\bxpr@tmpb \chardef\bxpr@ptexng=1 \fi
+
+%% \bxpr@pagewidth / \bxpr@pageheight
+%% \bxpr@horigin / \bxpr@vorigin
+\ifluatex % LuaTeX
+ \ifx\pagewidth\@undefined % old version
+ \let\bxpr@pagewidth\pdfpagewidth
+ \let\bxpr@pageheight\pdfpageheight
+ \else % new version
+ \let\bxpr@pagewidth\pagewidth
+ \let\bxpr@pageheight\pageheight
+ \fi
+ \ifx\pdfvariable\@undefined % old version
+ \let\bxpr@horigin\pdfhorigin
+ \let\bxpr@vorigin\pdfvorigin
+ \else % new version
+ \edef\bxpr@horigin{\pdfvariable horigin}
+ \edef\bxpr@vorigin{\pdfvariable vorigin}
+ \fi
+\else\ifxetex % XeTeX
+ % treated as dvi-mode
+\else\ifvtex % VTeX
+ \let\bxpr@pagewidth\mediawidth
+ \let\bxpr@pageheight\mediaheight
+\else\ifnum0\the\bxpr@ptexng\ifpdf1\fi>0 % pdfTeX in PDF mode
+ \let\bxpr@pagewidth\pdfpagewidth
+ \let\bxpr@pageheight\pdfpageheight
+ \let\bxpr@horigin\pdfhorigin
+ \let\bxpr@vorigin\pdfvorigin
+\fi\fi\fi\fi
+\ifx\bxpr@horigin\@undefined % fallback
+ \def\bxpr@horigin{1truein }
+ \def\bxpr@vorigin{1truein }
+\fi
+
+%% \bxpr@mode
+\ifx\bxpr@pagewidth\@undefined
+ \let\bxpr@mode\bxpr@mode@@dvimode
+\else
+ \let\bxpr@mode\bxpr@mode@@pdfmode
+\fi
+
+%% \bxpr@csletcs{<CSa>}{<CSb>}
+\def\bxpr@csletcs#1#2{%
+ \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}
+
+%--------------------------------------- parameters
+
+%% constants
+\chardef\bxpr@priority@@low=0
+\chardef\bxpr@priority@@middle=1
+\chardef\bxpr@priority@@default=1
+\chardef\bxpr@priority@@high=2
+\ifnum\bxpr@olddvips>\z@
+ \chardef\bxpr@priority@@low=2
+ \chardef\bxpr@priority@@high=0
+\fi
+\chardef\bxpr@size@@real=0 %'real', use \paperwidth/height
+\chardef\bxpr@size@@realS=1 %'real*'
+\chardef\bxpr@size@@box=2 %'box', use shipout box size
+\chardef\bxpr@size@@boxS=3 %'box*'
+\chardef\bxpr@size@@custom=4 % size explicitly given
+
+%% variables
+\newif\ifbxpr@needs@reset@size
+\let\bxpr@priority\bxpr@priority@@default
+\let\bxpr@size\bxpr@size@@real
+\def\bxpr@cs@width{\z@}% custom page width
+\def\bxpr@cs@height{\z@}% custom page height
+
+%% error message
+\def\bxpr@err@nlprm#1{%
+ \PackageError\bxpr@pkgname
+ {You can set '#1' only in preamble}%
+ \@ehc}
+\def\bxpr@err@ivval#1#2{%
+ \PackageError\bxpr@pkgname
+ {Invalid value for '#1': #2}%
+ \@ehc}
+\def\bxpr@err@ivkey{%
+ \begingroup \let\MessageBreak\relax % freeze
+ \let\bxpr@tmpb\@empty
+ \@for\bxpr@tmpa:=\XKV@rm\do{%
+ \edef\bxpr@tmpb{\bxpr@tmpb\MessageBreak\@spaces\bxpr@tmpa}}%
+ \PackageError\bxpr@pkgname
+ {Unknown parameter(s)\bxpr@tmpb\MessageBreak
+ are found in the given list}
+ \endgroup}
+
+%% 'active'
+\define@boolkey+[bxpr]{prm}{active}[true]{}%
+ {\bxpr@err@ivval{active}{#1}}
+\bxpr@prm@activetrue
+
+%% 'priority'
+\define@choicekey*+[bxpr]{prm}{priority}%
+ {low,middle,default,high}%
+ {\bxpr@set@priority{#1}}%
+ {\bxpr@err@ivval{priority}{#1}}
+\def\bxpr@set@priority#1{%
+ \bxpr@csletcs{bxpr@priority}{bxpr@priority@@#1}}
+\AtBeginDocument{%
+ \def\bxpr@set@priority#1{% invalidate
+ \bxpr@err@nlprm{priority}}}
+
+%% 'adjustmag'
+\define@boolkey+[bxpr]{prm}{adjustmag}[true]%
+ {}%
+ {\bxpr@err@ivval{adjustmag}{#1}}
+
+%% 'truedimen'
+\define@boolkey+[bxpr]{prm}{truedimen}[true]%
+ {\bxpr@needs@reset@sizetrue}%
+ {\bxpr@err@ivval{truedimen}{#1}}
+
+%% 'landscape'
+\define@boolkey+[bxpr]{prm}{landscape}[true]%
+ {\bxpr@needs@reset@sizetrue}%
+ {\bxpr@err@ivval{landscape}{#1}}
+
+%% 'size'
+\define@choicekey*+[bxpr]{prm}{size}[\bxpr@tmpa\bxpr@tmpb]%
+ {real,real*,box,box*,
+ % preset paper sizes
+ a0paper,a1paper,a2paper,a3paper,a4paper,a5paper,a6paper,%
+ b0paper,b1paper,b2paper,b3paper,b4paper,b5paper,b6paper,%
+ c0paper,c1paper,c2paper,c3paper,c4paper,c5paper,c6paper,%
+ b0j,b1j,b2j,b3j,b4j,b5j,b6j,%
+ ansiapaper,ansibpaper,ansicpaper,ansidpaper,ansiepaper,%
+ letterpaper,legalpaper,executivepaper,screen}%
+ {\def\bxpr@val@size{#1}\bxpr@needs@reset@sizefalse
+ \ifcase\bxpr@tmpb\relax
+ \let\bxpr@size\bxpr@size@@real
+ \or \let\bxpr@size\bxpr@size@@realS
+ \or \let\bxpr@size\bxpr@size@@box
+ \or \let\bxpr@size\bxpr@size@@boxS
+ \or \bxpr@set@size@a(841,1189){mm}% a0paper
+ \or \bxpr@set@size@a(594,841){mm}% a1paper
+ \or \bxpr@set@size@a(420,594){mm}% a2paper
+ \or \bxpr@set@size@a(297,420){mm}% a3paper
+ \or \bxpr@set@size@a(210,297){mm}% a4paper
+ \or \bxpr@set@size@a(148,210){mm}% a5paper
+ \or \bxpr@set@size@a(105,148){mm}% a6paper
+ \or \bxpr@set@size@a(1000,1414){mm}% b0paper
+ \or \bxpr@set@size@a(707,1000){mm}% b1paper
+ \or \bxpr@set@size@a(500,707){mm}% b2paper
+ \or \bxpr@set@size@a(353,500){mm}% b3paper
+ \or \bxpr@set@size@a(250,353){mm}% b4paper
+ \or \bxpr@set@size@a(176,250){mm}% b5paper
+ \or \bxpr@set@size@a(125,176){mm}% b6paper
+ \or \bxpr@set@size@a(917,1297){mm}% c0paper
+ \or \bxpr@set@size@a(648,917){mm}% c1paper
+ \or \bxpr@set@size@a(458,648){mm}% c2paper
+ \or \bxpr@set@size@a(324,458){mm}% c3paper
+ \or \bxpr@set@size@a(229,324){mm}% c4paper
+ \or \bxpr@set@size@a(162,229){mm}% c5paper
+ \or \bxpr@set@size@a(114,162){mm}% c6paper
+ \or \bxpr@set@size@a(1030,1456){mm}% b0j
+ \or \bxpr@set@size@a(728,1030){mm}% b1j
+ \or \bxpr@set@size@a(515,728){mm}% b2j
+ \or \bxpr@set@size@a(364,515){mm}% b3j
+ \or \bxpr@set@size@a(257,364){mm}% b4j
+ \or \bxpr@set@size@a(182,257){mm}% b5j
+ \or \bxpr@set@size@a(128,182){mm}% b6j
+ \or \bxpr@set@size@a(8.5,11){in}% ansiapaper
+ \or \bxpr@set@size@a(11,17){in}% ansibpaper
+ \or \bxpr@set@size@a(17,22){in}% ansicpaper
+ \or \bxpr@set@size@a(22,34){in}% ansidpaper
+ \or \bxpr@set@size@a(34,44){in}% ansiepaper
+ \or \bxpr@set@size@a(8.5,11){in}% letterpaper
+ \or \bxpr@set@size@a(8.5,14){in}% legalpaper
+ \or \bxpr@set@size@a(7.25,10.5){in}% executivepaper
+ \or \bxpr@set@size@a(225,180){mm}% screen
+ \fi}%
+ {% custom page size ('size={<width>,<height>}')
+ \def\bxpr@val@size{#1}\bxpr@needs@reset@sizefalse
+ \def\bxpr@tmpa##1,##2,##3\@nil{%
+ \begingroup\setbox\z@\hbox{%
+ \@tempdima##1\relax \@tempdimb##2\relax
+ \xdef\bxpr@g@next{%
+ \def\noexpand\bxpr@cs@width{\the\@tempdima}%
+ \def\noexpand\bxpr@cs@height{\the\@tempdimb}}}%
+ \endgroup\bxpr@g@next}%
+ \def\bxpr@tmpb{#1}%
+ \bxpr@set@size@star
+ \expandafter\bxpr@tmpa\bxpr@tmpb,,\@nil
+ \let\bxpr@size\bxpr@size@@custom}
+\def\bxpr@set@size@a(#1,#2)#3{%
+ \edef\bxpr@tmpa##1##2{%
+ \ifbxpr@prm@landscape##2\else##1\fi
+ \ifbxpr@prm@truedimen true\fi #3\relax}%
+ \bxpr@dima=\bxpr@tmpa{#1}{#2}\edef\bxpr@cs@width{\the\bxpr@dima}%
+ \bxpr@dima=\bxpr@tmpa{#2}{#1}\edef\bxpr@cs@height{\the\bxpr@dima}%
+ \let\bxpr@size\bxpr@size@@custom}
+\def\bxpr@set@size@star{%
+ \expandafter\bxpr@set@size@star@a\bxpr@tmpb**\bxpr@end}
+\def\bxpr@set@size@star@a#1*#2*#3\bxpr@end{%
+ \ifx*#2*\else \def\bxpr@tmpb{#1,#2}\fi}
+
+%--------------------------------------- user interface
+
+%%<*> \bxpapersizesetup{<key>=<value>,...}
+\newcommand*\bxpapersizesetup[1]{%
+ \setkeys*[bxpr]{prm}{#1}%
+ \ifx\XKV@rm\@empty\else
+ \bxpr@err@ivkey
+ \fi
+ \ifbxpr@needs@reset@size
+ \edef\bxpr@tmpa{%
+ \noexpand\setkeys[bxpr]{prm}{size=\bxpr@val@size}%
+ }\bxpr@tmpa
+ \fi}
+%%<*> \papersizesetup{<key>=<value>,...}
+% Synonym for \bxpapersizesetup, declared only if not yet defined.
+\providecommand*\papersizesetup{%
+ \bxpapersizesetup}
+
+%% apply package options
+\edef\bxpr@tmpa{%
+ \noexpand\bxpapersizesetup{\bxpr@kvopt}%
+}\bxpr@tmpa
+
+%--------------------------------------- page hook
+
+%% \bxpr@begindoc@first@hook
+% Placed at the head of the begin-docuemnt hook.
+\@onlypreamble\bxpr@begindoc@first@hook
+\let\bxpr@begindoc@first@hook\@empty
+\begingroup
+ \toks@\expandafter{\@begindocumenthook}
+ \xdef\@begindocumenthook{%
+ \noexpand\bxpr@begindoc@first@hook
+ \the\toks@}
+\endgroup
+
+%% \bxpr@begindoc@last@hook
+% Placed after the begin-docuemnt hook.
+\def\bxpr@begindoc@last@hook{%
+ \let\bxpr@begindoc@last@hook\@undefined}
+\g@addto@macro\document{%
+ \bxpr@begindoc@last@hook}
+
+%% add hook for every page
+\g@addto@macro\bxpr@begindoc@first@hook{%
+ \bxDebug{bxpapersize settings:^^J%
+ mode=\the\bxpr@mode^^J%
+ priority=\the\bxpr@priority^^J%
+ size=\the\bxpr@size(\bxpr@cs@width,\bxpr@cs@height)%
+ \ifnum\bxpr@tombow>\z@ [tombow]\fi}%
+ \bxpr@geometry@hack
+ \ifcase\bxpr@mode % dvi
+ \ifcase\bxpr@priority % low
+ \AtBeginShipoutInit
+ \def\bxpr@every@page@hook{%
+ \bxpr@page@process
+ \bxpr@modify@output@box\bxpr@special@chunk\relax
+ \AtBeginShipoutNext{\bxpr@every@page@hook}}%
+ \AtBeginShipoutNext{%
+ \bxpr@page@process
+ \AtBeginShipoutNext{\bxpr@every@page@hook}}%
+ \AtBeginShipoutFirst{\bxpr@special@chunk}
+ \or % default
+ \def\bxpr@every@page@hook{%
+ \bxpr@page@process
+ \bxpr@modify@output@box\relax\bxpr@special@chunk}%
+ \AtBeginShipout{\bxpr@every@page@hook}%
+ \or % high
+ \AtBeginShipoutInit
+ \def\bxpr@every@page@hook{%
+ \bxpr@page@process
+ \bxpr@modify@output@box\relax\bxpr@special@chunk
+ \AtBeginShipoutNext{\bxpr@every@page@hook}}%
+ \AtBeginShipoutNext{\bxpr@every@page@hook}%
+ \fi
+ \else % pdf
+ \def\bxpr@every@page@hook{%
+ \bxpr@page@process
+ \bxpr@modify@output@box\relax\bxpr@special@chunk}%
+ \AtBeginShipout{\bxpr@every@page@hook}%
+ \fi}
+
+%% \bxpr@tombow
+\chardef\bxpr@tombow=0
+\expandafter\ifx\csname iftombow\expandafter\endcsname
+ \csname iftrue\endcsname
+ \chardef\bxpr@tombow=1
+\fi
+
+%% \bxpr@modify@output@box{<pre>}{<post>}
+\def\bxpr@modify@output@box#1#2{%
+ \setbox\AtBeginShipoutBox\vbox{%
+ #1\box\AtBeginShipoutBox#2}}
+
+%--------------------------------------- geometry hack
+
+% The geometry package sets \paperwidth/height to incorrect
+% values after its begin-document hook when magnification is
+% in effect. For example, when \mag=2000 and the actual paper
+% width is 100pt (=200truept), geometry will set \paperwidth
+% to 200pt (=400truept), which is clearly incorrect.
+% This behavior seems intentional, but I don't know the reason.
+% At least it is harmful to the function of this package, so
+% that I fixed it by simply revoking the change by geometry.
+
+%% \bxpr@geometry@hack
+\@onlypreamble\bxpr@geometry@hack
+\def\bxpr@geometry@hack{%
+ \@ifpackageloaded{geometry}{%
+ \edef\bxpr@tmpa{%
+ \paperwidth=\the\paperwidth
+ \paperheight=\the\paperheight}%
+ \expandafter\g@addto@macro\expandafter\bxpr@begindoc@last@hook
+ \expandafter{\bxpr@tmpa}%
+ }{}}
+
+%--------------------------------------- per-page process
+
+%% \bxpr@special@chunk
+\let\bxpr@special@chunk\@empty
+
+%% \bxpr@set@page@size{<width>}{<height>}
+\ifcase\bxpr@mode %dvi
+ \def\bxpr@set@page@size#1#2{%
+ \begingroup
+ \bxpr@let@real@mag@to\bxpr@tmpa
+ \paperwidth=#1\relax \paperwidth=\bxpr@tmpa\paperwidth
+ \paperheight=#2\relax \paperheight=\bxpr@tmpa\paperheight
+ \xdef\bxpr@g@next{%
+ \def\noexpand\bxpr@tmpb{\the\paperwidth,\the\paperheight}}%
+ \endgroup \bxpr@g@next
+ \bxDebug{papersize=\bxpr@tmpb}%
+ \edef\bxpr@special@chunk{\special{papersize=\bxpr@tmpb}}}%
+\else %pdf
+ \def\bxpr@set@page@size#1#2{%
+ \let\bxpr@tmpb\@empty
+ \ifbxpr@prm@adjustmag
+ \bxpr@let@real@mag@to\bxpr@tmpb
+ \fi
+ \bxpr@pagewidth=#1\relax \bxpr@pagewidth=\bxpr@tmpb\bxpr@pagewidth
+ \bxpr@pageheight=#2\relax \bxpr@pageheight=\bxpr@tmpb\bxpr@pageheight
+ \bxDebug{papersize=\the\bxpr@pagewidth,\the\bxpr@pageheight}}%
+\fi
+
+%% \bxpr@let@real@mag@to\CS
+\def\bxpr@let@real@mag@to#1{%
+ \begingroup
+ \@tempcnta=\mag \advance\@tempcnta100000
+ \def\bxpr@tmpa1##1##2##3##4##5\relax{%
+ \@tempdima=##1##2.##3##4##5\p@}%
+ \expandafter\bxpr@tmpa\the\@tempcnta\relax
+ \xdef\bxpr@g@next{%
+ \def\noexpand#1{\strip@pt\@tempdima}}%
+ \endgroup \bxpr@g@next}
+
+%% \bxpr@page@process
+\def\bxpr@page@process{%
+ \ifbxpr@prm@active
+ \bxpr@page@process@a
+ \fi}
+\def\bxpr@page@process@a{%
+ \ifcase\bxpr@size % real
+ \bxpr@use@real@size
+ \bxpr@set@page@size{\bxpr@width}{\bxpr@height}%
+ \or % real*
+ \bxpr@set@page@size{\paperwidth}{\paperheight}%
+ \or % box
+ \bxpr@use@box@size
+ \setbox\AtBeginShipoutBox\vbox{%
+ \kern-\bxpr@vorigin
+ \moveleft\bxpr@horigin\box\AtBeginShipoutBox}%
+ \bxpr@set@page@size{\bxpr@width}{\bxpr@height}%
+ \or % box*
+ \bxpr@use@box@size
+ \bxpr@set@page@size{\bxpr@width}{\bxpr@height}%
+ \else % custom
+ \bxpr@set@page@size{\bxpr@cs@width}{\bxpr@cs@height}%
+ \fi}
+
+%% \bxpr@use@real@size
+\def\bxpr@use@real@size{%
+ \bxpr@use@real@size@a{width}%
+ \bxpr@use@real@size@a{height}}
+\def\bxpr@use@real@size@a#1{%
+ \begingroup
+ \bxpr@csletcs{bxpr@tmpa}{paper#1}%
+ \ifnum\bxpr@tombow>\z@
+ \advance\bxpr@tmpa2truein\relax
+ \fi
+ \bxpr@csletcs{bxpr@tmpb}{stock#1}%
+ \ifx\bxpr@tmpb\relax\else \ifdim\bxpr@tmpb>\z@
+ \bxpr@tmpa\bxpr@tmpb
+ \fi\fi
+ \xdef\bxpr@g@next{%
+ \def\expandafter\noexpand\csname bxpr@#1\endcsname{%
+ \the\bxpr@tmpa}}
+ \endgroup \bxpr@g@next}
+
+%% \bxpr@use@box@size
+\def\bxpr@use@box@size{%
+ \edef\bxpr@width{\the\wd\AtBeginShipoutBox}%
+ \bxpr@dima\ht\AtBeginShipoutBox
+ \advance\bxpr@dima\dp\AtBeginShipoutBox
+ \edef\bxpr@height{\the\bxpr@dima}}
+
+%--------------------------------------- cope with tate-direction
+
+% In (u)pTeX engine, boxes and lists have the direction attribute,
+% and yoko boxes cannot be unboxed in tate lists (and vice versa).
+% This restriction can cause the atbegshi package to fail, and thus
+% the 'priority=low' setting results in an error when used together
+% with document classes of tate direction.
+
+% if '\tate' is invalid then quit now
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname tate\endcsname\relax
+\expandafter\endinput\fi\relax
+
+% if priority is middle then quit
+\ifnum\bxpr@priority=\bxpr@priority@@default
+\expandafter\endinput\fi\relax
+
+% check in advance
+\ifx\AtBegShi@Output\@undefined
+ \PackageWarningNoLine\bxpr@pkgname
+ {The patch to atbegshi failed, so\MessageBreak
+ the package might not work well}
+\expandafter\endinput\fi\relax
+
+%% \ifbxpr@ddir
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname ifddir\endcsname\relax
+ \bxpr@csletcs{ifbxpr@ddir}{iffalse}
+\else
+ \bxpr@csletcs{ifbxpr@ddir}{ifddir}
+\fi
+
+%% \bxpr@patch
+% Patches the internal macro \AtBegShi@Output of atbegshi package,
+% so that the macro is prepended by a `\yoko` primitive and appended
+% by a direction primitive to switch back to the original.
+\@onlypreamble\bxpr@patch
+\def\bxpr@patch{%
+ \expandafter\bxpr@patch@a\AtBegShi@Output\bxpr@end}
+\@onlypreamble\bxpr@patch@a
+\def\bxpr@patch@a{%
+ \futurelet\bxpr@tok\bxpr@patch@b}
+\@onlypreamble\bxpr@patch@b
+\def\bxpr@patch@b{%
+ \ifx\bxpr@tok\egroup \expandafter\@firstoftwo
+ \else \expandafter\@secondoftwo
+ \fi{\bxpr@patch@c}{\bxpr@patch@d{}}}
+\@onlypreamble\bxpr@patch@c
+\def\bxpr@patch@c#1#2{%
+ \bxpr@patch@d{#1#2}}
+\@onlypreamble\bxpr@patch@d
+\def\bxpr@patch@d#1#2\bxpr@end{%
+ \def\AtBegShi@Output{#1\bxpr@ABS@prehook#2\bxpr@ABS@posthook}}
+% do patch
+\bxpr@patch
+
+%% \bxpr@restore@dir
+\let\bxpr@restore@dir\relax
+
+%% \bxpr@ABS@prehook
+\def\bxpr@ABS@prehook{%
+ \iftdir \yoko \let\bxpr@restore@dir\tate
+ \else\ifbxpr@ddir \yoko \let\bxpr@restore@dir\dtou
+ \else \let\bxpr@restore@dir\relax
+ \fi\fi
+ \ifx\bxpr@restore@dir\relax\else
+ \bxDebug{Temporarily switching \meaning\bxpr@restore@dir
+ \space to \string\yoko}%
+ \fi}
+%% \bxpr@ABS@posthook
+\def\bxpr@ABS@posthook{%
+ \bxpr@restore@dir}
+
+%--------------------------------------- all done
+\endinput
+%% EOF