summaryrefslogtreecommitdiff
path: root/macros/generic/ifptex/ifptex.sty
blob: a3e63d8d5d73a0aa179ad2036e50cb603595d2ee (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
%%
%% This is file 'ifptex.sty'.
%%
%% Copyright (c) 2008-2021 Takayuki YATO (aka. "ZR")
%%   GitHub:   https://github.com/zr-tex8r
%%   Twitter:  @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%
%
%% avoid multiple loading
\csname\if11bxipIfptexLoaded\fi\endcsname%
%% code guards
\begingroup\count255\catcode61\global\catcode61\catcode48%
\catcode91=1\catcode93=2\xdef\bxipIfptexLoaded[%
\catcode61=\the\count255%
\catcode13=\the\catcode13%
\catcode32=\the\catcode32%
\catcode35=\the\catcode35%
\catcode123=\the\catcode123%
\catcode125=\the\catcode125%
\endlinechar=\the\endlinechar]%
\endgroup\catcode32=10\catcode13=5\endlinechar=13\relax%
\catcode35=6 \catcode123=1 \catcode125=2
\edef\bxipIfptexLoaded{\bxipIfptexLoaded
\catcode33=\the\catcode33%
\catcode34=\the\catcode34%
\catcode39=\the\catcode39%
\catcode45=\the\catcode45%
\catcode46=\the\catcode46%
\catcode47=\the\catcode47%
\catcode58=\the\catcode58%
\catcode60=\the\catcode60%
\catcode62=\the\catcode62%
\catcode63=\the\catcode63%
\catcode64=\the\catcode64%
\catcode91=\the\catcode91%
\catcode93=\the\catcode93%
\catcode96=\the\catcode96%
\relax}
\catcode33=12 % <!>
\catcode34=12 % <">
\catcode39=12 % <'>
\catcode45=12 % <->
\catcode46=12 % <.>
\catcode47=12 % </>
\catcode58=12 % <:>
\catcode60=12 % <<>
\catcode62=12 % <>>
\catcode63=12 % <?>
\catcode64=11 % <@>
\catcode91=12 % <[>
\catcode93=12 % <]>
\catcode96=12 % <`>
\edef\bxip@restore@codes{\bxipIfptexLoaded
  \noexpand\let\noexpand\bxip@restore@codes\relax}
\def\bxipIfptexLoaded{\endinput}

%% check for LaTeX
\ifx\RequirePackage\@undefined %<*!LaTeX>
  \let\bxip@latex=f
  \long\def\bxip@input#1\ProvidesPackage#2[#3]{%
    \def\bxip@input\RequirePackage##1[##2]{\input ##1.sty\relax}%
    \immediate\write-1{Package: #2 #3}}
  \expandafter\bxip@input
\else                          %<*LaTeX>
  \let\bxip@latex=t
  \let\bxip@input\relax
\fi                            %</LaTeX>

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ifptex}[2021/07/01 v2.1 pTeX checker]
\def\bxip@pkgname{ifptex}

%% packages
\ifx\newif\@undefined\else
\bxip@input
\RequirePackage{iftex}[2013/04/04]% v0.2
\fi

%=======================================
\begingroup % entering a big group
%--------------------------------------- helpers

%% \bxip@csletcs{<csnameA>}{<csnameB>}
\def\bxip@csletcs#1#2{%
  \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}
%% \bxip@true{<csname>}
\def\bxip@true#1{%
  \expandafter\let\csname#1\endcsname\iftrue}
%% \bxip@false{<csname>}
\def\bxip@false#1{%
  \expandafter\let\csname#1\endcsname\iffalse}

%% switches
\bxip@false{ifbxip@ok}

%% \bxip@test@primitive\CS
\def\bxip@test@primitive#1{%
  \edef\bxip@tmpa{\string#1}\edef\bxip@tmpb{\meaning#1}%
  \ifx\bxip@tmpa\bxip@tmpb \bxip@true{ifbxip@ok}%
  \else \bxip@false{ifbxip@ok}%
  \fi}

%% \bxip@with@default{<arg>}\CS
\gdef\bxip@with@default#1#2{%
  \def\bxip@tmpa{#2}\def\bxip@tmpb{#2[#1]}%
  \futurelet\bxip@tok\bxip@with@default@a}
\gdef\bxip@with@default@a{%
  \ifx[\bxip@tok\expandafter\bxip@tmpa%]
  \else \expandafter\bxip@tmpb
  \fi}

%% \bxip@check@version{<current>}{<required>}{<label>}
\global\countdef\bxip@cnta=255
\gdef\bxip@check@version#1#2#3{%
  \ifnum#1<#2\relax
    \begingroup
      \bxip@cnta=#2\relax \advance\bxip@cnta100000\relax
      \expandafter\bxip@check@version@a\the\bxip@cnta\relax{#3}%
    \endgroup
  \fi}
\gdef\bxip@check@version@a#1#2#3#4#5#6\relax#7{%
  \bxip@err@required{#7 v.>=\number#2#3#4.#5#6}}

%% \bxip@Require\ifXXX{<string>}\fi
% (Equivalent to \IFTEX@Require of iftex.)
\gdef\bxip@Require#1#2#3{%
  #1\else
    \newlinechar64\relax
    \errorcontextlines-1\relax
    \immediate\write20{@
    ********************************************@
    * #2 is required to compile this document.@
    * Sorry!@
    ********************************************}%
    % do a hard stop
    \batchmode\read-1to\bxip@tmpa
  #3}
\gdef\bxip@err@required#1{\bxip@Require\iftrue{#1}\fi}

%% \bxip@protected
\let\bxip@protected\protected
\ifx\directlua\@undefined\else
  \directlua{tex.enableprimitives('bxip@', {'protected'})}
\fi
\bxip@csletcs{bxip@protected}{bxip@protected}

%--------------------------------------- guess version

%% \bxip@uptex@new@version
\global\mathchardef\bxip@uptex@new@version=19

%%<+> \upTeXguessedversion
% NB: The value of \upTeXguessedversion on pTeX is zero.
\global\mathchardef\upTeXguessedversion=0
\bxip@test@primitive\ptexversion\ifbxip@ok %<*version>
% If \(u)ptexversion is supported...

  % get version from \uptexversion/revision
  \bxip@test@primitive\uptexversion\ifbxip@ok
  \bxip@test@primitive\uptexrevision\ifbxip@ok
    \def\bxip@tmpa#1#2#3#4\relax{%
      \chardef\bxip@tmpa=0\relax
      \ifx.#1\afterassignment\bxip@tmpb\chardef\bxip@tmpa=0#2#3\relax
      \fi}
    \def\bxip@tmpb#1\relax{}
    \expandafter\bxip@tmpa\uptexrevision????\relax
    \bxip@cnta=\uptexversion\relax
    \multiply\bxip@cnta100\relax
    \advance\bxip@cnta\bxip@tmpa
    \global\mathchardef\upTeXguessedversion=\bxip@cnta
  \fi\fi

\else               %<*!version>
% If \(u)ptexversion is not supported...

% if \ucs exists, then gv >= 1
\bxip@test@primitive\ucs\ifbxip@ok
  \global\mathchardef\upTeXguessedversion=1
  % if \enablecjktoken exists, then gv >= 6
  \bxip@test@primitive\enablecjktoken\ifbxip@ok
    \global\mathchardef\upTeXguessedversion=6
    % if \kchar exists, then gv >= 10
    \bxip@test@primitive\kchar\ifbxip@ok
      \global\mathchardef\upTeXguessedversion=10
      % if \forcecjktoken exists, then gv >= 19
      \bxip@test@primitive\forcecjktoken\ifbxip@ok
        \global\mathchardef\upTeXguessedversion=19
      \fi
    \fi
  \fi
\fi

\fi                 %</version>

%--------------------------------------- public stuffs
% Note:
% 1) Names '\ifFooTeX' were used in old iftex.
% 2) Names '\iffootex' are used in ifxetex/ifluatex/....
% My preferences used to be:
% - '\ifwhateverFooTeX' and '\RequireWhateverFooTeX'.
% But now I adopt the preferences of new iftex:
% - '\ifwhateverfootex' and '\RequireWhateverFooTeX'.
% I also provide aliases '\ifwhateverFooTeX' for compatibility.

%%<+> \ifpTeX
\global\bxip@false{ifpTeX}
\bxip@test@primitive\kanjiskip\ifbxip@ok
  \global\bxip@true{ifpTeX}
\fi
%%<+> \ifptex == \ifpTeX
\global\bxip@csletcs{ifptex}{ifpTeX}

%%<+> \ifupTeX
\global\bxip@false{ifupTeX}
%%<+> \ifnativeupTeX
\global\bxip@false{ifnativeupTeX}
\ifnum\upTeXguessedversion>0
  \global\bxip@true{ifupTeX}
  % native-ness check
  \ifnum\ucs"3000="3000 \global\bxip@true{ifnativeupTeX}\fi
\fi
%%<+> \ifuptex == \ifupTeX
\global\bxip@csletcs{ifuptex}{ifupTeX}
%%<+> \ifnativeuptex == \ifnativeupTeX
\global\bxip@csletcs{ifnativeuptex}{ifnativeupTeX}

%%<+> \ifpTeXng
\global\bxip@false{ifpTeXng}
\bxip@test@primitive\ngbanner\ifbxip@ok
  \global\bxip@true{ifpTeXng}
\fi
%%<+> \ifptexng == \ifpTeXng
\global\bxip@csletcs{ifptexng}{ifpTeXng}

%%<+> \ifstrictpTeX
\global\bxip@false{ifstrictpTeX}
\ifpTeX \ifupTeX\else
  \global\bxip@true{ifstrictpTeX}
\fi\fi
%%<+> \ifstrictptex == \ifstrictpTeX
\global\bxip@csletcs{ifstrictptex}{ifstrictpTeX}

%%<+> \ifstrictupTeX
\global\bxip@false{ifstrictupTeX}
\ifupTeX \ifpTeXng\else
  \global\bxip@true{ifstrictupTeX}
\fi\fi
%%<+> \ifstrictuptex == \ifstrictupTeX
\global\bxip@csletcs{ifstrictuptex}{ifstrictupTeX}

%%<+> \ifstrictpTeXng (== \ifpTeXng, for now)
\global\bxip@csletcs{ifstrictpTeXng}{ifpTeXng}
%%<+> \ifstrictptexng == \ifstrictpTeXng
\global\bxip@csletcs{ifstrictptexng}{ifstrictpTeXng}

%%<+> \RequirepTeX
\bxip@protected\gdef\RequirepTeX{%
  \bxip@Require\ifpTeX{(u)pTeX}\fi}
%%<+> \RequireStrictpTeX
\bxip@protected\gdef\RequireStrictpTeX{%
  \bxip@Require\ifstrictpTeX{pTeX (not upTeX)}\fi}
%%<+> \RequireupTeX
\bxip@protected\gdef\RequireupTeX{%
  \bxip@Require\ifupTeX{upTeX}\fi}
%%<+> \RequireStrictupTeX
\bxip@protected\gdef\RequireStrictupTeX{%
  \bxip@Require\ifstrictupTeX{upTeX (not pTeX-ng)}\fi}
%%<+> \RequireNativeupTeX
\bxip@protected\gdef\RequireNativeupTeX{%
  \bxip@Require\ifnativeupTeX{upTeX in Unicode}\fi}
%%<+> \RequirepTeXng
\bxip@protected\gdef\RequirepTeXng{%
  \bxip@Require\ifpTeXng{pTeX-ng}\fi}
%%<+> \RequireStrictpTeXng
\bxip@protected\gdef\RequireStrictpTeXng{%
  \bxip@Require\ifstrictpTeXng{pTeX-ng}\fi}

%--------------------------------------- deprecated stuffs

%%<+>D \ifNativeupTeX == \ifnativeupTeX
\global\bxip@csletcs{ifNativeupTeX}{ifnativeupTeX}
%%<+>D \RequirenativeupTeX == \RequireNativeupTeX
\gdef\RequirenativeupTeX{\RequireNativeupTeX}

%%<+>D \ifnewupTeX
\global\bxip@false{ifnewupTeX}
\ifnum\upTeXguessedversion<\bxip@uptex@new@version\else
  \global\bxip@true{ifnewupTeX}
\fi

%%<+>D \RequireNewupTeX
\gdef\RequireNewupTeX{%
  \bxip@with@default\bxip@uptex@new@version\bxip@require@new@uptex@a}
\gdef\bxip@require@new@uptex@a[#1]{%
  \ifupTeX
    \bxip@check@version\upTeXguessedversion{#1}{upTeX}%
  \else \bxip@err@required{upTeX}%
  \fi}

%%<+>D \RequireNativeNewupTeX
\gdef\RequireNativeNewupTeX{%
  \bxip@with@default\bxip@uptex@new@version\bxip@require@new@uptex@b}
\gdef\bxip@require@new@uptex@b[#1]{%
  \ifnativeupTeX
    \bxip@check@version\upTeXguessedversion{#1}{upTeX in Unicode}%
  \else \bxip@err@required{upTeX in Unicode}%
  \fi}

%--------------------------------------- all done
\endgroup
% clean up
\let\bxip@latex\@undefined
\let\bxip@input\@undefined
\let\bxip@protected\@undefined
\bxip@restore@codes
\endinput
%% EOF