5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjp-atbegshi}[2020-09-27 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 \cs_new_eq:NN \__platex_original_shipout_execute_cont: \__shipout_execute_cont:
17 \cs_set:Npn \__shipout_execute_cont:
19 % if \l_shipout_box is not a \yoko-box (= horizontal writing),
20 % then make it a \yoko-box behorehand.
21 \unless\ifnum\ltjgetparameter{boxdir}{\l_shipout_box}=4
22 \vbox_set:Nn \l_shipout_box { \yoko \box_use:N \l_shipout_box }
24 % if the current direction is not \yoko,
25 % then enclose \__shipout_execute_cont: with
26 % a dummy \yoko-box named \l__platex_shipout_dummy_box.
27 \ifnum\ltjgetparameter{direction}=4
28 \__platex_original_shipout_execute_cont:
30 \vbox_set:Nn \l__platex_shipout_dummy_box {
31 \yoko \__platex_original_shipout_execute_cont:
33 % [Limitation] the code above may discard some contents,
34 % so we'd like to put it back by \box\l__platex_shipout_dummy_box.
35 % however, an infinite loop occurs if we uncomment the line below
37 %\box_use:N \l__platex_shipout_dummy_box
40 %</ltshipout>-----------------------------------
44 \RequirePackage{atbegshi}
45 %<*atbegshi>-------------------------------------
46 % patching atbegshi.sty
47 %%% following codes are almost copied from
48 %%% pxatbegshi.sty 2019/09/07 v0.5 (in platex-tools bundle, by H. Yamashita).
50 \ifdefined\AtBeginShipoutOriginalShipout
51 \let\AtBeginShipoutOriginalShipout\ltj@shipout
54 \DeclareRobustCommand \AtBeginDvi [1]{%
55 \global \setbox \@begindvibox
56 \vbox{\yoko\unvbox \@begindvibox #1}%
58 %% internal macros are locally effective
63 \def\pxabgs@mark{\pxabgs@mark@}
64 \def\pxabgs@fin{\pxabgs@fin@}
66 %% \pxabgs@patch@cmd\CMD{<orig>}{<new>}
67 \def\pxabgs@patch@cmd#1#2#3{%
69 \def\pxabgs@next##1#2##2\pxabgs@mark##3\pxabgs@fin{%
70 \ifx\pxabgs@mark##3\pxabgs@mark\let#1\relax
72 \def\pxabgs@fragment{##2}\def#1{##1#3##2}%
74 \expandafter\pxabgs@next#1\pxabgs@mark#2\pxabgs@mark\pxabgs@fin
79 \ifdefined\AtBegShi@Output
80 \let\pxabgs@AtBegShi@Output\AtBegShi@Output
81 \else\let\pxabgs@AtBegShi@Output\relax\fi
83 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
84 {\let\AtBegShi@OrgProtect\protect}%
85 {\setbox8\vbox\bgroup\yoko\let\AtBegShi@OrgProtect\protect}
86 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
87 {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox}%
88 {\AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox\egroup}
89 \pxabgs@patch@cmd\pxabgs@AtBegShi@Output
92 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
94 \let\protect\AtBegShi@OrgProtect
97 \setbox\AtBeginShipoutBox\box\AtBeginShipoutBox
99 \let\protect\AtBegShi@OrgProtect
102 % commit the change only when successful
103 \ifx\pxabgs@AtBegShi@Output\relax
104 \@PackageWarningNoLine{lltjp-atbegshi}{%
105 Failed in patching \string\AtBegShi@Output.\MessageBreak
106 This may cause error in tate direction%
109 \global\let\AtBegShi@Output\pxabgs@AtBegShi@Output
113 %% internal macros are no longer effective
114 %</atbegshi>-------------------------------------