OSDN Git Service

Correct package date in \ProvidesPackage
[luatex-ja/luatexja.git] / src / patches / lltjp-atbegshi.sty
1 %
2 % lltjp-atbegshi.sty
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-atbegshi}[2021-04-29 Patching \string\shipout\space hooks for LuaTeX-ja]
7
8 % concept: execute all hooks inside yoko direction \vbox
9
10 \ifltj@ltfilehook@avail
11 %<*ltshipout>-----------------------------------
12 %
13 \RequirePackage{expl3}
14 \ExplSyntaxOn\makeatletter
15 \box_new:N \l__platex_shipout_dummy_box
16 \if_cs_exist:N \__shipout_execute_main_cont:Nnnn %% 2021-06-01
17 \cs_new_eq:NN \__platex_original_shipout_execute_main_cont:Nnnn
18               \__shipout_execute_main_cont:Nnnn
19 \cs_set:Npn \__shipout_execute_main_cont:Nnnn #1#2#3#4 {
20   % if the box #1 is not a \yoko-box (= horizontal writing),
21   % then make it a \yoko-box behorehand.
22   \platex_if_box_yoko:NF #1 {
23     \vbox_set:Nn #1 { \platex_direction_yoko: \box_use:N #1 }
24   }
25   % if the current direction is not \yoko,
26   % then enclose \__shipout_execute_main_cont:Nnnn with
27   % a dummy \yoko-box named \l__platex_shipout_dummy_box.
28   \platex_if_direction_yoko:TF {
29     \__platex_original_shipout_execute_main_cont:Nnnn { #1 } { #2 } { #3 } { #4 }
30   }{
31     \vbox_set:Nn \l__platex_shipout_dummy_box {
32       \platex_direction_yoko:
33       \__platex_original_shipout_execute_main_cont:Nnnn { #1 } { #2 } { #3 } { #4 }
34     }
35     % [Limitation] the code above may discard some contents,
36     % so we'd like to put it back by \box\l__platex_shipout_dummy_box.
37     % however, an infinite loop occurs if we uncomment the line below
38     % so we can't.
39     %\box_use:N \l__platex_shipout_dummy_box
40   }
41 }
42
43 \else: %% 2020-10-01
44 \cs_new_eq:NN \__platex_original_shipout_execute_cont: \__shipout_execute_cont:
45 \cs_set:Npn \__shipout_execute_cont:
46 {
47   \platex_if_box_yoko:NF \l_shipout_box {
48     \vbox_set:Nn \l_shipout_box { \platex_direction_yoko: \box_use:N \l_shipout_box }
49   }
50   \platex_if_direction_yoko:TF {
51     \__platex_original_shipout_execute_cont:
52   }{
53     \vbox_set:Nn \l__platex_shipout_dummy_box {
54       \platex_direction_yoko: \__platex_original_shipout_execute_cont:
55     }
56   }
57 }
58 \fi:
59 %</ltshipout>-----------------------------------
60 \ExplSyntaxOff
61 \expandafter\endinput
62 \fi
63 \RequirePackage{atbegshi}
64 %<*atbegshi>-------------------------------------
65 % patching atbegshi.sty
66 %%%  following codes are almost copied from
67 %%%  pxatbegshi.sty 2019/09/07 v0.5 (in platex-tools bundle, by H. Yamashita).
68
69 \ifdefined\AtBeginShipoutOriginalShipout
70   \let\AtBeginShipoutOriginalShipout\ltj@shipout
71 \fi
72 \AtBeginShipoutInit
73 \DeclareRobustCommand \AtBeginDvi [1]{%
74   \global \setbox \@begindvibox
75     \vbox{\yoko\unvbox \@begindvibox #1}%
76 }
77 %% internal macros are locally effective
78 \begingroup
79
80 % helpers
81 %% unique tokens
82 \def\pxabgs@mark{\pxabgs@mark@}
83 \def\pxabgs@fin{\pxabgs@fin@}
84
85 %% \pxabgs@patch@cmd\CMD{<orig>}{<new>}
86 \def\pxabgs@patch@cmd#1#2#3{%
87   \ifx#1\relax\else
88   \def\pxabgs@next##1#2##2\pxabgs@mark##3\pxabgs@fin{%
89     \ifx\pxabgs@mark##3\pxabgs@mark\let#1\relax
90     \else
91       \def\pxabgs@fragment{##2}\def#1{##1#3##2}%
92     \fi}%
93   \expandafter\pxabgs@next#1\pxabgs@mark#2\pxabgs@mark\pxabgs@fin
94   \fi
95 }
96
97 % prepare
98 \ifdefined\AtBegShi@Output
99   \let\pxabgs@AtBegShi@Output\AtBegShi@Output
100 \else\let\pxabgs@AtBegShi@Output\relax\fi
101 % try first patch
102 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
103   {\let\AtBegShi@OrgProtect\protect}%
104   {\setbox8\vbox\bgroup\yoko\let\AtBegShi@OrgProtect\protect}
105 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
106   {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox}%
107   {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup}
108 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
109   {%
110     \begingroup
111       \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
112     \endgroup
113     \let\protect\AtBegShi@OrgProtect
114   }{%
115     \begingroup
116       \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
117     \endgroup
118     \let\protect\AtBegShi@OrgProtect
119     \egroup
120   }
121 % commit the change only when successful
122 \ifx\pxabgs@AtBegShi@Output\relax
123   \@PackageWarningNoLine{lltjp-atbegshi}{%
124     Failed in patching \string\AtBegShi@Output.\MessageBreak
125     This may cause error in tate direction%
126   }
127 \else
128   \global\let\AtBegShi@Output\pxabgs@AtBegShi@Output
129 \fi
130
131 \endgroup
132 %% internal macros are no longer effective
133 %</atbegshi>-------------------------------------
134 \endinput