summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/plautopatch/pxesopic.sty
blob: f020501e947f2cf9ff676f77ee45f06b73ff1081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%
% pxesopic.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the plautopatch bundle.
% https://github.com/aminophen/plautopatch
%
% This package is expected to be compatible with
%   * eso-pic.sty
%     ????/??/?? v?.? -- 2018/04/12 v2.0h
%
% --------------------------------------------------------------
% [Note]
% The package ``pxesopic.sty'' relies heavily on internals
% of ``plautopatch.sty''
% --------------------------------------------------------------
%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pxesopic}
    [2020/09/27 v0.2a Patch to eso-pic for tombow]

%% preparations
\def\pxesop@pkgname{pxesopic}
\def\pxesop@error{\PackageError\pxesop@pkgname}
\def\pxesop@warn{\PackageWarningNoLine\pxesop@pkgname}
\let\pxesop@debug\@gobble
\def\pxesop@debug#1{\typeout{\pxesop@pkgname: [DEBUG] #1}}% for debug

%% hooks
\ifx\declare@file@substitution\@undefined
  % LaTeX2e 2020-02-02 PL5 or older
  \RequirePackage{filehook}
  \let\pxesop@ExecuteAfterPackage=\AtEndOfPackageFile
  \let\pxesop@ExecuteBeforePackage=\AtBeginOfPackageFile
\else
  % LaTeX2e 2020-10-01 or newer
  \def\pxesop@ExecuteAfterPackage#1{\AddToHook{package/after/#1}}
  \def\pxesop@ExecuteBeforePackage#1{\AddToHook{package/before/#1}}
\fi

%% the contents of \AtBeginShipout is dependent on \iftombow;
%% delay execution of \AtBeginShipout inside ``eso-pic.sty''
%% until \AtBeginDocument, to support both (u)pLaTeX kernel
%% and ``gentombow.sty''
\RequirePackage{atbegshi}% eso-pic requires atbegshi
\pxesop@ExecuteBeforePackage{eso-pic}{\pxesop@before}
\pxesop@ExecuteAfterPackage{eso-pic}{\pxesop@after}
%
\def\pxesop@before{%
  \let\pxesop@AtBeginShipout\AtBeginShipout
  \def\AtBeginShipout##1{\def\pxesop@hook{##1}}% hide it
  \pxesop@debug{\noexpand\AtBeginShipout disabled}%
  \let\pxesop@before\relax
}
\def\pxesop@after{%
  \let\AtBeginShipout\pxesop@AtBeginShipout    % restore
  \let\pxesop@AtBeginShipout\relax
  \pxesop@debug{\noexpand\AtBeginShipout restored}%
  \let\@unknownoptionerror\relax %% avoid an error
  \pxesop@debug{\noexpand\@unknownoptionerror disabled}%
  \let\pxesop@after\relax
}
%%

%% load it; be careful not to cause unknown option error!
\expandafter\ifx\csname @unknownoptionerror\endcsname
  \pxesop@error{Failed to save \noexpand\@unknownoptionerror}\@ehc
\fi
\let\pxesop@unknownoptionerror\@unknownoptionerror
%
\chardef\pxesop@status\z@
\@ifpackageloaded{plautopatch}{%
  \expandafter\ifx\csname platpc@begin@eso-pic\endcsname\relax
    % ``plautopatch.sty'' is loaded but the macro is \relax
    % => means that ``pxesopic.sty'' is automatically loaded
    \chardef\pxesop@status\@ne
  \fi
}{}
%
%% pass all options to keyval-style ``eso-pic.sty''
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{eso-pic}}
\ProcessOptions\relax
\RequirePackage{eso-pic}
%
%% recover the error
\ifnum\pxesop@status>\z@ % auto
  \def\pxesop@pkgtohook{eso-pic}%
  % note that ``plautopatch.sty'' discards the hook
  % on LaTeX2e 2020-02-02 PL5 or older
  \ifx\declare@file@substitution\@undefined
    \let\pxesop@pkgtohook\pxesop@pkgname
    % throw an error for unsupported usage
    % [FIXME] the error below is actually unnecessary when
    % none of ``eso-pic.sty'' options is used; how to detect that?
    \pxesop@error{Try loading \pxesop@pkgname\space by hand}\@ehc
  \fi
\else
  \let\pxesop@pkgtohook\pxesop@pkgname
\fi
\pxesop@ExecuteAfterPackage\pxesop@pkgtohook{%
  \let\@unknownoptionerror\pxesop@unknownoptionerror
  \pxesop@debug{\noexpand\@unknownoptionerror restored}%
}
%%

%% delayed to detect \iftombow status
\AtBeginDocument{%
  \ifx\tombowtrue\@undefined
    \pxesop@warn{Tombow feature unavailable, aborting}%
  \fi
  \iftombow \pxesop@new \else \pxesop@orig \fi}%
%
%% for \iftombow is FALSE => restore from ``eso-pic.sty''
\expandafter\def\expandafter\pxesop@orig\expandafter{%
  \expandafter\AtBeginShipout\expandafter{\pxesop@hook}}
%
%% for \iftombow is TRUE => redefine by ``pxesopic.sty''
\def\pxesop@new{%
  %% \AtStockLowerLeft: based on TRUE of \ESO@isMEMOIR
  \renewcommand\AtStockLowerLeft[1]{%
    \begingroup
      \@tempdima=-\stockwidth
      \advance\@tempdima\paperwidth
      \@tempdimb=-\stockheight
      \advance\@tempdimb\paperheight
      %% specific BEGIN
      \advance\@tempdima 1in\relax
      \advance\@tempdimb 1in\relax
      %% specific END
      \AtPageLowerLeft{%
        \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){##1}%
      }%
    \endgroup
  }% ===
  %% \AtStockUpperLeft: based on TRUE of \ESO@isMEMOIR
  \renewcommand\AtStockUpperLeft[1]{%
    \AtStockLowerLeft{%
      \put(0,\LenToUnit{\stockheight}){##1}%
    }%
  }% ===
  %% \AtStockCenter: based on TRUE of \ESO@isMEMOIR
  \renewcommand\AtStockCenter[1]{%
    \AtStockLowerLeft{%
      \put(\LenToUnit{.5\stockwidth},\LenToUnit{.5\stockheight}){##1}%
    }%
  }%
  %% \AtTextUpperLeft: same as FALSE of \ESO@isMEMOIR
  %  (no change)
  %
  %% \AtBeginShipout: based on TRUE of \ESO@isMEMOIR
  \AtBeginShipout{%
    \@tempdima=\dimexpr(\stockwidth-\paperwidth)/2\relax
    \@tempdimb=-\dimexpr(\stockheight+\paperheight)/2\relax
    \ifESO@texcoord
      \advance\@tempdimb\paperheight % [FIXME] not sure!
    \fi
    \nointerlineskip
    \AtBeginShipoutUpperLeft{%
      \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){%
        \ESO@HookIIIBG\ESO@HookIBG\ESO@HookIIBG
        \global\let\ESO@HookIIBG\@empty
      }%
    }%
    \AtBeginShipoutUpperLeftForeground{%
      \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){%
        \ESO@HookIFG\ESO@HookIIFG\ESO@HookIIIFG
        \global\let\ESO@HookIIFG\@empty
      }%
    }%
  }% ===
}
%%

\endinput
%% EOF