OSDN Git Service

import platex/fcd26df6
[luatex-ja/luatexja.git] / src / patches / lltjfont.sty
1 %
2 % lltjfont.sty: derived from plfonts.dtx in pLaTeX.
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{lltjfont}[2020/03/27 Patch to NFSS2 for LuaTeX-ja]
7
8 %% patching \DeclareTextComposite
9 \def\ltj@chardef@text@cmd#1{%
10   \let\@ifdefinable\@@ifdefinable%
11   \edef\ltj@chardef@text@cmd@name{\expandafter\@gobble\string#1}%
12   \afterassignment\ltj@chardef@text@cmd@\ltj@tempcnta
13 }
14 \def\ltj@chardef@text@cmd@{%
15   \ifnum\ltj@tempcnta>"7F
16     \expandafter\edef\csname \ltj@chardef@text@cmd@name\endcsname{%
17       \noexpand\ltjalchar\the\ltj@tempcnta\space
18     }%
19   \else
20     \expandafter\chardef\csname \ltj@chardef@text@cmd@name\endcsname\ltj@tempcnta
21   \fi
22 }
23 \def\DeclareTextSymbol#1#2#3{%
24   \@dec@text@cmd\ltj@chardef@text@cmd#1{#2}#3\relax
25 }
26
27 \let\ltj@temp@DeclareTextComposite=\DeclareTextComposite
28 \def\DeclareTextComposite#1#2#3#4{}%
29 \input{tuenc.def}
30 \let\DeclareTextComposite=\ltj@temp@DeclareTextComposite
31 \expandafter\patchcmd\csname TU\string\textasteriskcentered\endcsname{\char}{\ltjalchar}{}{}
32
33
34 \let\k@encoding\@empty
35 \let\ck@encoding\@empty
36 % LuaTeX-ja uses JY3 and JT3 encodings.
37 \def\cy@encoding{JY3}\def\ct@encoding{JT3}
38
39 \let\k@family\@empty
40 \let\k@series\@empty
41 \let\k@shape\@empty
42 \def\curr@kfontshape{\k@encoding/\k@family/\k@series/\k@shape}
43 \def\rel@fontshape{\f@encoding/\f@family/\f@series/\f@shape}
44 \ifdefined\Cht\else\newdimen\Cht\fi
45 \ifdefined\cht\else\newdimen\cht\fi
46 \ifdefined\Cdp\else\newdimen\Cdp\fi
47 \ifdefined\cdp\else\newdimen\cdp\fi
48 \ifdefined\Cwd\else\newdimen\Cwd\fi
49 \ifdefined\cwd\else\newdimen\cwd\fi
50 \ifdefined\Cvs\else\newdimen\Cvs\fi
51 \ifdefined\cvs\else\newdimen\cvs\fi
52 \ifdefined\Chs\else\newdimen\Chs\fi
53 \ifdefined\chs\else\newdimen\chs\fi
54 \ifdefined\cHT\else\newdimen\cHT\fi
55 %\let\afont\font
56
57 \let\ystrutbox\strutbox
58 \newbox\dstrutbox
59 \newbox\tstrutbox
60 \newbox\zstrutbox
61 \def\strutbox{%
62   \ifnum\ltjgetparameter{direction}=1 \dstrutbox       % dtou
63   \else\ifnum\ltjgetparameter{direction}=4 \ystrutbox  % yoko
64   \else\tstrutbox  % tate and utod
65   \fi\fi
66 }
67 \DeclareRobustCommand\strut{\relax
68   \ifnum\ltjgetparameter{direction}=1 % dtou
69     \ifmmode\copy\dstrutbox\else\unhcopy\dstrutbox\fi
70   \else\ifnum\ltjgetparameter{direction}=4 % yoko
71     \ifmmode\copy\ystrutbox\else\unhcopy\ystrutbox\fi
72   \else % tate and utod
73     \ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi
74   \fi\fi
75 }
76
77 \DeclareRobustCommand\ystrut{\relax\hbox{\ltj@@orig@yoko
78    \ifmmode\copy\ystrutbox\else\unhcopy\ystrutbox\fi}}
79 \DeclareRobustCommand\tstrut{\relax\hbox{\ltj@@orig@tate
80    \ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi}}
81 \DeclareRobustCommand\dstrut{\relax\hbox{\ltj@@orig@dtou
82    \ifmmode\copy\dstrutbox\else\unhcopy\dstrutbox\fi}}
83 \DeclareRobustCommand\zstrut{\relax\hbox{\ltj@@orig@utod
84    \ifmmode\copy\zstrutbox\else\unhcopy\zstrutbox\fi}}
85
86 {%
87   \def\cdp@elt#1#2#3#4{%
88     \directlua{luatexja.jfont.add_fenc_list('\luatexluaescapestring{#1}')}}%
89   \cdp@list%
90 }
91
92 \def\DeclareFontEncoding{%
93   \begingroup
94   \nfss@catcodes
95   \expandafter\endgroup
96   \DeclareFontEncoding@}
97 \def\DeclareFontEncoding@#1#2#3{%
98   \expandafter
99   \ifx\csname T@#1\endcsname\relax
100      \def\cdp@elt{\noexpand\cdp@elt}%
101      \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
102                     {\default@family}{\default@series}%
103                     {\default@shape}}%
104      \expandafter\let\csname#1-cmd\endcsname\@changed@cmd
105      \directlua{luatexja.jfont.add_fenc_list('\luatexluaescapestring{#1}')}%
106   \else
107      \@font@info{Redeclaring font encoding #1}%
108   \fi
109   \global\@namedef{T@#1}{#2}%
110   \global\@namedef{M@#1}{\default@M#3}%
111   \xdef\LastDeclaredEncoding{#1}%
112   }
113 \def\DeclareKanjiEncoding#1{%
114   \@latex@warning{%
115      The \string\DeclareKanjiEncoding\space is obsoleted command.  Please use
116      \MessageBreak
117      the \string\DeclareTateKanjiEncoding\space for `Tate-kumi' encoding, and
118      \MessageBreak
119      the \string\DeclareYokoKanjiEncoding\space for `Yoko-kumi' encoding.
120      \MessageBreak
121      I treat the `#1' encoding as `Yoko-kumi'.}
122   \DeclareYokoKanjiEncoding{#1}%
123 }
124 \def\DeclareYokoKanjiEncoding{%
125   \begingroup
126   \nfss@catcodes
127   \expandafter\endgroup
128   \DeclareYokoKanjiEncoding@}
129 \def\DeclareYokoKanjiEncoding@#1#2#3{%
130   \expandafter\ifx\csname T@#1\endcsname\relax
131     \def\cdp@elt{\noexpand\cdp@elt}%
132     \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
133                     {\default@k@family}{\default@k@series}%
134                     {\default@k@shape}}%
135     \expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
136     \directlua{luatexja.jfont.add_kyenc_list('\luatexluaescapestring{#1}')}%
137   \else
138     \@font@info{Redeclaring KANJI (yoko) font encoding #1}%
139   \fi
140   \global\@namedef{T@#1}{#2}%
141   \global\@namedef{M@#1}{\default@KM#3}%
142   }
143 \def\DeclareTateKanjiEncoding{%
144   \begingroup
145   \nfss@catcodes
146   \expandafter\endgroup
147   \DeclareTateKanjiEncoding@}
148 \def\DeclareTateKanjiEncoding@#1#2#3{%
149   \expandafter\ifx\csname T@#1\endcsname\relax
150     \def\cdp@elt{\noexpand\cdp@elt}%
151     \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
152                     {\default@k@family}{\default@k@series}%
153                     {\default@k@shape}}%
154     \expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
155     \directlua{luatexja.jfont.add_ktenc_list('\luatexluaescapestring{#1}')}%
156   \else
157     \@font@info{Redeclaring KANJI (tate) font encoding #1}%
158   \fi
159   \global\@namedef{T@#1}{#2}%
160   \global\@namedef{M@#1}{\default@KM#3}%
161   }
162 \@onlypreamble\DeclareKanjiEncoding
163 \@onlypreamble\DeclareYokoKanjiEncoding
164 \@onlypreamble\DeclareYokoKanjiEncoding@
165 \@onlypreamble\DeclareTateKanjiEncoding
166 \@onlypreamble\DeclareTateKanjiEncoding@
167 \def\DeclareKanjiEncodingDefaults#1#2{%
168   \ifx\relax#1\else
169     \ifx\default@KT\@empty\else
170       \@font@info{Overwriting KANJI encoding scheme text defaults}%
171     \fi
172     \gdef\default@KT{#1}%
173   \fi
174   \ifx\relax#2\else
175     \ifx\default@KM\@empty\else
176       \@font@info{Overwriting KANJI encoding scheme math defaults}%
177     \fi
178     \gdef\default@KM{#2}%
179   \fi}
180 \let\default@KT\@empty
181 \let\default@KM\@empty
182 \@onlypreamble\DeclareKanjiEncodingDefaults
183 \def\DeclareFontFamily#1#2#3{%
184  \@ifundefined{T@#1}%
185     {\@latex@error{Encoding scheme `#1' unknown}\@eha}%
186     {\def\reserved@a{#3}%
187      \global
188      \expandafter\let\csname #1+#2\expandafter\endcsname
189             \ifx \reserved@a\@empty
190               \@empty
191             \else \reserved@a
192             \fi
193      \directlua{luatexja.jfont.add_ffam('\luatexluaescapestring{#2}')}%
194     }%
195 }
196 \def\DeclareKanjiFamily#1#2#3{%
197  \@ifundefined{T@#1}%
198     {\@latex@error{KANJI Encoding scheme `#1' unknown}\@eha}%
199     {\def\reserved@a{#3}%
200      \global
201      \expandafter\let\csname #1+#2\expandafter\endcsname
202             \ifx \reserved@a\@empty
203               \@empty
204             \else \reserved@a
205             \fi
206      \directlua{luatexja.jfont.add_kfam('\luatexluaescapestring{#2}')}%
207      }%
208 }
209 \def\DeclareKanjiSubstitution#1#2#3#4{%
210   \expandafter\ifx\csname T@#1\endcsname\relax
211     \@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
212   \else
213     \begingroup
214        \def\reserved@a{#1}%
215        \toks@{}%
216        \def\cdp@elt##1##2##3##4{%
217          \def\reserved@b{##1}%
218          \ifx\reserved@a\reserved@b
219            \addto@hook\toks@{\cdp@elt{#1}{#2}{#3}{#4}}%
220          \else
221            \addto@hook\toks@{\cdp@elt{##1}{##2}{##3}{##4}}%
222          \fi}%
223        \cdp@list
224        \xdef\cdp@list{\the\toks@}%
225     \endgroup
226     \global\@namedef{D@#1}{\def\default@k@family{#2}%
227                            \def\default@k@series{#3}%
228                            \def\default@k@shape{#4}}%
229   \fi}
230 \let\wrong@kfontshape\wrong@fontshape
231 \patchcmd\wrong@kfontshape{\default@shape}{\default@k@shape}{}{}
232 \patchcmd\wrong@kfontshape{\default@series}{\default@k@series}{}{}
233 \patchcmd\wrong@kfontshape{\default@family}{\default@k@family}{}{}
234 \@onlypreamble\DeclareKanjiSubstitution
235 \def\DeclareErrorKanjiFont#1#2#3#4#5{%
236    \xdef\error@kfontshape{%
237       \noexpand\expandafter\noexpand\split@name\noexpand\string
238       \expandafter\noexpand\csname#1/#2/#3/#4/#5\endcsname
239       \noexpand\@nil}%
240    \gdef\default@k@family{#2}%
241    \gdef\default@k@series{#3}%
242    \gdef\default@k@shape{#4}%
243    }
244 \@onlypreamble\DeclareErrorKanjiFont
245
246 \newif\ifltjselectfont@force@define
247 \def\DeclareFixedFont#1#2#3#4#5#6{%
248    \begingroup
249       \math@fontsfalse
250       \every@math@size{}%
251       \fontsize{#6}\z@
252       \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#2}')}\ifin@%
253             \ltjselectfont@force@definetrue
254         \usekanji{#2}{#3}{#4}{#5}%
255         \global\let#1\getjfont
256             \ltjselectfont@force@definefalse
257       \else
258         \directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{#2}')}\ifin@%
259               \ltjselectfont@force@definetrue
260           \usekanji{#2}{#3}{#4}{#5}%
261           \global\let#1\gettfont
262               \ltjselectfont@force@definefalse
263         \else
264           \useroman{#2}{#3}{#4}{#5}%
265           \global\expandafter\let\expandafter#1\the\font
266         \fi
267       \fi
268    \endgroup
269   }
270 \def\DLMfontsw@standard#1#2#3{#1{#2{#3}}}
271 \def\reDeclareMathAlphabet#1#2#3{%
272   \ifdefined#2
273     \@temptokena\expandafter{#2}%
274   \else
275     \@temptokena{#2}%
276   \fi
277   \ifdefined#3
278     \toks0\expandafter{#3}%
279   \else
280     \toks0{#3}%
281   \fi
282   \long\protected\edef#1{%
283     \noexpand\DLMfontsw@standard{\the\@temptokena}{\the\toks0}}%
284 }
285 \@onlypreamble\reDeclareMathAlphabet
286 \def\all@shape{all}%
287 \def\DeclareRelationFont#1#2#3#4#5#6#7#8{%
288   \def\rel@shape{#4}%
289   \ifx\rel@shape\@empty
290      \global
291      \expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
292        \romanencoding{#5}\romanfamily{#6}%
293        \romanseries{#7}}%
294   \else
295      \global
296      \expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
297        \romanencoding{#5}\romanfamily{#6}%
298        \romanseries{#7}\romanshape{#8}}%
299   \fi
300 }
301 \def\SetRelationFont#1#2#3#4#5#6#7#8{%
302   \def\rel@shape{#4}%
303   \ifx\rel@shape\@empty
304      \expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
305        \romanencoding{#5}\romanfamily{#6}%
306        \romanseries{#7}}%
307   \else
308      \expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
309        \romanencoding{#5}\romanfamily{#6}%
310        \romanseries{#7}\romanshape{#8}}%
311   \fi
312 }
313 \newif\if@knjcmd
314 \DeclareRobustCommand\userelfont{\@knjcmdtrue}
315
316
317 \RequirePackage{everysel}
318 \let\ltj@@EverySelectfont@Init=\@EverySelectfont@Init
319 \expandafter\expandafter\expandafter\let
320 \expandafter\expandafter\csname ltj@@orig@selectfont\endcsname\csname selectfont\space\endcsname
321 \@EverySelectfont@Init
322 %\let\ltj@@font@info\@font@info
323 %\let\ltj@@font@warning\@font@warning
324 \def\@EverySelectfont@Init{%
325   \expandafter\let\csname selectfont\space \endcsname \ltj@@orig@selectfont
326   \ltj@@EverySelectfont@Init
327 }
328 \def\ltj@selectfont@tate{%
329   \let\k@encoding\ct@encoding
330   \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
331   \pickup@tfont
332   \ifnum\ltjgetparameter{direction}=3 \font@name
333     \ltj@@does@alt@set{\curr@kfontshape}{%
334       % alt fonts の定義
335       \directlua{luatexja.jfont.output_alt_font_cmd('t', '\luatexluaescapestring{\curr@kfontshape}')}%
336       % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
337       \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
338     }%
339   \fi}
340 \def\ltj@selectfont@yoko{%
341   \let\k@encoding\cy@encoding
342   \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
343   \pickup@jfont
344   \unless\ifnum\ltjgetparameter{direction}=3 \font@name
345          \ltj@@does@alt@set{\curr@kfontshape}{%
346       % alt fonts の定義
347       \directlua{luatexja.jfont.output_alt_font_cmd('y', '\luatexluaescapestring{\curr@kfontshape}')}%
348       % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
349       \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
350     }%
351   \fi}
352 \def\ltj@selectfont@patch{%
353   \directlua{luatexja.base.start_time_measure('selectfont')}%
354   \let\tmp@error@fontshape\error@fontshape
355   \let\error@fontshape\error@kfontshape
356   \let\tmp@wrong@fontshape\wrong@fontshape
357   \let\wrong@fontshape\wrong@kfontshape
358   \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
359     \let\cy@encoding\k@encoding
360     \ensure@KanjiEncodingPair{t}%
361     \edef\ct@encoding{\csname t@enc@\k@encoding\endcsname}%
362   \else
363     \directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
364       \let\ct@encoding\k@encoding
365       \ensure@KanjiEncodingPair{y}%
366       \edef\cy@encoding{\csname y@enc@\k@encoding\endcsname}%
367     \else
368       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
369     \fi
370   \fi
371   \global\let\ltj@afont@name=\font@name
372   \ltj@selectfont@tate\ltj@selectfont@yoko
373 %
374   \edef\tmp@item{{\k@encoding}}\expandafter\def\expandafter\k@encoding\tmp@item
375   \kenc@update
376   \global\let\font@name=\ltj@afont@name
377   \let\error@fontshape\tmp@error@fontshape
378   \let\wrong@fontshape\tmp@wrong@fontshape
379   \if@knjcmd \@knjcmdfalse
380     \expandafter\ifx
381     \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\relax
382       \expandafter\ifx
383          \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\relax
384       \else
385          \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\selectfont
386          % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
387       \fi
388     \else
389        \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\selectfont
390        % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
391     \fi
392   \fi
393   \global\let\font@name=\ltj@afont@name
394   \directlua{luatexja.base.stop_time_measure('selectfont')}%
395 }
396 \EverySelectfont{\ltj@selectfont@patch}
397
398 \bgroup
399   \def\ltj@@dir@patch#1#2#3{%
400     \global\csletcs{ltj@@orig@#1}{#1}%
401         \protected\expandafter\xdef\csname #1\endcsname{%
402           \csname ltj@@orig@#1\endcsname
403       \unexpanded{\ifnum#3<\z@\let\ltj@@protect\protect\set@typeset@protect}%
404       \unexpanded{\global\let\ltj@afont@name=\font@name}%
405           \expandonce{\csname ltj@selectfont@#2\endcsname}%
406       \unexpanded{\global\let\font@name=\ltj@afont@name}%
407       \unexpanded{\let\protect\ltj@@protect\fi}%
408         }%
409   }
410   \ltj@@dir@patch{yoko}{yoko}{\ltj@curjfnt}
411   \ltj@@dir@patch{tate}{tate}{\ltj@curtfnt}
412   \ltj@@dir@patch{utod}{yoko}{\ltj@curjfnt}
413   \ltj@@dir@patch{dtou}{yoko}{\ltj@curjfnt}
414 \egroup
415
416 \def\KanjiEncodingPair#1#2{\@namedef{t@enc@#1}{#2}\@namedef{y@enc@#2}{#1}}
417 \def\ensure@KanjiEncodingPair#1{%
418   \edef\reserved@a{\csname #1@enc@\k@encoding\endcsname}%
419   \edef\reserved@b{\csname c#1@encoding\endcsname}%
420   \ifcat\relax\reserved@a
421     \@latex@error
422       {KANJI Encoding pair for `\k@encoding' undefined}%
423       {Use \string\KanjiEncodingPair, falling back to `\reserved@b'...}%
424     \expandafter\edef\reserved@a{\reserved@b}%
425   \fi}
426 \def\set@fontsize#1#2#3{%
427     \@defaultunits\@tempdimb#2pt\relax\@nnil
428     \edef\f@size{\strip@pt\@tempdimb}%
429     \@defaultunits\@tempskipa#3pt\relax\@nnil
430     \edef\f@baselineskip{\the\@tempskipa}%
431     \edef\f@linespread{#1}%
432     \let\baselinestretch\f@linespread
433     \def\size@update{%
434       \baselineskip\f@baselineskip\relax
435       \baselineskip\f@linespread\baselineskip
436       \normalbaselineskip\baselineskip
437       \adjustbaseline
438       \setbox\ystrutbox\hbox{\ltj@@orig@yoko
439           \vrule\@width\z@
440                 \@height.7\baselineskip \@depth.3\baselineskip}%
441       \setbox\dstrutbox\hbox{\ltj@@orig@dtou
442           \vrule\@width\z@
443                 \@height.7\baselineskip \@depth.3\baselineskip}%
444       \setbox\tstrutbox\hbox{\ltj@@orig@tate
445           \vrule\@width\z@
446                 \@height.5\baselineskip \@depth.5\baselineskip}%
447       \setbox\zstrutbox\hbox{\ltj@@orig@utod
448           \vrule\@width\z@
449                 \@height.7\baselineskip \@depth.3\baselineskip}%
450      \let\size@update\relax}}
451
452 \newluafunction\ltj@@adjust@baseline@inner
453 \begingroup\catcode`\~=12
454 \directlua{%
455   local nulltable = {}
456   local t = lua.get_functions_table()
457   local getfont, dir_tate = font.getfont, luatexja.dir_table.dir_tate
458   local fmt, get_attr = luatexja.jfont.font_metric_table, tex.getattribute
459   local getcount=tex.getcount
460   local setdimen, set_attr = tex.setdimen, tex.setattribute
461   local dir = luatexja.unary_pars.direction
462   t[\the\ltj@@adjust@baseline@inner] = function()
463     local ft = fmt[get_attr('ltj@curtfnt')] or nulltable
464     ft = ft.char_type or nulltable
465     local fk = ft[0] or nulltable
466     local ht, dp, wd = fk.height or 0, fk.depth or 0,
467                        fk.width or ft.zw or 0
468     local fm 
469       = ((getfont(font.current()) or nulltable)
470         .characters or nulltable)[77] or nulltable %% 'M'
471     set_attr('ltj@tablshift',
472       tex.round(0.5*((fm.height or 0)- (fm.depth or 0) - ht+ dp)))
473     if dir() ~= dir_tate then
474       ft = fmt[get_attr('ltj@curjfnt')] or nulltable
475       ft = ft.char_type or nulltable
476       fk = ft[0] or nulltable
477       ht, dp, wd = fk.height or 0, fk.depth or 0,
478                    fk.width or ft.zw or 0
479     end
480     setdimen('cht', ht); setdimen('cdp', dp)
481     setdimen('cwd', wd); setdimen('chs', wd)
482     setdimen('cHT', ht+dp)
483   end
484 }\endgroup
485 \DeclareRobustCommand\adjustbaseline{\luafunction\ltj@@adjust@baseline@inner
486    \cvs\normalbaselineskip}
487 \DeclareRobustCommand\romanencoding[1]{%
488     \expandafter\ifx\csname T@#1\endcsname\relax
489       \@latex@error{Encoding scheme `#1' unknown}\@eha
490     \else
491       \edef\f@encoding{#1}%
492       \ifx\cf@encoding\f@encoding
493         \let\enc@update\relax
494       \else
495         \let\enc@update\@@enc@update
496       \fi
497     \fi
498 }
499 \DeclareRobustCommand\kanjiencoding[1]{%
500     \expandafter\ifx\csname T@#1\endcsname\relax
501       \@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
502     \else
503       \edef\k@encoding{#1}%
504       \ifx\ck@encoding\k@encoding
505          \let\kenc@update\relax
506       \else
507          \let\kenc@update\@@kenc@update
508       \fi
509     \fi
510 }
511 \DeclareRobustCommand\fontencoding[1]{%
512   \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#1}')}\ifin@%
513   \kanjiencoding{#1}\else\romanencoding{#1}\fi}
514 \def\@@kenc@update{%
515   \default@KT
516   \csname T@\k@encoding\endcsname
517   \csname D@\k@encoding\endcsname
518   \let\kenc@update\relax
519   \let\ck@encoding\k@encoding
520   \edef\tmp@enc{'\luatexluaescapestring{\k@encoding}'}%
521   \directlua{luatexja.jfont.is_kyenc(\tmp@enc)}\ifin@%
522     \let\cy@encoding\k@encoding
523   \else
524     \directlua{luatexja.jfont.is_ktenc(\tmp@enc)}\ifin@%
525       \let\ct@encoding\k@encoding
526     \else
527       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
528     \fi
529   \fi
530 }
531 \let\kenc@update\relax
532 \def\@changed@kcmd#1#2{%
533    \ifx\protect\@typeset@protect
534       \@inmathwarn#1%
535       \expandafter\ifx\csname\ck@encoding\string#1\endcsname\relax
536          \expandafter\ifx\csname ?\string#1\endcsname\relax
537             \expandafter\def\csname ?\string#1\endcsname{%
538                \TextSymbolUnavailable#1%
539             }%
540          \fi
541          \global\expandafter\let
542                \csname\cf@encoding \string#1\expandafter\endcsname
543                \csname ?\string#1\endcsname
544       \fi
545       \csname\ck@encoding\string#1%
546          \expandafter\endcsname
547    \else
548       \noexpand#1%
549    \fi}
550 \newif\if@notkfam
551 \newif\if@notffam
552 \newif\if@tempswz
553 \def\@ltj@use@fd{true}
554 \DeclareRobustCommand\romanfamily[1]{\edef\f@family{#1}}
555 \DeclareRobustCommand\kanjifamily[1]{\edef\k@family{#1}}
556 \DeclareRobustCommand\fontfamily[1]{%
557   \@notkfamfalse\@notffamfalse
558   \edef\tmp@item{'\luatexluaescapestring{#1}'}%
559   %
560   \directlua{luatexja.jfont.search_kfam(\tmp@item, \@ltj@use@fd)}%
561   \ifin@\edef\k@family{#1}\else\@notkfamtrue\fi
562   %
563   % alphabetic fonts part
564   \directlua{luatexja.jfont.is_ffam(\tmp@item)}%
565   \ifin@\edef\f@family{#1}\else
566     % checking is_stored_ffam is not sufficient,
567     % since LuaTeX-ja doesn't know whats fonts are defined before LuaTeX-ja is loaded.
568     \ifcsname \f@encoding+#1\endcsname % easy case
569       \directlua{luatexja.jfont.add_ffam(\tmp@item)}\edef\f@family{#1}%
570     \else
571       \@tempswafalse
572       \def\cdp@elt##1{\ifcsname ##1+#1\endcsname\@tempswatrue\fi}%
573       \directlua{luatexja.jfont.search_ffam_declared()}%
574       \if@tempswz
575         \directlua{luatexja.jfont.add_ffam(\tmp@item)}\edef\f@family{#1}%
576       \else
577         % now we search Nffam_list and font definition files.
578         \directlua{luatexja.jfont.search_ffam_fd(\tmp@item)}%
579         \ifin@\edef\f@family{#1}\else\@notffamtrue\fi
580       \fi
581     \fi
582   \fi
583   %
584   \if@notkfam\if@notffam
585     \edef\k@family{#1}\edef\f@family{#1}%
586   \fi\fi
587 }
588
589 \newcount\ltj@@latex@plv \ltj@@latex@plv=-1
590 \ifdefined\@rmfamilyhook
591 %%%% LaTeX 2020-02-02
592 \newif\if@shape@roman@kanji
593 %%%%%% 2020-02-02 patchlevel detection
594 \ifx\@forced@seriestrue\@undefined % 2020-02-02 pl0--2
595   \@latex@error
596    {Please update LaTeX2e!^^J\space\space
597      At least LaTeX2e 2020-02-02 patch level 3 is required}
598    {LaTeX2e 2020-02-02 patch level 2 (and 4) has a bug.}
599 \else
600   \ltj@@latex@plv=300
601   \unless\ifx\series@maybe@drop@one@m@x\@undefined % pl5 + develop
602     \ltj@@latex@plv=501
603   \else\unless\ifx\series@maybe@drop@one@m\@undefined % patch level 5
604     \ltj@@latex@plv=500
605   \fi\fi
606 \fi
607 %%%%%%
608
609 \def\merge@kanji@series#1{%
610   \expandafter\expandafter\expandafter
611   \merge@kanji@series@
612     \csname series@\k@series @#1\endcsname
613     {#1}%
614     \@nil
615 }
616
617 \ifnum\ltj@@latex@plv>500 % !!! pl5 + develop
618   \def\set@target@series@kanji#1{%
619       \edef\k@series{#1}%
620       \series@maybe@drop@one@m\k@series\k@series
621   }
622 \else\ifnum\ltj@@latex@plv>300 % !!! pl5
623   \def\set@target@series@kanji#1{%
624       \edef\k@series{#1}%
625       \expandafter\series@maybe@drop@one@m\expandafter{\k@series}\k@series
626   }
627 \else % !!! pl 3, 4
628   \def\set@target@series@kanji#1{%
629       \edef\k@series{#1}%
630           \edef\k@series{\expandafter\series@drop@one@m\k@series mm\series@drop@one@m}%
631   }
632 \fi\fi
633
634 \def\merge@kanji@series@#1#2#3\@nil{%
635   \def\reserved@a{#3}%
636   \ifx\reserved@a\@empty
637     \set@target@series@kanji{#2}%
638   \else
639     \begingroup\let\f@encoding\k@encoding\let\f@family\k@family
640            \maybe@load@fontshape\endgroup
641     \edef\reserved@a{\k@encoding /\k@family /#1/\k@shape}%
642      \ifcsname \reserved@a \endcsname
643        \set@target@series@kanji{#1}%
644     \else
645        \ifcsname \k@encoding /\k@family /#2/\k@shape \endcsname
646          \set@target@series@kanji{#2}%
647          {\let\curr@fontshape\curr@kfontshape\@font@shape@subst@warning}%
648        \else
649          \set@target@series@kanji{#3}%
650          {\let\curr@fontshape\curr@kfontshape\@font@shape@subst@warning}%
651        \fi
652     \fi
653   \fi
654 }
655 \def\merge@kanji@shape#1{%
656   \expandafter\expandafter\expandafter
657   \merge@kanji@shape@
658     \csname shape@\k@shape @#1\endcsname
659     {#1}%
660     \@nil
661 }
662 \def\merge@kanji@shape@#1#2#3\@nil{%
663   \def\reserved@a{#3}%
664   \ifx\reserved@a\@empty
665     \if@shape@roman@kanji
666       \set@safe@kanji@shape{#2}{}%
667     \else
668       \edef\k@shape{#2}%
669     \fi
670   \else
671     \begingroup\let\f@encoding\k@encoding\let\f@family\k@family
672            \maybe@load@fontshape\endgroup
673     \edef\reserved@a{\k@encoding /\k@family /\k@series/#1}%
674      \ifcsname \reserved@a\endcsname
675        \edef\k@shape{#1}%
676     \else
677        \ifcsname \k@encoding /\k@family /\k@series/#2\endcsname
678          \edef\k@shape{#2}%
679          {\let\curr@fontshape\curr@kfontshape\@font@shape@subst@warning}%
680        \else
681          \if@shape@roman@kanji
682            \set@safe@kanji@shape{#3}%
683            {{\let\curr@fontshape\curr@kfontshape\@font@shape@subst@warning}}%
684          \else
685            \edef\k@shape{#3}%
686            {\let\curr@fontshape\curr@kfontshape\@font@shape@subst@warning}%
687          \fi
688        \fi
689     \fi
690   \fi
691 }
692 \def\set@safe@kanji@shape#1#2{%
693   \edef\reserved@b{\k@encoding /\k@family /\k@series/#1}%
694   \ifcsname \reserved@b\endcsname
695     \edef\k@shape{#1}%
696     #2%
697   \else
698     \@kanji@shape@nochange@info{\reserved@b}%
699   \fi
700 }
701 \def\@kanji@shape@nochange@info#1{%
702     \@font@info{Kanji font shape `#1' undefined\MessageBreak
703                 No change}%
704 }
705 \ifnum\ltj@@latex@plv=300 % !!! pl3, 4
706   \DeclareRobustCommand\romanseries[1]{\merge@font@series{#1}}
707   \DeclareRobustCommand\kanjiseries[1]{\merge@kanji@series{#1}}
708   \DeclareRobustCommand\fontseries[1]{%
709      \merge@font@series{#1}\merge@kanji@series{#1}}
710   \DeclareRobustCommand\romanseriesforce[1]{\edef\f@series{#1}}
711   \DeclareRobustCommand\kanjiseriesforce[1]{\edef\k@series{#1}}
712   \DeclareRobustCommand\fontseriesforce[1]{%
713      \edef\f@series{#1}\edef\k@series{#1}}
714 \else % !!! pl 5
715   \DeclareRobustCommand\romanseries[1]{\@forced@seriesfalse\merge@font@series{#1}}
716   \DeclareRobustCommand\kanjiseries[1]{\@forced@seriesfalse\merge@kanji@series{#1}}
717   \DeclareRobustCommand\fontseries[1]{%
718     \@forced@seriesfalse\merge@font@series{#1}\merge@kanji@series{#1}}
719   \DeclareRobustCommand\romanseriesforce[1]{\@forced@seriestrue\merge@font@series{#1}}
720   \DeclareRobustCommand\kanjiseriesforce[1]{\@forced@seriestrue\merge@kanji@series{#1}}
721   \DeclareRobustCommand\fontseriesforce[1]{%
722      \@forced@seriestrue\merge@font@series{#1}\merge@kanji@series{#1}}
723 \fi
724 \DeclareRobustCommand\romanshape[1]{\merge@font@shape{#1}}
725 \DeclareRobustCommand\kanjishape[1]{\merge@kanji@shape{#1}}
726 \DeclareRobustCommand\fontshape[1]{%
727    \@shape@roman@kanjitrue
728    \merge@font@shape{#1}\merge@kanji@shape{#1}%
729    \@shape@roman@kanjifalse
730 }
731 \DeclareRobustCommand\romanshapeforce[1]{\edef\f@shape{#1}}
732 \DeclareRobustCommand\kanjishapeforce[1]{\edef\k@shape{#1}}
733 \DeclareRobustCommand\fontshapeforce[1]{\set@safe@kanji@shape{#1}{}\romanshapeforce{#1}}
734 \DeclareRobustCommand\usekanji[4]{%
735     \kanjiencoding{#1}\edef\k@family{#2}\edef\k@series{#3}\edef\k@shape{#4}%
736     \selectfont\ignorespaces}
737 \DeclareRobustCommand\useroman[4]{%
738     \romanencoding{#1}\edef\f@family{#2}\edef\f@series{#3}\edef\f@shape{#4}%
739     \selectfont\ignorespaces}
740 %%%% LaTeX 2020-02-02 END
741 \else
742 %%%% LaTeX 2019-10-01
743 \DeclareRobustCommand\romanseries[1]{\edef\f@series{#1}}
744 \DeclareRobustCommand\kanjiseries[1]{\edef\k@series{#1}}
745 \DeclareRobustCommand\fontseries[1]{\kanjiseries{#1}\romanseries{#1}}
746 \DeclareRobustCommand\romanshape[1]{\edef\f@shape{#1}}
747 \DeclareRobustCommand\kanjishape[1]{\edef\k@shape{#1}}
748 \DeclareRobustCommand\fontshape[1]{\kanjishape{#1}\romanshape{#1}}
749 \DeclareRobustCommand\usekanji[4]{%
750     \kanjiencoding{#1}\kanjifamily{#2}\kanjiseries{#3}\kanjishape{#4}%
751     \selectfont\ignorespaces}
752 \DeclareRobustCommand\useroman[4]{%
753     \romanencoding{#1}\romanfamily{#2}\romanseries{#3}\romanshape{#4}%
754     \selectfont\ignorespaces}
755 %%%% LaTeX 2019-10-01 END
756 \fi
757 %%%%
758 \protected\def\usefont#1#2#3#4{%
759   \directlua{luatexja.jfont.is_kenc('\luatexluaescapestring{#1}')}\ifin@%
760   \usekanji{#1}{#2}{#3}{#4}%
761   \else\useroman{#1}{#2}{#3}{#4}%
762   \fi}
763 \DeclareRobustCommand\normalfont{%
764     \useroman\encodingdefault\familydefault\seriesdefault\shapedefault
765     \usekanji\kanjiencodingdefault\kanjifamilydefault\kanjiseriesdefault\kanjishapedefault}
766 \let\reset@font\normalfont
767
768 \ifdefined\@rmfamilyhook
769 %%%% LaTeX 2020-02-02
770 \let\prepare@family@series@update@kanji=\prepare@family@series@update
771 \patchcmd\prepare@family@series@update{\fontfamily}{\romanfamily}{}{}
772 \patchcmd\prepare@family@series@update@kanji{\fontfamily}{\kanjifamily}{}{}
773 \patchcmd\prepare@family@series@update@kanji{\update@series@target@value}{\update@series@target@value@kanji}{}{}
774 \patchcmd\prepare@family@series@update@kanji{\f@family}{\k@family}{}{}
775 \patchcmd\prepare@family@series@update@kanji{\@meta@family@list}{\@meta@family@list@kanji}{}{}
776 \patchcmd\prepare@family@series@update@kanji{\fontfamily}{\kanjifamily}{}{}
777 \patchcmd\prepare@family@series@update@kanji{\maybe@load@fontshape}
778   {\begingroup\let\f@encoding\k@encoding\let\f@family\k@family
779     \maybe@load@fontshape\endgroup}{}{}
780 \patchcmd\prepare@family@series@update@kanji{\f@series}{\k@series}{}{}
781 \patchcmd\prepare@family@series@update@kanji{\f@series}{\k@series}{}{}
782 \let\update@series@target@value@kanji=\update@series@target@value
783 \patchcmd\update@series@target@value@kanji{\f@family}{\k@family}{}{}
784 \patchcmd\update@series@target@value@kanji{\f@series}{\k@series}{}{}
785 \patchcmd\update@series@target@value@kanji{\f@series}{\k@series}{}{}
786 \patchcmd\update@series@target@value@kanji{\f@series}{\k@series}{}{}
787 \patchcmd\update@series@target@value@kanji{\f@series}{\k@series}{}{}
788 \def\@meta@family@list@kanji{\@elt{mc}\@elt{gt}\@elt{jtt}}
789
790 \expandafter\patchcmd\csname bfseries \endcsname{%
791   \let\bfseries@rm\bfdef@ult
792   \let\bfseries@sf\bfdef@ult
793   \let\bfseries@tt\bfdef@ult
794 }{%
795   \let\bfseries@rm\bfdef@ult
796   \let\bfseries@sf\bfdef@ult
797   \let\bfseries@tt\bfdef@ult
798   \let\bfseries@mc\bfdef@ult
799   \let\bfseries@gt\bfdef@ult
800   \let\bfseries@jtt\bfdef@ult
801 }{}{}
802 \expandafter\patchcmd\csname mdseries \endcsname{%
803   \let\mdseries@rm\mddef@ult
804   \let\mdseries@sf\mddef@ult
805   \let\mdseries@tt\mddef@ult
806 }{%
807   \let\mdseries@rm\mddef@ult
808   \let\mdseries@sf\mddef@ult
809   \let\mdseries@tt\mddef@ult
810   \let\mdseries@mc\mddef@ult
811   \let\mdseries@gt\mddef@ult
812   \let\mdseries@jtt\mddef@ult
813 }{}{}
814 \expandafter\patchcmd\csname bfseries \endcsname{\selectfont}%
815 {%
816   \ifx\k@family\mcdef@ult      \kanjiseries\bfseries@mc
817   \else\ifx\k@family\gtdef@ult \kanjiseries\bfseries@gt
818   \else\ifx\k@family\jttdef@ult\kanjiseries\bfseries@jtt
819   \else                        \kanjiseries\bfdefault
820   \fi\fi\fi
821   \selectfont
822 }{}{}
823 \expandafter\patchcmd\csname mdseries \endcsname{\selectfont}%
824 {%
825   \ifx\k@family\mcdef@ult      \kanjiseries\mdseries@mc
826   \else\ifx\k@family\gtdef@ult \kanjiseries\mdseries@gt
827   \else\ifx\k@family\jttdef@ult\kanjiseries\mdseries@jtt
828   \else                        \kanjiseries\mddefault
829   \fi\fi\fi
830   \selectfont
831 }{}{}
832 \appto\expand@font@defaults{%
833   \edef\mcdef@ult{\mcdefault}%
834   \edef\gtdef@ult{\gtdefault}%
835   \edef\jttdef@ult{\jttdefault}%
836   \edef\kanjidef@ult{\kanjifamilydefault}%
837 }
838 \appto\init@series@setup{%
839   \ifx\kanjidef@ult\mcdef@ult      \mcfamily
840   \else\ifx\kanjidef@ult\gtdef@ult \gtfamily
841   \else\ifx\kanjidef@ult\jttdef@ult \jttfamily
842   \fi\fi\fi
843 }
844 \fi
845 \ifdefined\prepare@family@series@update@kanji\else
846 %%%% LaTeX 2019-10-01
847 \def\prepare@family@series@update@kanji#1{\kanjifamily}
848 \fi
849
850 \DeclareRobustCommand\mcfamily{%
851   \unless\ifltj@disablejfam\not@math@alphabet\mcfamily\mathmc\fi
852   \prepare@family@series@update@kanji{mc}\mcdefault
853   \selectfont}
854 \DeclareRobustCommand\gtfamily{%
855   \unless\ifltj@disablejfam\not@math@alphabet\gtfamily\mathgt\fi
856   \prepare@family@series@update@kanji{gt}\gtdefault
857   \selectfont}
858
859
860
861 \let\romanprocess@table\process@table
862 \def\kanjiprocess@table{%
863   \kanjiencoding{\kanjiencodingdefault}%
864   \kanjifamily{\kanjifamilydefault}%
865   \kanjiseries{\kanjiseriesdefault}%
866   \kanjishape{\kanjishapedefault}%
867 }
868 \def\process@table{%
869   \romanprocess@table
870   \kanjiprocess@table
871 }
872 \@onlypreamble\romanprocess@table
873 \@onlypreamble\kanjiprocess@table
874
875 %%%%%% LuaTeX-ja specific
876
877 % #1 の展開結果から encoding 部分をとりだし,それが和文用かどうかの結果を \ifin@ に代入
878 \def\ltj@@IsFontJapanese#1{%
879   \directlua{luatexja.jfont.is_kenc(string.match(
880       '\luatexluaescapestring{#1}', '[^/]+'))}}
881
882
883 \let\extract@afont\extract@font
884 \def\pickup@jfont{%
885   \ifnum
886         \unless\ifnum\ltjgetparameter{direction}=3 1\else
887             \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
888     \expandafter \ifx \font@name \relax
889        \let\extract@font\extract@jfont
890        \define@newfont
891        \let\extract@font\extract@afont
892     \fi
893     \let\getjfont\font@name
894   \else
895         \begingroup\escapechar\m@ne
896         \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
897        \let\extract@font\extract@jfont@onlyjfm
898        \define@newfont
899        \let\extract@font\extract@afont
900         \fi
901         \endgroup
902         \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
903   \fi
904 }
905 \def\pickup@tfont{%
906   \ifnum
907         \ifnum\ltjgetparameter{direction}=3 1\else
908             \ifltjselectfont@force@define 1\else 0\fi\fi =1 %
909     \expandafter \ifx \font@name \relax
910        \let\extract@font\extract@tfont
911        \define@newfont
912        \let\extract@font\extract@afont
913     \fi
914     \let\gettfont\font@name
915   \else
916         \begingroup\escapechar\m@ne
917         \ifcsname ltj@@fontjfm/\expandafter\string\font@name\endcsname\else
918        \let\extract@font\extract@tfont@onlyjfm
919        \define@newfont
920        \let\extract@font\extract@afont
921         \fi
922         \endgroup
923         \csname ltj@@fontjfm/\expandafter\expandafter\expandafter\@gobble\expandafter\string\font@name\endcsname
924   \fi
925 }
926
927 % 異なる和文 enc/fam/ser/shape からは異なるフォント番号が振られるように
928 % わざと「ゴミをつける」
929 \def\ltj@@patch@external@font#1 at{%
930   \directlua{
931         local s = '\luatexluaescapestring{#1}'
932         local is_braced, is_quoted
933         if s:sub(1,1)=='{' and s:sub(-1)=='}' then is_braced=true; s=s:sub(2,-2) end
934         if s:sub(1,1)=='"' and s:sub(-1)=='"' then is_quoted=true; s=s:sub(2,-2) end
935         s=s..luatexja.jfont.print_aftl_address()
936         if is_braced then s='{'..s..'}' elseif is_quoted then s='"'..s..'"' end
937         %print(s, is_quoted, is_braced)
938     tex.sprint(-2, s)}%
939   \space at%
940 }
941 \def\extract@jfont{%
942         \get@external@font
943     \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}{%
944       \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
945     }%
946     \expandafter\globaljfont\font@name\external@font\relax\font@name% ここで時間がかかる
947     \csname \f@encoding+\f@family\endcsname
948     \csname\curr@fontshape\endcsname}
949 \def\extract@tfont{%
950         \get@external@font
951     \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}{%
952       \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
953     }%
954     \expandafter\globaltfont\font@name\external@font\relax\font@name
955     \csname \f@encoding+\f@family\endcsname
956     \csname\curr@fontshape\endcsname}
957 \def\extract@jfont@onlyjfm{%
958         \get@external@font
959         \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
960           \directlua{%
961                 luatexja.jfont.load_jfmonly('\luatexluaescapestring{\external@font}', 'yoko')
962           }%
963         }}
964 \def\extract@tfont@onlyjfm{%
965         \get@external@font
966         \csxdef{ltj@@fontjfm/\expandafter\string\font@name}{%
967           \directlua{%
968                 luatexja.jfont.load_jfmonly('\luatexluaescapestring{\external@font}', 'tate')
969           }%
970         }}
971
972 \let\ltj@@al@do@subst@correction=\do@subst@correction
973 \def\ltj@@ja@do@subst@correction{%
974     \xdef\subst@correction{%
975       \font@name
976       \global\expandafter\let\csname \curr@fontshape/\f@size\endcsname\font@name%
977       \relax}%
978     \aftergroup\subst@correction
979 }
980 \def\do@subst@correction{%
981    \directlua{luatexja.jfont.is_kenc('\luatexluaescapestring{\f@encoding}')}\ifin@%
982      \ltj@@ja@do@subst@correction
983    \else
984      \ltj@@al@do@subst@correction
985    \fi
986 }
987 \let\@@italiccorr=\/
988
989 %%%%%% Japanese font for math mode
990 \unless\ifltj@disablejfam
991
992 % \M@<enc> から その <enc> が和文用か調べる
993 {\catcode`M=12%
994 \gdef\ltj@@mathJapaneseFonts#1M#2#3\relax{\ltj@@IsFontJapanese{#3}}}
995
996 \let\ltj@@al@getanddefine@fonts=\getanddefine@fonts
997 \def\ltj@@ja@getanddefine@fonts#1#2{%
998   \csletcs{if@ltj@tempif}{ifltjselectfont@force@define}%
999   \ltjselectfont@force@definetrue
1000   \xdef\font@name{\csname \string#2/\tf@size\endcsname}%
1001   \pickup@jfont\let\textfont@name\font@name
1002   \xdef\font@name{\csname \string#2/\sf@size\endcsname}%
1003   \pickup@jfont\let\scriptfont@name\font@name
1004   \xdef\font@name{\csname \string#2/\ssf@size\endcsname}%
1005   \pickup@jfont
1006   \csletcs{ifltjselectfont@force@define}{if@ltj@tempif}%
1007   \edef\math@fonts{\math@fonts\ltj@setpar@global%
1008     \ltj@@set@stackfont#1,\textfont@name:{MJT}%
1009     \ltj@@set@stackfont#1,\scriptfont@name:{MJS}%
1010     \ltj@@set@stackfont#1,\font@name:{MJSS}%
1011   }%
1012 }
1013
1014 \def\getanddefine@fonts#1#2{%
1015   \ltj@tempcnta=#1\ltj@@IsFontJapanese{\string#2}%
1016   \ifin@\let\ltj@temp=\ltj@@ja@getanddefine@fonts%
1017   \else \let\ltj@temp=\ltj@@al@getanddefine@fonts\fi
1018   \ltj@temp{#1}{#2}%
1019 }
1020 \def\use@mathgroup#1#2{\relax\ifmmode
1021   \math@bgroup
1022     \expandafter\ifx\csname M@\f@encoding\endcsname#1\else
1023     #1\fi\ltj@tempcnta=#2 \expandafter\ltj@@mathJapaneseFonts\string#1\relax%
1024     \ifin@\jfam#2\relax\else\mathgroup#2\relax\fi
1025   \expandafter\math@egroup\fi}%
1026
1027 \fi
1028
1029 %%%%%% Alternate Japanese Fonts
1030 %%%% \DeclareAlternateKanjiFont<Benc><Bfam><Bser><Bshape><Aenc><Afam><Aser><Ashape><range>
1031 % いつも global
1032 \def\DeclareAlternateKanjiFont#1#2#3#4#5#6#7#8#9{%
1033   \edef\@temp{#9}%
1034   \ifx\@temp\@empty\else
1035     {\def\ltj@temp@bfont{#1/#2/#3/#4}\def\ltj@temp@afont{#5/#6/#7/#8}%
1036      \expandafter\ltj@@altfont@latex#9,,}\ignorespaces
1037   \fi}
1038 \def\ltj@@altfont@latex#1,{\def\ltj@temp{#1}%
1039   \ifx\ltj@temp\empty\let\@next=\relax\else
1040   \ltj@@altfont@latexA{#1}\let\@next=\ltj@@altfont@latex\fi\@next}
1041 \def\ltj@@altfont@latexA#1{\ltj@@altfont@latexB#1--\@nil}
1042 \def\ltj@@altfont@latexB#1-#2-#3\@nil{\def\ltj@temp{#3}%
1043   \ifx\ltj@temp\empty
1044     \ltj@tempcnta=#1\relax\ltj@tempcntb=\ltj@tempcnta
1045   \else
1046     \def\ltj@temp{#1}%
1047     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
1048     \def\ltj@temp{#2}%
1049     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
1050   \fi
1051   \directlua{luatexja.jfont.set_alt_font_latex(
1052     \the\ltj@tempcnta,\the\ltj@tempcntb,
1053     '\luatexluaescapestring{\ltj@temp@afont}',
1054     '\luatexluaescapestring{\ltj@temp@bfont}')}%
1055   }
1056
1057 %%%% \ClearAlternateKanjiFont<Benc><Bfam><Bser><Bshape>
1058 % いつも global
1059 \def\ClearAlternateKanjiFont#1#2#3#4{%
1060    \directlua{luatexja.jfont.clear_alt_font_latex('\luatexluaescapestring{#1/#2/#3/#4}')}}
1061
1062 \def\ltj@pickup@altfont@auxy#1{%
1063   \begingroup\edef\font@name{\csname #1/\f@size\endcsname}\pickup@jfont\endgroup%
1064 }
1065 \def\ltj@pickup@altfont@auxt#1{%
1066   \begingroup\edef\font@name{\csname #1/\f@size\endcsname}\pickup@tfont\endgroup%
1067 }
1068 \def\ltj@pickup@altfont@copy#1#2{%
1069   \ltj@@getjfontnumber#1%
1070   \directlua{luatexja.jfont.pickup_alt_font_b(\the\ltj@tempcntc,'\luatexluaescapestring{#2}')}%
1071 }
1072
1073 \def\ltj@@does@alt@set#1#2{%
1074   \directlua{luatexja.jfont.does_alt_set'\luatexluaescapestring{#1}'}{#2}}
1075
1076 %%%% patch \@text@composite because of {y,t}albaselineshift
1077
1078 % %% \pltx@isletter from plfonts.dtx
1079 % \def\pltx@mark{\pltx@mark@}
1080 % \let\pltx@scanstop\relax
1081 % \long\def\pltx@cond#1\fi{%
1082 %   #1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
1083 % \long\def\pltx@isletter#1{%
1084 %   \expandafter\pltx@isletter@i#1\pltx@scanstop}
1085 % \long\def\pltx@isletter@i#1\pltx@scanstop{%
1086 %   \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi{\@firstoftwo}%
1087 %     {\pltx@isletter@ii\pltx@scanstop#1\pltx@scanstop{}#1\pltx@mark}}
1088 % \long\def\pltx@isletter@ii#1\pltx@scanstop#{%
1089 %   \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi%
1090 %     {\pltx@isletter@iii}{\pltx@isletter@iv}}
1091 % \long\def\pltx@isletter@iii#1\pltx@mark{\@secondoftwo}
1092 % \long\def\pltx@isletter@iv#1#2#3\pltx@mark{%
1093 %   \pltx@cond\ifx\pltx@mark#3\pltx@mark\fi{%
1094 %     \pltx@cond{\ifnum0\ifcat A\noexpand#21\fi\ifcat=\noexpand#21\fi>\z@}\fi
1095 %       {\@firstoftwo}{\@secondoftwo}%
1096 %   }{\@secondoftwo}}
1097 %
1098 % \def\@text@composite@x#1#2{%
1099 %   \ifx#1\relax
1100 %     #2%
1101 %   \else\pltx@isletter{#1}{#1}{%
1102 %     \begingroup
1103 %     \setbox\z@\hbox\bgroup%
1104 %       \ltj@yablshift\z@ \ltj@tablshift\z@
1105 %       #1%
1106 %       \@tempcntb\directlua{luatexja.pltx_composite_last_node_char()}%)
1107 %       \xdef\pltx@composite@temp{\noexpand\@tempcntb=\the\@tempcntb\relax}%
1108 %       \aftergroup\pltx@composite@temp
1109 %     \egroup
1110 %     \ifnum\ltjgetparameter{direction}=3 %
1111 %       \@tempdima=\ltj@tablshift sp\else\@tempdima=\ltj@yablshift sp\fi
1112 %     \ifnum\@tempcntb<\z@\@tempcnta\z@\else
1113 %       \@tempcnta=\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{\@tempcntb}}\relax
1114 %       \ifnum\@tempcnta=\z@\@tempdima\z@\fi
1115 %     \fi
1116 %     \ifnum\@tempcnta>\z@
1117 %       \ifodd\ltjgetparameter{alxspmode}{\@tempcntb}\else\leavevmode\hbox{}\fi
1118 %       \begingroup\mathsurround\z@$%
1119 %         \hbox{\lower\@tempdima\box\z@}
1120 %       $\endgroup%
1121 %       \ifnum\ltjgetparameter{alxspmode}{\@tempcntb}<2\hbox{}\fi
1122 %     \else
1123 %       \ifdim\@tempdima=\z@{\ltj@yablshift\z@ \ltj@tablshift\z@#1}%
1124 %       \else\lower\@tempdima\box\z@\fi
1125 %     \fi
1126 %     \endgroup}%
1127 %   \fi
1128 % }
1129
1130 \endinput