summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/platex-tools/pxeverysel.sty
blob: 8a1a9b5eade4e229c4651349bc316212a5715ee6 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
%
% pxeverysel.sty
% originally written by Takayuki Yato (ZR)
% and modified by Hironobu Yamashita
%
% This package is distributed as part of the platex-tools bundle
% maintained by Hironobu Yamashita
% by courtesy of the original author.
% https://github.com/aminophen/platex-tools
%
% --------------------------------------------------------------------
% [Note]
% Update: version 2021/02/13 v0.9a does nothing, since
% pLaTeX2e 2021-??-?? will support the situation natively.
% --------------------------------------------------------------------
%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pxeverysel}
    [2021/02/13 v0.9b Patch to everysel for (u)pLaTeX]

%% Since LaTeX2e 2021-05-01, everysel.sty is merely
%% an emulation by everysel-ltx.sty from firstaid.

\chardef\pxys@status=\z@
\ifx\IfHookExistsTF\@undefined\else  % >= LaTeX2e 2020-10-01
  \IfHookExistsTF{selectfont}{%      % >= LaTeX2e 2021-05-01
    \chardef\pxys@status=\@ne
  }{}
\fi
\ifnum\pxys@status=\@ne
  % if LaTeX2e and pLaTeX2e are inconsistent, raise an error!
  \ifx\delayed@k@adjustment\@undefined
    \PackageError{pxeverysel}{Inconsistent LaTeX2e/pLaTeX2e combination}\@ehc
  \else
    \PackageInfo{pxeverysel}{This package is no longer needed}%
  \fi
  \RequirePackage{everysel}% input anyway
  \expandafter\endinput
\fi

%% The rest of this package is meant for
%% LaTeX2e 2020-10-01 PL4 or older.

%% in case it's too late ...
\@ifpackageloaded{everysel}{%
  % everysel.sty removes \@EverySelectfont@Init once it is used
  \ifx\@EverySelectfont@Init\undefined
    \PackageError{pxeverysel}{%
      Patch too late!\MessageBreak
      Load pxeverysel earlier}\@ehc
    \expandafter\endinput
  \fi
}{}

%% load it, but ensure that \@EverySelectfont@Init is not executed
%  [Note] everysel.sty contains
%    \AtBeginDocument{\@EverySelectfont@Init}
%  at the end. In most cases, the execution is actually delayed;
%  however,
%    \AtBeginDocument{\RequirePackage{everysel}}
%  can execute it immediately (e.g. found in sidecap.sty).
%  In this case, delay it until the end of pxeverysel.sty.
\ifx\AtBeginDocument\@firstofone
  \def\pxys@begindocumenthook{\let\AtBeginDocument\@firstofone}
  \def\AtBeginDocument{\g@addto@macro\pxys@begindocumenthook}
  \AtEndOfPackage{\pxys@begindocumenthook}
\fi
\RequirePackage{everysel}

%% support for (u)pLaTeX font tracing
\@ifpackageloaded{tracefnt}{%
  \ifx\kanjiskip\@undefined\else\ifx\ucs\@undefined
  \RequirePackage{ptrace}\else\RequirePackage{uptrace}\fi\fi}{}

%--------------------------------------- helpers

%% preparations
\def\pxys@pkgname{pxeverysel}
\def\pxys@warn{\PackageWarningNoLine\pxys@pkgname}

%% unique tokens
\def\pxys@mark{\pxys@mark@}
\def\pxys@fin{\pxys@fin@}

%% \pxys@patch@cmd\CMD{<pre>}{<post>}{<new>}
\@onlypreamble\pxys@patch@cmd
\def\pxys@patch@cmd#1#2#3#4{%
  \def\pxys@next##1#2##2#3##3\pxys@mark##4\pxys@fin{%
    \ifx\pxys@mark##4\pxys@mark
      \let\pxys@fragment\relax
    \else
      \def\pxys@fragment{##2}%
      \def#1{##1#4##3}%
    \fi}%
  \expandafter\pxys@next#1\pxys@mark#2#3\pxys@mark\pxys@fin}

