%#!lualatex
\documentclass{ltjsarticle}
\usepackage{fontspec}% 欧文フォントを OpenType にしたいだけ

%%% この文書のタイプセットには，
%%% KozMinPr6N-Regular.otf, KozGoPr6N-Medium.otf,
%%% ipag.ttf が必要

\DeclareKanjiFamily{JY3}{mcX}{}
\DeclareKanjiFamily{JY3}{gtX}{}
\DeclareFontShape{JY3}{mcX}{m}{n}{<-> s*[0.962216] KozMinPr6N-Regular:jfm=ujis}{}
\DeclareFontShape{JY3}{gtX}{m}{n}{<-> s*[0.962216] KozGoPr6N-Medium:jfm=ujis}{}
\DeclareFontShape{JY3}{mcX}{bx}{n}{<-> ssub*gtX/m/n}{}
\def\mcdefault{mcX}
\def\gtdefault{gtX}

\begin{document}

%%%%%%%% plain TeX
\jfont\jaA={KozMinPr6N-Regular:jfm=ujis} at 9.24872pt
\jfont\jaB={KozGoPr6N-Medium:jfm=ujis}   at 9.24872pt
\jfont\jaC={IPAGothic:jfm=ujis}          at 9.24872pt

\jaA 
あア漢字% 置換なし

\ltjdeclarealtfont\jaA\jaB{"3000-"30FF}
あア漢字% 「あ」のみ置換（段落末尾の状況が全段落で通用）
\ltjdeclarealtfont\jaA\jaA{"30A0-"30FF}
あア漢字% 「あ」のみ置換

