blob: bbe8c49ac3ff148616421366a3c63763b9b739c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
%
% pxatbegshi.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the platex-tools bundle.
% https://github.com/aminophen/platex-tools
%
% --------------------------------------------------------------------
% [Note]
% Previous version (2018/09/21 v0.4) was largely based on
% "cope with tate-direction"
% of bxpapersize.sty 2017/05/02 v0.3a by T. Yato.
% -- concept: execute all hooks in temporary yoko direction,
% -- by prepending \yoko and switching back to the original
% However, it was problematic when used with multicol.sty.
%
% Thus, in newer version (2019/09/07 v0.5), I reverted back to
% the original code (2018/09/21 v0.3), which was largely based on
% H. Kitagawa's on GitHub:texjporg/tex-jp-build#21.
% -- concept: execute all hooks inside yoko direction \vbox
% --------------------------------------------------
%
%% package declaration
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxatbegshi}
[2019/09/07 v0.5 Patch to atbegshi for (u)pLaTeX]
%% preparations
\def\pxabgs@pkgname{pxatbegshi}
\def\pxabgs@warn{\PackageWarningNoLine\pxabgs@pkgname}
%% load it
\RequirePackage{atbegshi}
%% internal macros are locally effective
\begingroup
%--------------------------------------- helpers
%% unique tokens
\def\pxabgs@mark{\pxabgs@mark@}
\def\pxabgs@fin{\pxabgs@fin@}
%% \pxabgs@patch@cmd\CMD{<orig>}{<new>}
\@onlypreamble\pxabgs@patch@cmd
\def\pxabgs@patch@cmd#1#2#3{%
\def\pxabgs@next##1#2##2\pxabgs@mark##3\pxabgs@fin{%
\ifx\pxabgs@mark##3\pxabgs@mark
\let\pxabgs@fragment\relax
\else
\def\pxabgs@fragment{##2}%
\def#1{##1#3##2}%
\fi}%
\expandafter\pxabgs@next#1\pxabgs@mark#2\pxabgs@mark\pxabgs@fin}
%---------------------------------------
% concept: execute all hooks inside yoko direction \vbox
% prepare
\let\pxabgs@AtBegShi@Output\AtBegShi@Output
% try first patch
\pxabgs@patch@cmd\pxabgs@AtBegShi@Output
{\let\AtBegShi@OrgProtect\protect}%
{\setbox8\vbox\bgroup\yoko\let\AtBegShi@OrgProtect\protect}
\ifx\pxabgs@fragment\relax % failure
\let\pxabgs@AtBegShi@Output\relax
\else % success, try second patch
\pxabgs@patch@cmd\pxabgs@AtBegShi@Output
{\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox}%
{\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup}
\ifx\pxabgs@fragment\relax % failure
\let\pxabgs@AtBegShi@Output\relax
\else % success, try third patch
\pxabgs@patch@cmd\pxabgs@AtBegShi@Output{%
\begingroup
\setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
\endgroup
\let\protect\AtBegShi@OrgProtect
}{%
\begingroup
\setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
\endgroup
\let\protect\AtBegShi@OrgProtect
\egroup
}
\ifx\pxabgs@fragment\relax % failure
\let\pxabgs@AtBegShi@Output\relax
\fi
\fi
\fi
% commit the change only when successful
\ifx\pxabgs@AtBegShi@Output\relax
\pxabgs@warn{Failed in patching \string\AtBegShi@Output}
\else
\global\let\AtBegShi@Output\pxabgs@AtBegShi@Output
\fi
\endgroup
%% internal macros are no longer effective
%--------------------------------------- done
\endinput
%% EOF
|