summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty')
-rw-r--r--Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty76
1 files changed, 76 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty b/Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty
new file mode 100644
index 00000000000..91e107dc790
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/platex-tools/pxatbegshi.sty
@@ -0,0 +1,76 @@
+%
+% pxatbegshi.sty
+% based on H. Kitagawa's code on GitHub:texjporg/tex-jp-build#21
+% and modified by Hironobu Yamashita
+%
+% This package is distributed as part of the platex-tools bundle
+% maintained by Hironobu Yamashita
+% https://github.com/aminophen/platex-tools
+%
+
+%% package declaration
+\NeedsTeXFormat{pLaTeX2e}
+\ProvidesPackage{pxatbegshi}
+ [2017/11/04 v0.2 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
+ \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