\ltjdeclarealtfont\jaA\jaB{"3000-"30FF}
\ltjdeclarealtfont\jaA\jaC{`漢}
あア漢字% 「あ」「ア」「漢」置換
\mc
あア漢字% 置換なし
\jaA 
あア漢字% 「あ」「ア」「漢」置換

\jaA 
あア漢字% 置換なし，\ltjclearaltfont の効力はこの段落全部なので
\ltjclearaltfont\jaA
あア漢字% 置換なし

% 文字クラスベースの指定
\jfont\jaR={IPAGothic:jfm=ujis;color=FF0000} at 9.24872pt
\jfont\jaP={IPAGothic:jfm=ujis;color=7F007F} at 9.24872pt
\jaA 
\ltjdeclarealtfont\jaA\jaR{{-1}-{-2}}
\ltjdeclarealtfont\jaA\jaP{{-6}-{-6}}
この文章は，（あんまり）意味がないサンプルテキストです⁈

\scrollmode
\font\g=cmr10
\ltjdeclarealtfont\jaA\g{"3000-"30FF}% error
\ltjdeclarealtfont\g\jaA{"3000-"30FF}% error
\errorstopmode

%%%%%%%% LaTeX

\DeclareAlternateKanjiFont{JY3}{mcX}{m}{n}{JY3}{gtX}{m}{n}{`い,`う}
\mc
あいうえお%             \selectfont しないと有効にはならない
\selectfont あいうえお% 「い」「う」が置換
{\Large  あいうえお}

{%
  \DeclareAlternateKanjiFont{JY3}{mcX}{m}{n}{JY3}{mcX}{m}{n}{`い}%
}% always global
\DeclareAlternateKanjiFont{JY3}{mcX}{m}{n}{JY3}{gtX}{m}{n}{`お}
\selectfont あいうえお% 「う」「お」が置換
{\Large  あいうえお}

\ClearAlternateKanjiFont{JY3}{mcX}{m}{n}
{\Large  あいうえお}%    置換なし
あいうえお%              まだ「う」「お」が置換のまま 

\section{例1}

\DeclareFontShape{JY3}{gtX}{an}{n}{<-> s*[0.962216] KozGoPr6N-Medium:jfm=ujis}{}
\DeclareFontShape{JY3}{mcX}{bx}{kana}{<-> s*[0.962216] KozMinPr6N-Regular:jfm=ujis}{}
\DeclareAlternateKanjiFont{JY3}{gtX}{an}{n}{JY3}{mcX}{bx}{kana}{"3000-"30FF}

{\Large\gt 
漢字をゴシック体，仮名を明朝を使って
{\kanjiseries{an}\selectfont このように文章を組む}
ことが可能になった（太さが合わないのは気にしない）．}

\section{例2：メトリックの文字クラスによる指定}

\ClearAlternateKanjiFont{JY3}{gtX}{an}{n}% 一旦リセットして……
\DeclareFontShape{JY3}{gtX}{m}{red}{<-> s*[0.962216] KozGoPr6N-Medium:jfm=ujis;color=FF0000}{}
\DeclareFontShape{JY3}{gtX}{m}{blue}{<-> s*[0.962216] KozGoPr6N-Medium:jfm=ujis;color=0000FF}{}
\DeclareAlternateKanjiFont{JY3}{gtX}{an}{n}{JY3}{gtX}{m}{red}{{-7}-{-7}}% 半角カナ
% ... {{-7}} のようにはできないので注意
\DeclareAlternateKanjiFont{JY3}{gtX}{an}{n}{JY3}{gtX}{m}{blue}{{-1}-{-2}}% 括弧類

{\kanjifamily{gtX}\kanjiseries{an}\selectfont
半角ｶﾀｶﾅとか「括弧類」だけ色を変えてみた（うまくいっているだろうか？）．
}

\paragraph{fwid feature}
\DeclareFontShape{JY3}{gtX}{af}{n}{<-> s*[0.962216] KozGoPr6N-Medium:jfm=ujis;+fwid}{}
  % fwid weature 使用

{\kanjifamily{gtX}\kanjiseries{af}\selectfont
fwid featureﾉﾀﾒ通常ﾃﾞﾊ半角ｶﾅﾊ全角化ｻﾚﾙ

\DeclareAlternateKanjiFont{JY3}{gtX}{af}{n}{JY3}{gtX}{m}{red}{{-7}-{-7}}% 半角カナ
\DeclareAlternateKanjiFont{JY3}{gtX}{af}{n}{JY3}{gtX}{m}{blue}{{-1}-{-2}}% 括弧類
\selectfont
ｼｶｼ \verb+\DeclareAlternateKanjiFont+ ﾆﾖﾙ置ｷ換ｴﾊfont featureﾆﾖﾙ置換ﾉﾏｴﾆ実施
ｻﾚﾙ．なおかつ置き換え先のフォントにはfwid featureは設定されていないので，
ｺﾉﾖｳﾆ半角ｶﾅﾊ赤字・半角ﾉﾏﾏ．
}


\newpage
\section{例2：教育漢字を強調する}
青文字は日本の小学校で学ぶ教育漢字で，
緑文字はU+4E00--U+9FFF (CJK Unified Ideographs)に属するその他の文字．

\DeclareKanjiFamily{JY3}{edm}{}
\DeclareFontShape{JY3}{edm}{m}{n}{<-> s*[0.962216] 
  KozMinPr6N-Regular:jfm=ujis}{}
\DeclareFontShape{JY3}{edm}{m}{blue}{<-> s*[0.962216] 
  KozGoPr6N-Medium:jfm=ujis;color=0000FF}{}
\DeclareFontShape{JY3}{edm}{m}{green}{<-> s*[0.962216] 
  KozMinPr6N-Regular:jfm=ujis;color=007F00}{}

%%% 16進表記の A--F は大文字で！

% U+4E00--U+9FFF は JY3/edm/m/green を使う
\DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{green}{"4E00-"9FFF}%
% しかし，その中でも教育漢字は JY3/edm/m/blue を使う
\DeclareAlternateKanjiFont{JY3}{edm}{m}{n}{JY3}{edm}{m}{blue}{%
  "4E00,"53F3,"96E8,"5186,"738B,"97F3,"4E0B,"706B,"82B1,"8C9D,"5B66,"6C17,"4E5D,
  "4F11,"7389,"91D1,"7A7A,"6708,"72AC,"898B,"4E94,"53E3,"6821,"5DE6,"4E09,"5C71,
  "5B50,"56DB,"7CF8,"5B57,"8033,"4E03,"8ECA,"624B,"5341,"51FA,"5973,"5C0F,"4E0A,
  "68EE,"4EBA,"6C34,"6B63,"751F,"9752,"5915,"77F3,"8D64,"5343,"5DDD,"5148,"65E9,
  "8349,"8DB3,"6751,"5927,"7537,"7AF9,"4E2D,"866B,"753A,"5929,"7530,"571F,"4E8C,
  "65E5,"5165,"5E74,"767D,"516B,"767E,"6587,"6728,"672C,"540D,"76EE,"7ACB,"529B,
  "6797,"516D,"5F15,"7FBD,"96F2,"5712,"9060,"4F55,"79D1,"590F,"5BB6,"6B4C,"753B,
  "56DE,"4F1A,"6D77,"7D75,"5916,"89D2,"697D,"6D3B,"9593,"4E38,"5CA9,"9854,"6C7D,
  "8A18,"5E30,"5F13,"725B,"9B5A,"4EAC,"5F37,"6559,"8FD1,"5144,"5F62,"8A08,"5143,
  "8A00,"539F,"6238,"53E4,"5348,"5F8C,"8A9E,"5DE5,"516C,"5E83,"4EA4,"5149,"8003,
  "884C,"9AD8,"9EC4,"5408,"8C37,"56FD,"9ED2,"4ECA,"624D,"7D30,"4F5C,"7B97,"6B62,
  "5E02,"77E2,"59C9,"601D,"7D19,"5BFA,"81EA,"6642,"5BA4,"793E,"5F31,"9996,"79CB,
  "9031,"6625,"66F8,"5C11,"5834,"8272,"98DF,"5FC3,"65B0,"89AA,"56F3,"6570,"897F,
  "58F0,"661F,"6674,"5207,"96EA,"8239,"7DDA,"524D,"7D44,"8D70,"591A,"592A,"4F53,
  "53F0,"5730,"6C60,"77E5,"8336,"663C,"9577,"9CE5,"671D,"76F4,"901A,"5F1F,"5E97,
  "70B9,"96FB,"5200,"51AC,"5F53,"6771,"7B54,"982D,"540C,"9053,"8AAD,"5185,"5357,
  "8089,"99AC,"58F2,"8CB7,"9EA6,"534A,"756A,"7236,"98A8,"5206,"805E,"7C73,"6B69,
  "6BCD,"65B9,"5317,"6BCE,"59B9,"4E07,"660E,"9CF4,"6BDB,"9580,"591C,"91CE,"53CB,
  "7528,"66DC,"6765,"91CC,"7406,"8A71,"60AA,"5B89,"6697,"533B,"59D4,"610F,"80B2,
  "54E1,"9662,"98F2,"904B,"6CF3,"99C5,"592E,"6A2A,"5C4B,"6E29,"5316,"8377,"754C,
  "958B,"968E,"5BD2,"611F,"6F22,"9928,"5CB8,"8D77,"671F,"5BA2,"7A76,"6025,"7D1A,
  "5BAE,"7403,"53BB,"6A4B,"696D,"66F2,"5C40,"9280,"533A,"82E6,"5177,"541B,"4FC2,
  "8EFD,"8840,"6C7A,"7814,"770C,"5EAB,"6E56,"5411,"5E78,"6E2F,"53F7,"6839,"796D,
  "76BF,"4ED5,"6B7B,"4F7F,"59CB,"6307,"6B6F,"8A69,"6B21,"4E8B,"6301,"5F0F,"5B9F,
  "5199,"8005,"4E3B,"5B88,"53D6,"9152,"53D7,"5DDE,"62FE,"7D42,"7FD2,"96C6,"4F4F,
  "91CD,"5BBF,"6240,"6691,"52A9,"662D,"6D88,"5546,"7AE0,"52DD,"4E57,"690D,"7533,
  "8EAB,"795E,"771F,"6DF1,"9032,"4E16,"6574,"6614,"5168,"76F8,"9001,"60F3,"606F,
  "901F,"65CF,"4ED6,"6253,"5BFE,"5F85,"4EE3,"7B2C,"984C,"70AD,"77ED,"8AC7,"7740,
  "6CE8,"67F1,"4E01,"5E33,"8ABF,"8FFD,"5B9A,"5EAD,"7B1B,"9244,"8EE2,"90FD,"5EA6,
  "6295,"8C46,"5CF6,"6E6F,"767B,"7B49,"52D5,"7AE5,"8FB2,"6CE2,"914D,"500D,"7BB1,
  "7551,"767A,"53CD,"5742,"677F,"76AE,"60B2,"7F8E,"9F3B,"7B46,"6C37,"8868,"79D2,
  "75C5,"54C1,"8CA0,"90E8,"670D,"798F,"7269,"5E73,"8FD4,"52C9,"653E,"5473,"547D,
  "9762,"554F,"5F79,"85AC,"7531,"6CB9,"6709,"904A,"4E88,"7F8A,"6D0B,"8449,"967D,
  "69D8,"843D,"6D41,"65C5,"4E21,"7DD1,"793C,"5217,"7DF4,"8DEF,"548C,"611B,"6848,
  "4EE5,"8863,"4F4D,"56F2,"80C3,"5370,"82F1,"6804,"5869,"5104,"52A0,"679C,"8CA8,
  "8AB2,"82BD,"6539,"68B0,"5BB3,"8857,"5404,"899A,"5B8C,"5B98,"7BA1,"95A2,"89B3,
  "9858,"5E0C,"5B63,"7D00,"559C,"65D7,"5668,"6A5F,"8B70,"6C42,"6CE3,"6551,"7D66,
  "6319,"6F01,"5171,"5354,"93E1,"7AF6,"6975,"8A13,"8ECD,"90E1,"5F84,"578B,"666F,
  "82B8,"6B20,"7D50,"5EFA,"5065,"9A13,"56FA,"529F,"597D,"5019,"822A,"5EB7,"544A,
  "5DEE,"83DC,"6700,"6750,"6628,"672D,"5237,"6BBA,"5BDF,"53C2,"7523,"6563,"6B8B,
  "58EB,"6C0F,"53F2,"53F8,"8A66,"5150,"6CBB,"8F9E,"5931,"501F,"7A2E,"5468,"795D,
  "9806,"521D,"677E,"7B11,"5531,"713C,"8C61,"7167,"8CDE,"81E3,"4FE1,"6210,"7701,
  "6E05,"9759,"5E2D,"7A4D,"6298,"7BC0,"8AAC,"6D45,"6226,"9078,"7136,"4E89,"5009,
  "5DE3,"675F,"5074,"7D9A,"5352,"5B6B,"5E2F,"968A,"9054,"5358,"7F6E,"4EF2,"8CAF,
  "5146,"8178,"4F4E,"5E95,"505C,"7684,"5178,"4F1D,"5F92,"52AA,"706F,"5802,"50CD,
  "7279,"5F97,"6BD2,"71B1,"5FF5,"6557,"6885,"535A,"98EF,"98DB,"8CBB,"5FC5,"7968,
  "6A19,"4E0D,"592B,"4ED8,"5E9C,"526F,"7C89,"5175,"5225,"8FBA,"5909,"4FBF,"5305,
  "6CD5,"671B,"7267,"672B,"6E80,"672A,"8108,"6C11,"7121,"7D04,"52C7,"8981,"990A,
  "6D74,"5229,"9678,"826F,"6599,"91CF,"8F2A,"985E,"4EE4,"51B7,"4F8B,"6B74,"9023,
  "8001,"52B4,"9332,"5727,"79FB,"56E0,"6C38,"55B6,"885B,"6613,"76CA,"6DB2,"6F14,
  "5FDC,"5F80,"685C,"6069,"53EF,"4EEE,"4FA1,"6CB3,"904E,"8CC0,"5FEB,"89E3,"683C,
  "78BA,"984D,"520A,"5E79,"6163,"773C,"57FA,"5BC4,"898F,"6280,"7FA9,"9006,"4E45,
  "65E7,"5C45,"8A31,"5883,"5747,"7981,"53E5,"7FA4,"7D4C,"6F54,"4EF6,"5238,"967A,
  "691C,"9650,"73FE,"6E1B,"6545,"500B,"8B77,"52B9,"539A,"8015,"9271,"69CB,"8208,
  "8B1B,"6DF7,"67FB,"518D,"707D,"59BB,"63A1,"969B,"5728,"8CA1,"7F6A,"96D1,"9178,
  "8CDB,"652F,"5FD7,"679D,"5E2B,"8CC7,"98FC,"793A,"4F3C,"8B58,"8CEA,"820E,"8B1D,
  "6388,"4FEE,"8FF0,"8853,"6E96,"5E8F,"62DB,"627F,"8A3C,"6761,"72B6,"5E38,"60C5,
  "7E54,"8077,"5236,"6027,"653F,"52E2,"7CBE,"88FD,"7A0E,"8CAC,"7E3E,"63A5,"8A2D,
  "820C,"7D76,"92AD,"7956,"7D20,"7DCF,"9020,"50CF,"5897,"5247,"6E2C,"5C5E,"7387,
  "640D,"9000,"8CB8,"614B,"56E3,"65AD,"7BC9,"5F35,"63D0,"7A0B,"9069,"6575,"7D71,
  "9285,"5C0E,"5FB3,"72EC,"4EFB,"71C3,"80FD,"7834,"72AF,"5224,"7248,"6BD4,"80A5,
  "975E,"5099,"4FF5,"8A55,"8CA7,"5E03,"5A66,"5BCC,"6B66,"5FA9,"8907,"4ECF,"7DE8,
  "5F01,"4FDD,"5893,"5831,"8C4A,"9632,"8CBF,"66B4,"52D9,"5922,"8FF7,"7DBF,"8F38,
  "4F59,"9810,"5BB9,"7565,"7559,"9818,"7570,"907A,"57DF,"5B87,"6620,"5EF6,"6CBF,
  "6211,"7070,"62E1,"9769,"95A3,"5272,"682A,"5E72,"5DFB,"770B,"7C21,"5371,"673A,
  "63EE,"8CB4,"7591,"5438,"4F9B,"80F8,"90F7,"52E4,"7B4B,"7CFB,"656C,"8B66,"5287,
  "6FC0,"7A74,"7D79,"6A29,"61B2,"6E90,"53B3,"5DF1,"547C,"8AA4,"540E,"5B5D,"7687,
  "7D05,"964D,"92FC,"523B,"7A40,"9AA8,"56F0,"7802,"5EA7,"6E08,"88C1,"7B56,"518A,
  "8695,"81F3,"79C1,"59FF,"8996,"8A5E,"8A8C,"78C1,"5C04,"6368,"5C3A,"82E5,"6A39,
  "53CE,"5B97,"5C31,"8846,"5F93,"7E26,"7E2E,"719F,"7D14,"51E6,"7F72,"8AF8,"9664,
  "5C06,"50B7,"969C,"57CE,"84B8,"91DD,"4EC1,"5782,"63A8,"5BF8,"76DB,"8056,"8AA0,
  "5BA3,"5C02,"6CC9,"6D17,"67D3,"5584,"594F,"7A93,"5275,"88C5,"5C64,"64CD,"8535,
  "81D3,"5B58,"5C0A,"5B85,"62C5,"63A2,"8A95,"6BB5,"6696,"5024,"5B99,"5FE0,"8457,
  "5E81,"9802,"6F6E,"8CC3,"75DB,"5C55,"8A0E,"515A,"7CD6,"5C4A,"96E3,"4E73,"8A8D,
  "7D0D,"8133,"6D3E,"62DD,"80CC,"80BA,"4FF3,"73ED,"6669,"5426,"6279,"79D8,"8179,
  "596E,"4E26,"965B,"9589,"7247,"88DC,"66AE,"5B9D,"8A2A,"4EA1,"5FD8,"68D2,"679A,
  "5E55,"5BC6,"76DF,"6A21,"8A33,"90F5,"512A,"5E7C,"6B32,"7FCC,"4E71,"5375,"89A7,
  "88CF,"5F8B,"81E8,"6717,"8AD6}

\paragraph{日本国憲法　前文}

{\kanjifamily{edm}\selectfont
日本国民は、正当に選挙された国会における代表者を通じて行動し、われらとわれらの子孫のために、
諸国民との協和による成果と、わが国全土にわたつて自由のもたらす恵沢を確保し、政府の行為によ
つて再び戦争の惨禍が起ることのないやうにすることを決意し、ここに主権が国民に存することを宣
言し、この憲法を確定する。そもそも国政は、国民の厳粛な信託によるものであつて、その権威は国
民に由来し、その権力は国民の代表者がこれを行使し、その福利は国民がこれを享受する。これは人
類普遍の原理であり、この憲法は、かかる原理に基くものである。われらは、これに反する一切の憲
法、法令及び詔勅を排除する。

日本国民は、恒久の平和を念願し、人間相互の関係を支配する崇高な理想を深く自覚するのであつて、
平和を愛する諸国民の公正と信義に信頼して、われらの安全と生存を保持しようと決意した。われら
は、平和を維持し、専制と隷従、圧迫と偏狭を地上から永遠に除去しようと努めてゐる国際社会にお
いて、名誉ある地位を占めたいと思ふ。われらは、全世界の国民が、ひとしく恐怖と欠乏から免かれ、
平和のうちに生存する権利を有することを確認する。

われらは、いづれの国家も、自国のことのみに専念して他国を無視してはならないのであつて、政治
道徳の法則は、普遍的なものであり、この法則に従ふことは、自国の主権を維持し、他国と対等関係
に立たうとする各国の責務であると信ずる。

日本国民は、国家の名誉にかけ、全力をあげてこの崇高な理想と目的を達成することを誓ふ。
}

\paragraph{大日本帝國憲法　「上諭」}\ \\
Wikisource (\texttt{http://ja.wikisource.org/wiki/大日本帝國憲法})中の
「JIS~X~0208版」から引用．

\medskip

{\kanjifamily{edm}\selectfont
朕祖宗ノ遺烈ヲ承ケ萬世一系ノ帝位ヲ踐ミ朕カ親愛スル所ノ臣民ハ即チ朕カ祖宗ノ惠撫慈養シタマヒ
シ所ノ臣民ナルヲ念ヒ其ノ康福ヲ増進シ其ノ懿徳良能ヲ發達セシメムコトヲ願ヒ又其ノ翼贊ニ依リ與
ニ倶ニ國家ノ進運ヲ扶持セムコトヲ望ミ乃チ明治十四年十月十二日ノ詔命ヲ履踐シ茲ニ大憲ヲ制
定シ朕カ率由スル所ヲ示シ朕カ後嗣及臣民及臣民ノ子孫タル者ヲシテ永遠ニ循行スル所ヲ知ラシム

國家統治ノ大權ハ朕カ之ヲ祖宗ニ承ケテ之ヲ子孫ニ傳フル所ナリ朕及朕カ子孫ハ將來此ノ憲法ノ條章
ニ循ヒ之ヲ行フコトヲ愆ラサルヘシ

朕ハ我カ臣民ノ權利及財産ノ安全ヲ貴重シ及之ヲ保護シ此ノ憲法及法律ノ範圍内ニ於テ其ノ享有ヲ完
全ナラシムヘキコトヲ宣言ス

帝國議會ハ明治二十三年ヲ以テ之ヲ召集シ議會開會ノ時ヲ以テ此ノ憲法ヲシテ有効ナラシムルノ期ト
スヘシ

將來若此ノ憲法ノ或ル條章ヲ改定スルノ必要ナル時宜ヲ見ルニ至ラハ朕及朕カ繼統ノ子孫ハ發議ノ權
ヲ執リ之ヲ議會ニ付シ議會ハ此ノ憲法ニ定メタル要件ニ依リ之ヲ議決スルノ外朕カ子孫及臣民ハ敢テ
之カ紛更ヲ試ミルコトヲ得サルヘシ

朕カ在廷ノ大臣ハ朕カ爲ニ此ノ憲法ヲ施行スルノ責ニ任スヘク朕カ現在及將來ノ臣民ハ此ノ憲法ニ對
シ永遠ニ從順ノ義務ヲ負フヘシ
}


\end{document}