%% \pxys@append@to\CSa\CSb
\@onlypreamble\pxys@append@to
\def\pxys@append@to#1#2{%
  \expandafter\g@addto@macro\expandafter#1\expandafter{#2}}

%% \pxys@term
\let\pxys@term\relax

%---------------------------------------

%% variables
\let\pxys@self@hook\@empty
\let\pxys@everysel@hook\@empty
\@onlypreamble\pxys@selectfont
\let\pxys@selectfont\relax
\@onlypreamble\pxys@org@selectfont
\let\pxys@org@selectfont\relax
\@onlypreamble\pxys@new@selectfont
\let\pxys@new@selectfont\relax

%% \@EverySelectfont@Init redefined
\@onlypreamble\pxys@EverySelectfont@Init
\let\pxys@EverySelectfont@Init\@EverySelectfont@Init
\def\@EverySelectfont@Init{%
  \pxys@preproc
  \pxys@EverySelectfont@Init
  \pxys@postproc}

%% \pxys@preproc
\@onlypreamble\pxys@preproc
\def\pxys@preproc{%
  % prepare
  \expandafter\let\expandafter\pxys@selectfont
      \csname selectfont \endcsname
  \let\pxys@org@selectfont\pxys@selectfont
  % extract "pre-\size@update" insertion
  \pxys@append@to\pxys@selectfont\pxys@term
  \pxys@patch@cmd\pxys@selectfont
    {\pickup@font\font@name}{\size@update\pxys@term}%      % plfonts/ptrace
    {\pickup@font\font@name\pxys@self@hook\pxys@everysel@hook
     \size@update}%
  \ifx\pxys@fragment\relax
    \let\pxys@selectfont\pxys@org@selectfont
    % extract "pre-\enc@update" insertion
    \pxys@patch@cmd\pxys@selectfont
      {\pickup@font\font@name}{\size@update\enc@update}%   % ltfsstrc/tracefnt
      {\pickup@font\font@name\pxys@self@hook\pxys@everysel@hook
       \size@update\enc@update}%
    \ifx\pxys@fragment\relax % failure
      \let\pxys@selectfont\relax
    \else
      \pxys@append@to\pxys@self@hook\pxys@fragment
    \fi
  \else
    \pxys@append@to\pxys@self@hook\pxys@fragment
  \fi
  \let\pxys@new@selectfont\pxys@selectfont
  % prepare for everysel routine
  \let\pxys@CheckCommand\CheckCommand
  \let\CheckCommand\@gobble
  % hack for disabling duplicate font info
  \expandafter\let\expandafter\pxys@ver@tracefnt
    \csname ver@tracefnt.sty\endcsname
  \expandafter\let\csname ver@tracefnt.sty\endcsname\@undefined}

%% \pxys@postproc
\@onlypreamble\pxys@postproc
\def\pxys@postproc{%
  % revert the hack for disabling duplicate font info
  \expandafter\let\csname ver@tracefnt.sty\endcsname\pxys@ver@tracefnt
  \let\pxys@ver@tracefnt\@undefined
  % post handling of everysel routine
  \let\CheckCommand\pxys@CheckCommand
  \let\pxys@CheckCommand\@undefined
  \expandafter\let\expandafter\pxys@selectfont
      \csname selectfont \endcsname
  % extract the code insertion by everysel
  \pxys@patch@cmd\pxys@selectfont
    {\pickup@font\font@name}{\size@update\enc@update}{}%
  \ifx\pxys@fragment\relax % failure
    \let\pxys@new@selectfont\relax
  \else % success
    \pxys@append@to\pxys@everysel@hook\pxys@fragment
  \fi
  % commit the change
  \ifx\pxys@new@selectfont\relax % failure
    \let\pxys@selectfont\pxys@org@selectfont % revert
    \pxys@warn{Failed in patching \string\selectfont}%
  \else % success
    \let\pxys@selectfont\pxys@new@selectfont
  \fi
  \expandafter\let\csname selectfont \endcsname\pxys@selectfont}

%--------------------------------------- done

\endinput
%% EOF