OSDN Git Service

Use everysel package for patching \selectfont.
[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}[2014/01/23 Patch to NFSS2 for LuaTeX-ja]
7
8 \let\k@encoding\@empty
9 \let\ck@encoding\@empty
10 % LuaTeX-ja uses JY3 and JT3 encodings.
11 \def\cy@encoding{JY3}\def\ct@encoding{JT3}
12
13 \let\k@family\@empty
14 \let\k@series\@empty
15 \let\k@shape\@empty
16 \def\curr@kfontshape{\k@encoding/\k@family/\k@series/\k@shape}
17 \def\rel@fontshape{\f@encoding/\f@family/\f@series/\f@shape}
18 \ifdefined\Cht\else\newdimen\Cht\fi
19 \ifdefined\cht\else\newdimen\cht\fi
20 \ifdefined\Cdp\else\newdimen\Cdp\fi
21 \ifdefined\cdp\else\newdimen\cdp\fi
22 \ifdefined\Cwd\else\newdimen\Cwd\fi
23 \ifdefined\cwd\else\newdimen\cwd\fi
24 \ifdefined\Cvs\else\newdimen\Cvs\fi
25 \ifdefined\cvs\else\newdimen\cvs\fi
26 \ifdefined\Chs\else\newdimen\Chs\fi
27 \ifdefined\chs\else\newdimen\chs\fi
28 \ifdefined\cHT\else\newdimen\cHT\fi
29 %\let\afont\font
30
31 \newbox\tstrutbox
32 \newbox\zstrutbox
33 \def\strut{\relax
34   \ifydir
35     \ifmmode\copy\strutbox\else\unhcopy\strutbox\fi
36   \else
37     \ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi
38   \fi
39 }
40 \def\tstrut{\relax\hbox{\tate
41    \ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi}}
42 \def\zstrut{\relax\hbox{\tate
43    \ifmmode\copy\zstrutbox\else\unhcopy\zstrutbox\fi}}
44 \def\DeclareFontEncoding{%
45   \begingroup
46   \nfss@catcodes
47   \expandafter\endgroup
48   \DeclareFontEncoding@}
49 \def\DeclareFontEncoding@#1#2#3{%
50   \expandafter
51   \ifx\csname T@#1\endcsname\relax
52      \def\cdp@elt{\noexpand\cdp@elt}%
53      \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
54                     {\default@family}{\default@series}%
55                     {\default@shape}}%
56      \expandafter\let\csname#1-cmd\endcsname\@changed@cmd
57      \def\enc@elt{\noexpand\enc@elt}%
58   \else
59      \@font@info{Redeclaring font encoding #1}%
60   \fi
61   \global\@namedef{T@#1}{#2}%
62   \global\@namedef{M@#1}{\default@M#3}%
63   \xdef\LastDeclaredEncoding{#1}%
64   }
65 \def\DeclareKanjiEncoding#1{%
66   \@latex@warning{%
67      The \string\DeclareKanjiEncoding\space is obsoleted command.  Please use
68      \MessageBreak
69      the \string\DeclareTateKanjiEncoding\space for `Tate-kumi' encoding, and
70      \MessageBreak
71      the \string\DeclareYokoKanjiEncoding\space for `Yoko-kumi' encoding.
72      \MessageBreak
73      I treat the `#1' encoding as `Yoko-kumi'.}
74   \DeclareYokoKanjiEncoding{#1}%
75 }
76 \def\DeclareYokoKanjiEncoding{%
77   \begingroup
78   \nfss@catcodes
79   \expandafter\endgroup
80   \DeclareYokoKanjiEncoding@}
81 \def\DeclareYokoKanjiEncoding@#1#2#3{%
82   \expandafter\ifx\csname T@#1\endcsname\relax
83     \def\cdp@elt{\noexpand\cdp@elt}%
84     \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
85                     {\default@k@family}{\default@k@series}%
86                     {\default@k@shape}}%
87     \expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
88      \directlua{luatexja.jfont.add_kyenc_list('\luatexluaescapestring{#1}')}%
89   \else
90     \@font@info{Redeclaring KANJI (yoko) font encoding #1}%
91   \fi
92   \global\@namedef{T@#1}{#2}%
93   \global\@namedef{M@#1}{\default@KM#3}%
94   }
95 \def\DeclareTateKanjiEncoding{%
96   \begingroup
97   \nfss@catcodes
98   \expandafter\endgroup
99   \DeclareTateKanjiEncoding@}
100 \def\DeclareTateKanjiEncoding@#1#2#3{%
101   \expandafter\ifx\csname T@#1\endcsname\relax
102     \def\cdp@elt{\noexpand\cdp@elt}%
103     \xdef\cdp@list{\cdp@list\cdp@elt{#1}%
104                     {\default@k@family}{\default@k@series}%
105                     {\default@k@shape}}%
106     \expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
107     \directlua{luatexja.jfont.add_ktenc_list('\luatexluaescapestring{#1}')}%
108   \else
109     \@font@info{Redeclaring KANJI (tate) font encoding #1}%
110   \fi
111   \global\@namedef{T@#1}{#2}%
112   \global\@namedef{M@#1}{\default@KM#3}%
113   }
114 \@onlypreamble\DeclareKanjiEncoding
115 \@onlypreamble\DeclareYokoKanjiEncoding
116 \@onlypreamble\DeclareYokoKanjiEncoding@
117 \@onlypreamble\DeclareTateKanjiEncoding
118 \@onlypreamble\DeclareTateKanjiEncoding@
119 \def\DeclareKanjiEncodingDefaults#1#2{%
120   \ifx\relax#1\else
121     \ifx\default@KT\@empty\else
122       \@font@info{Overwriting KANJI encoding scheme text defaults}%
123     \fi
124     \gdef\default@KT{#1}%
125   \fi
126   \ifx\relax#2\else
127     \ifx\default@KM\@empty\else
128       \@font@info{Overwriting KANJI encoding scheme math defaults}%
129     \fi
130     \gdef\default@KM{#2}%
131   \fi}
132 \let\default@KT\@empty
133 \let\default@KM\@empty
134 \@onlypreamble\DeclareKanjiEncodingDefaults
135 \def\DeclareFontFamily#1#2#3{%
136  \@ifundefined{T@#1}%
137     {\@latex@error{Encoding scheme `#1' unknown}\@eha}%
138     {\def\reserved@a{#3}%
139      \global
140      \expandafter\let\csname #1+#2\expandafter\endcsname
141             \ifx \reserved@a\@empty
142               \@empty
143             \else \reserved@a
144             \fi
145     }%
146 }
147 \def\DeclareKanjiFamily#1#2#3{%
148  \@ifundefined{T@#1}%
149     {\@latex@error{KANJI Encoding scheme `#1' unknown}\@eha}%
150     {\def\reserved@a{#3}%
151      \global
152      \expandafter\let\csname #1+#2\expandafter\endcsname
153             \ifx \reserved@a\@empty
154               \@empty
155             \else \reserved@a
156             \fi
157      }%
158 }
159 \def\DeclareKanjiSubstitution#1#2#3#4{%
160   \expandafter\ifx\csname T@#1\endcsname\relax
161     \@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
162   \else
163     \begingroup
164        \def\reserved@a{#1}%
165        \toks@{}%
166        \def\cdp@elt##1##2##3##4{%
167          \def\reserved@b{##1}%
168          \ifx\reserved@a\reserved@b
169            \addto@hook\toks@{\cdp@elt{#1}{#2}{#3}{#4}}%
170          \else
171            \addto@hook\toks@{\cdp@elt{##1}{##2}{##3}{##4}}%
172          \fi}%
173        \cdp@list
174        \xdef\cdp@list{\the\toks@}%
175     \endgroup
176     \global\@namedef{D@#1}{\def\default@family{#2}%
177                            \def\default@series{#3}%
178                            \def\default@shape{#4}}%
179   \fi}
180 \def\DeclareErrorKanjiFont#1#2#3#4#5{%
181    \xdef\error@kfontshape{%
182       \noexpand\expandafter\noexpand\split@name\noexpand\string
183       \expandafter\noexpand\csname#1/#2/#3/#4/#5\endcsname
184       \noexpand\@nil}%
185    \gdef\default@k@family{#2}%
186    \gdef\default@k@series{#3}%
187    \gdef\default@k@shape{#4}%
188    \global\let\k@family\default@k@family
189    \global\let\k@series\default@k@series
190    \global\let\k@shape\default@k@shape
191    \gdef\f@size{#5}%
192    \gdef\f@baselineskip{#5pt}}
193 \@onlypreamble\DeclareKanjiSubstitution
194 \@onlypreamble\DeclareErrorKanjiFont
195 \def\DeclareFixedFont#1#2#3#4#5#6{%
196    \begingroup
197       \math@fontsfalse
198       \every@math@size{}%
199       \fontsize{#6}\z@
200       \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#2}')}\ifin@%
201         \usekanji{#2}{#3}{#4}{#5}%
202         \global\let#1\getjfont
203       \else
204         \directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{#2}')}\ifin@%
205           \usekanji{#2}{#3}{#4}{#5}%
206           \global\let#1\gettfont
207         \else
208           \useroman{#2}{#3}{#4}{#5}%
209           \global\expandafter\let\expandafter#1\the\font
210         \fi
211       \fi
212    \endgroup
213   }
214 \def\DLMfontsw@standard#1#2#3{#1{#2{#3}}}
215 \def\reDeclareMathAlphabet#1#2#3{%
216   \ifdefined#2
217     \@temptokena\expandafter{#2}%
218   \else
219     \@temptokena{#2}%
220   \fi
221   \ifdefined#3
222     \toks0\expandafter{#3}%
223   \else
224     \toks0{#3}%
225   \fi
226   \long\protected\edef#1{%
227     \noexpand\DLMfontsw@standard{\the\@temptokena}{\the\toks0}}%
228 }
229 \@onlypreamble\reDeclareMathAlphabet
230 \def\all@shape{all}%
231 \def\DeclareRelationFont#1#2#3#4#5#6#7#8{%
232   \def\rel@shape{#4}%
233   \ifx\rel@shape\@empty
234      \global
235      \expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
236        \romanencoding{#5}\romanfamily{#6}%
237        \romanseries{#7}}%
238   \else
239      \global
240      \expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
241        \romanencoding{#5}\romanfamily{#6}%
242        \romanseries{#7}\romanshape{#8}}%
243   \fi
244 }
245 \def\SetRelationFont#1#2#3#4#5#6#7#8{%
246   \def\rel@shape{#4}%
247   \ifx\rel@shape\@empty
248      \expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
249        \romanencoding{#5}\romanfamily{#6}%
250        \romanseries{#7}}%
251   \else
252      \expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
253        \romanencoding{#5}\romanfamily{#6}%
254        \romanseries{#7}\romanshape{#8}}%
255   \fi
256 }
257 \newif\if@knjcmd
258 \def\userelfont{\@knjcmdtrue}
259
260
261 \RequirePackage{everysel}
262 \@EverySelectfont@Init
263 \def\ltj@selectfont@patch{%
264  \let\tmp@error@fontshape\error@fontshape
265   \let\error@fontshape\error@kfontshape
266   \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
267     \let\cy@encoding\k@encoding
268     \edef\ct@encoding{\csname t@enc@\k@encoding\endcsname}%
269   \else
270     \directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
271      \let\ct@encoding\k@encoding
272      \edef\cy@encoding{\csname y@enc@\k@encoding\endcsname}%
273     \else
274       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
275     \fi
276   \fi
277 %
278   \let\k@encoding\ct@encoding
279   \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
280   \pickup@tfont
281   \font@name
282   \ltj@@does@alt@set{\curr@kfontshape}%
283     % alt fonts の定義
284     \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}%
285     % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
286     \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
287   \fi
288 %
289   \let\k@encoding\cy@encoding
290   \xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
291   \pickup@jfont
292   \font@name
293   \ltj@@does@alt@set{\curr@kfontshape}%
294     % alt fonts の定義
295     \directlua{luatexja.jfont.output_alt_font_cmd('\luatexluaescapestring{\curr@kfontshape}')}%
296     % 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
297     \directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
298   \fi
299 %
300   \edef\tmp@item{{\k@encoding}}\expandafter\def\expandafter\k@encoding\tmp@item
301   \kenc@update
302   \let\error@fontshape\tmp@error@fontshape
303 %
304   \if@knjcmd \@knjcmdfalse
305     \expandafter\ifx
306     \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\relax
307       \expandafter\ifx
308          \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\relax
309       \else
310          \csname rel@\k@encoding/\k@family/\k@series/all\endcsname\selectfont
311          % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
312       \fi
313     \else
314        \csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\selectfont
315        % 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
316     \fi
317   \fi
318 }
319 \EverySelectfont{\ltj@selectfont@patch}
320 \def\@EverySelectfont@Init{\let\@EverySelectfont@Init\undefined}
321
322 \def\KanjiEncodingPair#1#2{\@namedef{t@enc@#1}{#2}\@namedef{y@enc@#2}{#1}}
323 \def\set@fontsize#1#2#3{%
324     \@defaultunits\@tempdimb#2pt\relax\@nnil
325     \edef\f@size{\strip@pt\@tempdimb}%
326     \@defaultunits\@tempskipa#3pt\relax\@nnil
327     \edef\f@baselineskip{\the\@tempskipa}%
328     \edef\f@linespread{#1}%
329     \let\baselinestretch\f@linespread
330     \def\size@update{%
331       \baselineskip\f@baselineskip\relax
332       \baselineskip\f@linespread\baselineskip
333       \normalbaselineskip\baselineskip
334       \adjustbaseline
335       \setbox\strutbox\hbox{%\yoko
336           \vrule\@width\z@
337                 \@height.7\baselineskip \@depth.3\baselineskip}%
338       \setbox\tstrutbox\hbox{%\tate
339           \vrule\@width\z@
340                 \@height.5\baselineskip \@depth.5\baselineskip}%
341       \setbox\zstrutbox\hbox{%\tate
342           \vrule\@width\z@
343                 \@height.7\baselineskip \@depth.3\baselineskip}%
344         \let\size@update\relax}}
345 \newbox\adjust@box
346 \newdimen\adjust@dimen
347 \def\adjustbaseline{%
348     \setbox\adjust@box\hbox{\ltjsetparameter{yjabaselineshift=\z@}あ}%
349     \cht\ht\adjust@box
350     \cdp\dp\adjust@box
351     \cwd\wd\adjust@box
352     \cvs\normalbaselineskip
353     \chs\cwd
354     \cHT\cht \advance\cHT\cdp
355     %\iftdir
356       \setbox0\hbox{\tate\ltjsetparameter{tjabaselineshift=\z@}あ}%
357       \setbox\adjust@box\hbox{\tate\ltjsetparameter{talbaselineshift=\z@}M}%
358       \adjust@dimen\ht\adjust@box
359       \advance\adjust@dimen\dp\adjust@box
360       \advance\adjust@dimen-\ht0
361       \divide\adjust@dimen\tw@
362       \advance\adjust@dimen0.5\dp0
363       \advance\adjust@dimen-\dp\adjust@box
364       \ltjsetparameter{talbaselineshift=\adjust@dimen}
365     %\fi
366   }
367 \DeclareRobustCommand\romanencoding[1]{%
368     \expandafter\ifx\csname T@#1\endcsname\relax
369       \@latex@error{Encoding scheme `#1' unknown}\@eha
370     \else
371       \edef\f@encoding{#1}%
372       \ifx\cf@encoding\f@encoding
373         \let\enc@update\relax
374       \else
375         \let\enc@update\@@enc@update
376       \fi
377     \fi
378 }
379 \DeclareRobustCommand\kanjiencoding[1]{%
380     \expandafter\ifx\csname T@#1\endcsname\relax
381       \@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
382     \else
383       \edef\k@encoding{#1}%
384       \ifx\ck@encoding\k@encoding
385          \let\kenc@update\relax
386       \else
387          \let\kenc@update\@@kenc@update
388       \fi
389     \fi
390 }
391 \DeclareRobustCommand\fontencoding[1]{%
392   \directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#1}')}\ifin@%
393   \kanjiencoding{#1}\else\romanencoding{#1}\fi}
394 \def\@@kenc@update{%
395   \default@KT
396   \csname T@\k@encoding\endcsname
397   \csname D@\k@encoding\endcsname
398   \let\kenc@update\relax
399   \let\ck@encoding\k@encoding
400   \edef\tmp@enc{'\luatexluaescapestring{\k@encoding}'}
401   \directlua{luatexja.jfont.is_kyenc(\tmp@enc)}\ifin@%
402     \let\cy@encoding\k@encoding
403   \else
404     \directlua{luatexja.jfont.is_ktenc(\tmp@enc)}\ifin@%
405       \let\ct@encoding\k@encoding
406     \else
407       \@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
408     \fi
409   \fi
410 }
411 \let\kenc@update\relax
412 \def\@changed@kcmd#1#2{%
413    \ifx\protect\@typeset@protect
414       \@inmathwarn#1%
415       \expandafter\ifx\csname\ck@encoding\string#1\endcsname\relax
416          \expandafter\ifx\csname ?\string#1\endcsname\relax
417             \expandafter\def\csname ?\string#1\endcsname{%
418                \TextSymbolUnavailable#1%
419             }%
420          \fi
421          \global\expandafter\let
422                \csname\cf@encoding \string#1\expandafter\endcsname
423                \csname ?\string#1\endcsname
424       \fi
425       \csname\ck@encoding\string#1%
426          \expandafter\endcsname
427    \else
428       \noexpand#1%
429    \fi}
430 \newif\if@notkfam
431 \newif\if@notffam
432 \newif\if@tempswz
433 \DeclareRobustCommand\romanfamily[1]{\edef\f@family{#1}}
434 \DeclareRobustCommand\kanjifamily[1]{\edef\k@family{#1}}
435 \DeclareRobustCommand\fontfamily[1]{%
436   \@notkfamfalse\@notffamfalse
437   \edef\tmp@item{'\luatexluaescapestring{#1}'}%
438   \edef\tmp@enc{'\luatexluaescapestring{\k@encoding}'}%
439   \ifcsname \k@encoding+#1\endcsname % if \k@encoding+#1 is already defined
440     \edef\k@family{#1}%
441   \else % search font definition file...
442      \directlua{luatexja.jfont.is_kfam(\tmp@enc, \tmp@item)}%
443      \ifin@\edef\k@family{#1}\else%
444        \directlua{luatexja.jfont.is_Nkfam(\tmp@enc, \tmp@item)}%
445        \ifin@\@notkfamtrue\else%
446          % filename of font definition file is always lowercase
447          \edef\@temp{\lowercase{\noexpand\IfFileExists{\k@encoding#1.fd}}}%
448          \message{(I search kanjifont definition file)}%
449          \@temp{\@tempswztrue}{\@tempswzfalse}%
450          \if@tempswz
451            \directlua{luatexja.jfont.add_kfam_list(\tmp@enc, \tmp@item)}%
452            \edef\k@family{#1}%
453          \else
454            \directlua{luatexja.jfont.add_Nkfam_list(\tmp@enc, \tmp@item)}%
455            \@notkfamtrue%
456          \fi
457        \fi
458      \fi
459   \fi
460   \edef\tmp@enc{'\luatexluaescapestring{\f@encoding}'}%
461   \ifcsname \f@encoding+#1\endcsname
462     \edef\f@family{#1}%
463   \else % search font definition file...
464      \directlua{luatexja.jfont.is_ffam(\tmp@enc, \tmp@item)}%
465      \ifin@\edef\f@family{#1}\else
466        \directlua{luatexja.jfont.is_Nffam(\tmp@enc, \tmp@item)}%
467        \ifin@\@notffamtrue\else
468          % filename of font definition file is always lowercase
469          \edef\@temp{\lowercase{\noexpand\IfFileExists{\f@encoding#1.fd}}}%
470          \message{(I search font definition file)}%
471          \@temp{\@tempswztrue}{\@tempswzfalse}%
472          \if@tempswz
473            \directlua{luatexja.jfont.add_ffam_list(\tmp@enc, \tmp@item)}%
474            \edef\f@family{#1}%
475          \else
476            \directlua{luatexja.jfont.add_Nffam_list(\tmp@enc, \tmp@item)}%
477            \@notffamtrue%
478          \fi
479        \fi
480      \fi
481   \fi
482   \if@notkfam\if@notffam
483       {\ifcsname D@\k@encoding\endcsname\@nameuse{D@\k@encoding}\fi
484         \xdef\@@temp{\default@family}}\edef\k@family{\@@temp}%
485       {\ifcsname D@\f@encoding\endcsname\@nameuse{D@\f@encoding}\fi
486         \xdef\@@temp{\default@family}}\edef\f@family{\@@temp}%
487   \fi\fi
488 }
489 \DeclareRobustCommand\romanseries[1]{\edef\f@series{#1}}
490 \DeclareRobustCommand\kanjiseries[1]{\edef\k@series{#1}}
491 \DeclareRobustCommand\fontseries[1]{\kanjiseries{#1}\romanseries{#1}}
492 \DeclareRobustCommand\romanshape[1]{\edef\f@shape{#1}}
493 \DeclareRobustCommand\kanjishape[1]{\edef\k@shape{#1}}
494 \DeclareRobustCommand\fontshape[1]{\kanjishape{#1}\romanshape{#1}}
495 \def\usekanji#1#2#3#4{%
496     \kanjiencoding{#1}\kanjifamily{#2}\kanjiseries{#3}\kanjishape{#4}%
497     \selectfont\ignorespaces}
498 \def\useroman#1#2#3#4{%
499     \romanencoding{#1}\romanfamily{#2}\romanseries{#3}\romanshape{#4}%
500     \selectfont\ignorespaces}
501 \protected\def\usefont#1#2#3#4{%
502   \directlua{luatexja.jfont.is_kenc('\luatexluaescapestring{#1}')}\ifin@%
503   \usekanji{#1}{#2}{#3}{#4}%
504   \else\useroman{#1}{#2}{#3}{#4}%
505   \fi}
506 \DeclareRobustCommand\normalfont{%
507     \kanjiencoding{\kanjiencodingdefault}%
508     \kanjifamily{\kanjifamilydefault}%
509     \kanjiseries{\kanjiseriesdefault}%
510     \kanjishape{\kanjishapedefault}%
511     \romanencoding{\encodingdefault}%
512     \romanfamily{\familydefault}%
513     \romanseries{\seriesdefault}%
514     \romanshape{\shapedefault}%
515     \selectfont\ignorespaces}
516 \let\reset@font\normalfont
517 \DeclareRobustCommand\mcfamily
518         {\not@math@alphabet\mcfamily\mathmc
519          \kanjifamily\mcdefault\selectfont}
520 \DeclareRobustCommand\gtfamily
521         {\not@math@alphabet\gtfamily\mathgt
522          \kanjifamily\gtdefault\selectfont}
523 \let\romanprocess@table\process@table
524 \def\kanjiprocess@table{%
525   \kanjiencoding{\kanjiencodingdefault}%
526   \kanjifamily{\kanjifamilydefault}%
527   \kanjiseries{\kanjiseriesdefault}%
528   \kanjishape{\kanjishapedefault}%
529 }
530 \def\process@table{%
531   \romanprocess@table
532   \kanjiprocess@table
533 }
534 \@onlypreamble\romanprocess@table
535 \@onlypreamble\kanjiprocess@table
536 \DeclareTextCommandDefault{\textunderscore}{%
537   \leavevmode\kern.06em
538   %\iftdir\raise-\tbaselineshift\fi
539   \vbox{\hrule\@width.3em}}
540
541 %%%%%% LuaTeX-ja specific
542
543 % #1 の展開結果から encoding 部分をとりだし,それが和文用かどうかの結果を \ifin@ に代入
544 \def\ltj@@IsFontJapanese#1{%
545   \directlua{luatexja.jfont.is_kenc(string.match(
546       '\luatexluaescapestring{#1}', '[^/]+'))}}
547
548
549 \let\extract@afont\extract@font
550 \def\pickup@jfont{%
551     \expandafter \ifx \font@name \relax
552        \let\extract@font\extract@jfont
553        \define@newfont
554        \let\extract@font\extract@afont
555     \fi
556     \let\getjfont\font@name}
557 \def\pickup@tfont{%
558     \expandafter \ifx \font@name \relax
559        \let\extract@font\extract@tfont
560        \define@newfont
561        \let\extract@font\extract@afont
562     \fi
563     \let\gettfont\font@name}
564
565 % 異なる和文 enc/fam/ser/shape からは異なるフォント番号が振られるように
566 % わざと「ゴミをつける」
567 \def\ltj@@patch@external@font#1 at{%
568   #1\directlua{luatexja.jfont.print_aftl_address()}\space at%
569 }
570 \def\extract@jfont{%
571    \get@external@font
572     \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}%
573       \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
574     \fi
575     \expandafter\globaljfont\font@name\external@font\relax
576     \font@name%\global\zw=\zw\global\zh=\zh
577     \csname \f@encoding+\f@family\endcsname
578     \csname\curr@fontshape\endcsname}
579 \def\extract@tfont{%
580    \get@external@font
581     \ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}%
582       \edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
583     \fi
584     \expandafter\globaltfont\font@name\external@font\relax
585     \font@name%\global\zw=\zw\global\zh=\zh
586     \csname \f@encoding+\f@family\endcsname
587     \csname\curr@fontshape\endcsname}
588
589 \let\ltj@@al@do@subst@correction=\do@subst@correction
590 \def\ltj@@ja@do@subst@correction{%
591     \xdef\subst@correction{%
592       \font@name
593       \global\expandafter\let\csname \curr@fontshape/\f@size\endcsname\font@name%
594       \relax}%
595     \aftergroup\subst@correction
596 }
597 \def\do@subst@correction{%
598    \ltj@@IsFontJapanese{\curr@fontshape}\ifin@%
599      \ltj@@ja@do@subst@correction
600    \else
601      \ltj@@al@do@subst@correction
602    \fi
603 }
604 \let\@@italiccorr=\/
605
606 %%%%%% Japanese font for math mode
607
608 % \M@<enc> から その <enc> が和文用か調べる
609 {\catcode`M=12%
610 \gdef\ltj@@mathJapaneseFonts#1M#2#3\relax{\ltj@@IsFontJapanese{#3}}}
611
612 \let\ltj@@al@getanddefine@fonts=\getanddefine@fonts
613 \def\ltj@@ja@getanddefine@fonts#1#2{%
614   \xdef\font@name{\csname \string#2/\tf@size\endcsname}%
615   \pickup@jfont\let\textfont@name\font@name
616   \xdef\font@name{\csname \string#2/\sf@size\endcsname}%
617   \pickup@jfont\let\scriptfont@name\font@name
618   \xdef\font@name{\csname \string#2/\ssf@size\endcsname}%
619   \pickup@jfont
620   \edef\math@fonts{\math@fonts\ltj@setpar@global%
621     \ltj@@set@stackfont#1,\textfont@name:{MJT}%
622     \ltj@@set@stackfont#1,\scriptfont@name:{MJS}%
623     \ltj@@set@stackfont#1,\font@name:{MJSS}%
624   }%
625 }
626
627 \def\getanddefine@fonts#1#2{%
628   \ltj@tempcnta=#1\ltj@@IsFontJapanese{\string#2}%
629   \ifin@\let\ltj@temp=\ltj@@ja@getanddefine@fonts%
630   \else \let\ltj@temp=\ltj@@al@getanddefine@fonts\fi
631   \ltj@temp{#1}{#2}%
632 }
633 \def\use@mathgroup#1#2{\relax\ifmmode
634   \math@bgroup
635     \expandafter\ifx\csname M@\f@encoding\endcsname#1\else
636     #1\fi\ltj@tempcnta=#2 \expandafter\ltj@@mathJapaneseFonts\string#1\relax%
637     \ifin@\jfam#2\relax\else\mathgroup#2\relax\fi
638   \expandafter\math@egroup\fi}%
639
640 %%%%%% Alternate Japanese Fonts
641 %%%% \DeclareAlternateKanjiFont<Benc><Bfam><Bser><Bshape><Aenc><Afam><Aser><Ashape><range>
642 % いつも global
643 \def\DeclareAlternateKanjiFont#1#2#3#4#5#6#7#8#9{%
644   \edef\@temp{#9}%
645   \ifx\@temp\@empty\else
646     {\def\ltj@temp@bfont{#1/#2/#3/#4}\def\ltj@temp@afont{#5/#6/#7/#8}%
647      \expandafter\ltj@@altfont@latex#9,,}\ignorespaces
648   \fi}
649 \def\ltj@@altfont@latex#1,{\def\ltj@temp{#1}%
650   \ifx\ltj@temp\empty\let\@next=\relax\else
651   \ltj@@altfont@latexA{#1}\let\@next=\ltj@@altfont@latex\fi\@next}
652 \def\ltj@@altfont@latexA#1{\ltj@@altfont@latexB#1--\@nil}
653 \def\ltj@@altfont@latexB#1-#2-#3\@nil{\def\ltj@temp{#3}%
654   \ifx\ltj@temp\empty
655     \ltj@tempcnta=#1\relax\ltj@tempcntb=\ltj@tempcnta
656   \else
657     \def\ltj@temp{#1}%
658     \ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
659     \def\ltj@temp{#2}%
660     \ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
661   \fi
662   \directlua{luatexja.jfont.set_alt_font_latex(
663     \the\ltj@tempcnta,\the\ltj@tempcntb,
664     '\luatexluaescapestring{\ltj@temp@afont}',
665     '\luatexluaescapestring{\ltj@temp@bfont}')}%
666   }
667
668 %%%% \ClearAlternateKanjiFont<Benc><Bfam><Bser><Bshape>
669 % いつも global
670 \def\ClearAlternateKanjiFont#1#2#3#4{%
671    \directlua{luatexja.jfont.clear_alt_font_latex('\luatexluaescapestring{#1/#2/#3/#4}')}}
672
673 \def\ltj@pickup@altfont@aux#1{%
674   \begingroup\edef\font@name{\csname #1/\f@size\endcsname}\pickup@jfont\endgroup%
675 }
676 \def\ltj@pickup@altfont@copy#1#2{%
677   \ltj@@getjfontnumber#1%
678   \directlua{luatexja.jfont.pickup_alt_font_b(\the\ltj@tempcntc,'\luatexluaescapestring{#2}')}%
679 }
680
681 \def\ltj@@does@alt@set#1{%
682   \directlua{luatexja.jfont.does_alt_set'\luatexluaescapestring{#1}'}}
683
684 \endinput