5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-atbegshi}[2021-04-29 Patching \string\shipout\space hooks for LuaTeX-ja]
8 % concept: execute all hooks inside yoko direction \vbox
10 \ifltj@ltfilehook@avail
11 %<*ltshipout>-----------------------------------
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 }
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 }
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 }
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
39 %\box_use:N \l__platex_shipout_dummy_box
44 \cs_new_eq:NN \__platex_original_shipout_execute_cont: \__shipout_execute_cont:
45 \cs_set:Npn \__shipout_execute_cont:
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 }
50 \platex_if_direction_yoko:TF {
51 \__platex_original_shipout_execute_cont:
53 \vbox_set:Nn \l__platex_shipout_dummy_box {
54 \platex_direction_yoko: \__platex_original_shipout_execute_cont:
59 %</ltshipout>-----------------------------------
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).
69 \ifdefined\AtBeginShipoutOriginalShipout
70 \let\AtBeginShipoutOriginalShipout\ltj@shipout
73 \DeclareRobustCommand \AtBeginDvi [1]{%
74 \global \setbox \@begindvibox
75 \vbox{\yoko\unvbox \@begindvibox #1}%
77 %% internal macros are locally effective
82 \def\pxabgs@mark{\pxabgs@mark@}
83 \def\pxabgs@fin{\pxabgs@fin@}
85 %% \pxabgs@patch@cmd\CMD{<orig>}{<new>}
86 \def\pxabgs@patch@cmd#1#2#3{%
88 \def\pxabgs@next##1#2##2\pxabgs@mark##3\pxabgs@fin{%
89 \ifx\pxabgs@mark##3\pxabgs@mark\let#1\relax
91 \def\pxabgs@fragment{##2}\def#1{##1#3##2}%
93 \expandafter\pxabgs@next#1\pxabgs@mark#2\pxabgs@mark\pxabgs@fin
98 \ifdefined\AtBegShi@Output
99 \let\pxabgs@AtBegShi@Output\AtBegShi@Output
100 \else\let\pxabgs@AtBegShi@Output\relax\fi
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
111 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
113 \let\protect\AtBegShi@OrgProtect
116 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
118 \let\protect\AtBegShi@OrgProtect
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%
128 \global\let\AtBegShi@Output\pxabgs@AtBegShi@Output
132 %% internal macros are no longer effective
133 %</atbegshi>-------------------------------------