5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-atbegshi}[2022-08-12 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
40 \box_clear:N \l__platex_shipout_dummy_box
45 \cs_new_eq:NN \__platex_original_shipout_execute_cont: \__shipout_execute_cont:
46 \cs_set:Npn \__shipout_execute_cont:
48 \platex_if_box_yoko:NF \l_shipout_box {
49 \vbox_set:Nn \l_shipout_box { \platex_direction_yoko: \box_use:N \l_shipout_box }
51 \platex_if_direction_yoko:TF {
52 \__platex_original_shipout_execute_cont:
54 \vbox_set:Nn \l__platex_shipout_dummy_box {
55 \platex_direction_yoko: \__platex_original_shipout_execute_cont:
57 \box_clear:N \l__platex_shipout_dummy_box
61 %</ltshipout>-----------------------------------
65 \RequirePackage{atbegshi}
66 %<*atbegshi>-------------------------------------
67 % patching atbegshi.sty
68 %%% following codes are almost copied from
69 %%% pxatbegshi.sty 2019/09/07 v0.5 (in platex-tools bundle, by H. Yamashita).
71 \ifdefined\AtBeginShipoutOriginalShipout
72 \let\AtBeginShipoutOriginalShipout\ltj@shipout
75 \DeclareRobustCommand \AtBeginDvi [1]{%
76 \global \setbox \@begindvibox
77 \vbox{\yoko\unvbox \@begindvibox #1}%
79 %% internal macros are locally effective
84 \def\pxabgs@mark{\pxabgs@mark@}
85 \def\pxabgs@fin{\pxabgs@fin@}
87 %% \pxabgs@patch@cmd\CMD{<orig>}{<new>}
88 \def\pxabgs@patch@cmd#1#2#3{%
90 \def\pxabgs@next##1#2##2\pxabgs@mark##3\pxabgs@fin{%
91 \ifx\pxabgs@mark##3\pxabgs@mark\let#1\relax
93 \def\pxabgs@fragment{##2}\def#1{##1#3##2}%
95 \expandafter\pxabgs@next#1\pxabgs@mark#2\pxabgs@mark\pxabgs@fin
100 \ifdefined\AtBegShi@Output
101 \let\pxabgs@AtBegShi@Output\AtBegShi@Output
102 \else\let\pxabgs@AtBegShi@Output\relax\fi
104 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
105 {\let\AtBegShi@OrgProtect\protect}%
106 {\setbox8\vbox\bgroup\yoko\let\AtBegShi@OrgProtect\protect}
107 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
108 {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox}%
109 {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup\setbox8\box\voidb@x}
110 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
113 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
115 \let\protect\AtBegShi@OrgProtect
118 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
120 \let\protect\AtBegShi@OrgProtect
123 % commit the change only when successful
124 \ifx\pxabgs@AtBegShi@Output\relax
125 \@PackageWarningNoLine{lltjp-atbegshi}{%
126 Failed in patching \string\AtBegShi@Output.\MessageBreak
127 This may cause error in tate direction%
130 \global\let\AtBegShi@Output\pxabgs@AtBegShi@Output
134 %% internal macros are no longer effective
135 %</atbegshi>-------------------------------------