これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。
HTML ファイル生成日時: 2024/11/24 14:07:03.493 (台灣標準時)
これまでは、 latex コマンドを使って DVI ファイルを生成し、できた DVI ファイルを PS ファイルに変換し、更にその PS ファイルを PDF ファイルに 変換していたでござる。分量の大きな文書になると、 PDF ファイルを作るの に、数分間もかかっていたでござる。 pdfTeX や LuaTeX だと直接に PDF ファ イルを作ることができるので、短い時間で処理が終わりそうでござる。ただ、 日本語も中国語も取り扱うことができることを確認しなくては、 LuaTeX に乗 り換えられないので、それについて調べてみたでござる。 DVI mode で LaTeX を使っていたときには、 latex-cjk を使って日本語と中国語のどちらも使え るようにしたいたでござる。
LuaTeX を使って、日本語の平仮名、片仮名、漢字と中国語の漢字が混在した PDF ファイルを作成するにはどのようにすればよいのか調べ、上手くいくかど うか実際に試してみたでござる。
LuaTeX でフォント関連の設定を行うには、 fontspec というパッケージを使 えばよいようでござる。 "\setmainfont", "\setsansfont", "\setmonofont" でデフォルトの欧文 フォントを指定し、 "\setmainjfont", "\setsansjfont", "\setmonojfont" でデフォルトの日 本語フォントを指定すればよいようでござる。また、デフォルトのフォント以 外のフォントを使おうとする場合には、 "\newfontfamily" と "\newjfontfamily" を使って使いたいフォントの設定を行えばよい ようでござる。フォントの指定には、フォントのファイル名 (foo.otf や bar.ttf) を使ってもよいし、フォント名を使ってもよいようでござる。また、 bold font や italic font が用意されているものについては、 BoldFont や ItalicFont などオプションを使ってそれらを指定できるようでござる。
試しに、以下のような内容のファイルを準備してみたでござる。
\documentclass{article} % Time-stamp: <2024/04/14 19:18:23 (UT+8) daisuke> \usepackage{luatexja-fontspec} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for default fonts % \setmainfont[ BoldFont=lmroman10-bold.otf, ItalicFont=lmroman10-italic.otf, BoldItalicFont=lmroman10-bolditalic.otf, SlantedFont=lmromanslant10-regular.otf, ]{lmroman10-regular.otf} \setsansfont[ BoldFont=lmsans10-bold.otf, ItalicFont=lmsans10-oblique.otf, BoldItalicFont=lmsans10-boldoblique.otf, ]{lmsans10-regular.otf} \setmonofont[ BoldFont=lmmonolt10-bold.otf, ItalicFont=lmmonolt10-oblique.otf, BoldItalicFont=lmmonolt10-boldoblique.otf, SlantedFont=lmmonoslant10-regular.otf, ]{lmmonolt10-regular.otf} \setmainjfont[ BoldFont=NotoSerifCJKjp-Bold.otf ]{NotoSerifCJKjp-Regular.otf} \setsansjfont[ BoldFont=NotoSansCJKjp-Bold.otf ]{NotoSansCJKjp-Medium.otf} \setmonojfont[ BoldFont=NotoSansMonoCJKjp-Bold.otf ]{NotoSansMonoCJKjp-Regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for Latin Modern fonts % \newfontfamily\lmr[ BoldFont=lmroman10-bold.otf, ItalicFont=lmroman10-italic.otf, BoldItalicFont=lmroman10-bolditalic.otf, SlantedFont=lmromanslant10-regular.otf, ]{lmroman10-regular.otf} \newfontfamily\lms[ BoldFont=lmsans10-bold.otf, ItalicFont=lmsans10-oblique.otf, BoldItalicFont=lmsans10-boldoblique.otf, ]{lmsans10-regular.otf} \newfontfamily\lmm[ BoldFont=lmmonolt10-bold.otf, ItalicFont=lmmonolt10-oblique.otf, BoldItalicFont=lmmonolt10-boldoblique.otf, SlantedFont=lmmonoslant10-regular.otf, ]{lmmonolt10-regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for New Computer Modern fonts % \newfontfamily\ncmr[ BoldFont=NewCM10-Bold.otf, ItalicFont=NewCM10-Italic.otf, BoldItalicFont=NewCM10-BoldItalic.otf, SmallCapsFeatures={Numbers=OldStyle}, ]{NewCM10-Regular.otf} \newfontfamily\ncms[ BoldFont=NewCMSans10-Bold.otf, ItalicFont=NewCMSans10-Oblique.otf, BoldItalicFont=NewCMSans10-BoldOblique.otf, SmallCapsFeatures={Numbers=OldStyle}, ]{NewCMSans10-Regular.otf} \newfontfamily\ncmm[ BoldFont=NewCMMono10-Bold.otf, ItalicFont=NewCMMono10-Italic.otf, BoldItalicFont=NewCMMono10-BookItalic.otf, SmallCapsFeatures={Numbers=OldStyle}, ]{NewCMMono10-Regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for Alegreya fonts % \newfontfamily\alegreya[ BoldFont=Alegreya-Bold.otf, ItalicFont=Alegreya-Italic.otf, BoldItalicFont=Alegreya-BoldItalic.otf, ]{Alegreya-Regular.otf} \newfontfamily\alegreyas[ BoldFont=AlegreyaSans-Bold.otf, ItalicFont=AlegreyaSans-Italic.otf, BoldItalicFont=AlegreyaSans-BoldItalic.otf, ]{AlegreyaSans-Regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for Gyre fonts % \newfontfamily\gyres[ BoldFont=texgyreschola-bold.otf, ItalicFont=texgyreschola-italic.otf, BoldItalicFont=texgyreschola-bolditalic.otf, ]{texgyreschola-regular.otf} \newfontfamily\gyreh[ BoldFont=texgyreheros-bold.otf, ItalicFont=texgyreheros-italic.otf, BoldItalicFont=texgyreheros-bolditalic.otf, ]{texgyreheros-regular.otf} \newfontfamily\gyret[ BoldFont=texgyrecursor-bold.otf, ItalicFont=texgyrecursor-italic.otf, BoldItalicFont=texgyrecursor-bolditalic.otf, ]{texgyrecursor-regular.otf} \newfontfamily\gyrec{texgyrechorus-mediumitalic.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for Japanese Noto fonts % \newjfontfamily\notojpm[ BoldFont=NotoSerifCJKjp-Bold.otf, ]{NotoSerifCJKjp-Regular.otf} \newjfontfamily\notojpg[ BoldFont=NotoSansCJKjp-Bold.otf, ]{NotoSansCJKjp-Medium.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for HaranoAji fonts % \newjfontfamily\haram[ BoldFont=HaranoAjiMincho-Bold.otf ]{HaranoAjiMincho-Regular.otf} \newjfontfamily\harag[ BoldFont=HaranoAjiGothic-Bold.otf ]{HaranoAjiGothic-Regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for IPAex fonts % \newjfontfamily\ipaexm{ipaexm.ttf} \newjfontfamily\ipaexg{ipaexg.ttf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for IPAex fonts % \newjfontfamily\bkai{bkai00mp.ttf} \newjfontfamily\bsmi{bsmi00lp.ttf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % settings for Traditional Chinese Noto fonts % \newjfontfamily\nototws[ BoldFont=NotoSerifCJKtc-Bold.otf, ]{NotoSerifCJKtc-Regular.otf} \newjfontfamily\nototwh[ BoldFont=NotoSansCJKtc-Bold.otf, ]{NotoSansCJKtc-Regular.otf} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\english}{ Wealth without work. \\ Pleasure without conscience. \\ Knowledge without character. \\ Commerce without morality. \\ Science without humanity. \\ Religion without sacrifice. \\ Politics without principle. \\ } \newcommand{\japanese}{ \noindent あいうえお \, かきくけこ \, さしすせそ \, たちつてと \, なにぬねの \\ はひふへほ \, まみむめも \, やゆよ \, らりるれろ \, わをん \\ アイウエオ \, カキクケコ \, サシスセソ \, タチツテト \, ナニヌネノ \\ ハヒフヘホ \, マミムメモ \, ヤユヨ \, ラリルレロ \, ワヲン \\ \noindent 色は匂へど \, 散りぬるを \\ 我が世誰ぞ \, 常ならむ \\ 有為の奥山 \, 今日越えて \\ 浅き夢見し \, 酔ひもせず \\ 春はあけぼの。やうやう白くなりゆく山ぎは、すこしあかりて、紫だちたる雲の ほそくたなびきたる。 \\ 夏は夜。月のころはさらなり。やみもなほ、蛍の多く飛びちがひたる。また、た だ一つ二つなど、ほのかにうち光りて行くもをかし。雨など降るもをかし。 \\ 行く川のながれは絶えずして、しかも本の水にあらず。よどみに浮ぶうたかたは、 かつ消えかつ結びて久しくとゞまることなし。 \\ 月日は百代の過客にして、行きかふ年もまた旅人なり。舟の上に生涯を浮かべ、 馬の口とらへて老いを迎ふる者は、日々旅にして、旅を栖とす。古人も多く旅に 死せるあり。 } \newcommand{\chinese}{ 青光閃動,一柄青鋼劍倏地刺出,指向中年漢子左肩,使劍少年不等劍招用老,腕抖劍 斜,劍鋒已削向那漢子右頸。那中年漢子豎劍擋格,錚的一聲響,雙劍相擊,嗡嗡作聲,震 聲未絕,雙劍劍光霍霍,已拆了三招。中年漢子長劍猛地擊落,直砍少年頂門。那少 年避向右側,左手劍訣一引,青鋼劍疾刺那漢子大腿。 } \title{\bf Making a PDF file using Lua\TeX} \author{Kinoshita Daisuke} \date{14 April 2024} \begin{document} \maketitle \begin{abstract} This is a test for making a PDF file using Lua\TeX. The command ``{\tt lualatex}'' can be used to generate a PDF file directly from a \LaTeX \, source file. TrueType and OpenType fonts can be used for Lua\TeX easily by using ``{\tt fontspec}'' package. \end{abstract} \section{English} \subsection{Latin Modern fonts} \subsubsection{Latin Modern Roman Regular} \english \subsubsection{Latin Modern Roman Bold} {\bf \english } \subsubsection{Latin Modern Roman Italic} {\it \english } \subsubsection{Latin Modern Roman Slanted} {\sl \english } \subsubsection{Latin Modern Roman Small Capital} {\sc \english } \subsubsection{Latin Modern Sans Regular} {\lms \english } \subsubsection{Latin Modern Sans Bold} {\bf \lms \english } \subsubsection{Latin Modern Sans Italic} {\it \lms \english } \subsubsection{Latin Modern Mono} {\tt \english } \subsection{New Computer Modern fonts} \subsubsection{New Computer Modern Roman Regular} {\ncmr \english } \subsubsection{New Computer Modern Roman Bold} {\bf \ncmr \english } \subsubsection{New Computer Modern Roman Italic} {\it \ncmr \english } \subsubsection{New Computer Modern Sans Regular} {\ncms \english } \subsubsection{New Computer Modern Sans Bold} {\bf \ncms \english } \subsubsection{New Computer Modern Sans Italic} {\it \ncms \english } \subsubsection{New Computer Modern Mono Regular} {\ncmm \english } \subsubsection{New Computer Modern Mono Bold} {\bf \ncmm \english } \subsubsection{New Computer Modern Mono Italic} {\it \ncmm \english } \subsection{Alegreya fonts} \subsubsection{Alegreya Regular} {\alegreya \english } \subsubsection{Alegreya Bold} {\bf \alegreya \english } \subsubsection{Alegreya Italic} {\it \alegreya \english } \subsubsection{Alegreya Sans Regular} {\alegreyas \english } \subsubsection{Alegreya Sans Bold} {\bf \alegreyas \english } \subsubsection{Alegreya Sans Italic} {\it \alegreyas \english } \subsection{Gyre fonts} \subsubsection{Gyre Schola} {\gyres \english } \subsubsection{Gyre Heros} {\gyreh \english } \subsubsection{Gyre Cursor} {\gyret \english } \subsubsection{Gyre Chorus} {\gyrec \english } \section{Japanese} \subsection{HaranoAji fonts} \subsubsection{HaranoAji Serif} \japanese \subsubsection{HaranoAji Sans} {\bf \japanese } \subsection{Google Noto fonts} \subsubsection{Google Noto Serif} {\notojpm \japanese } \subsubsection{Google Noto Sans} {\notojpg \japanese } \subsection{IPAex fonts} \subsubsection{IPAex Serif} {\ipaexm \japanese } \subsubsection{IPAex Sans} {\ipaexg \japanese } \newpage \section{Traditional Chinese} \subsection{Arphic fonts} \subsubsection{bsmi} {\bsmi \chinese } \subsubsection{bkai} {\bkai \chinese } \subsection{Google Noto fonts} \subsubsection{Google Noto Serif} {\nototws \chinese } \subsubsection{Google Noto Sans} {\nototwh \chinese } \newpage \section{Comparison of Chinese characters of Chinese and Japanese fonts} \Large \begin{center} \begin{tabular}{|c|c|} \hline Traditional Chinese & Japanese \\ \hline \hline {\nototws 述} & {\haram 述} \\ {\nototws 氣} & {\haram 気} \\ {\nototws 黃} & {\haram 黄} \\ {\nototws 內} & {\haram 内} \\ {\nototws 德} & {\haram 徳} \\ {\nototws 對} & {\haram 対} \\ {\nototws 歷} & {\haram 歴} \\ {\nototws 溫} & {\haram 温} \\ {\nototws 佛} & {\haram 仏} \\ {\nototws 禮} & {\haram 礼} \\ {\nototws 國} & {\haram 国} \\ {\nototws 圓} & {\haram 円} \\ {\nototws 歐} & {\haram 欧} \\ {\nototws 處} & {\haram 処} \\ {\nototws 聽} & {\haram 聴} \\ {\nototws 單} & {\haram 単} \\ {\nototws 免} & {\haram 免} \\ {\nototws 帶} & {\haram 帯} \\ {\nototws 變} & {\haram 変} \\ {\nototws 壓} & {\haram 圧} \\ {\nototws 骨} & {\haram 骨} \\ {\nototws 起} & {\haram 起} \\ {\nototws 參} & {\haram 参} \\ \hline \end{tabular} \end{center} \end{document}
準備した LaTeX ソースファイルを lualatex コマンドを使って処理するでご ざる。
% lualatex test_luatex_cjk_0.tex This is LuaTeX, Version 1.18.0 (Web2C 2024) restricted system commands enabled. (./test_luatex_cjk_0.tex LaTeX2e <2023-11-01> patch level 1 L3 programming layer <2024-03-14> (/usr/pkg/share/texmf-dist/tex/latex/base/article.cls Document Class: article 2023/05/17 v1.4n Standard LaTeX document class (/usr/pkg/share/texmf-dist/tex/latex/base/size10.clo)) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty (/usr/pkg/share/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty (/usr/pkg/share/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/pkg/share/texmf-dist/tex/latex/l3backend/l3backend-luatex.def))) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/luatexja.sty (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/luatexja-core.sty (/usr/pkg/share/texmf-dist/tex/generic/infwarerr/infwarerr.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexbase/luatexbase.sty (/usr/pkg/share/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)) (/usr/pkg/share/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty) (/usr/pkg/share/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty (/usr/pkg/share/texmf-dist/tex/generic/iftex/iftex.sty)) (/usr/pkg/share/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/pkg/share/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/pkg/share/texmf-dist/tex/generic/xkeyval/xkvutils.tex (/usr/pkg/share/texmf-dist/tex/generic/xkeyval/keyval.tex)))) (/usr/pkg/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/ltj-base.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/ltj-latex.sty (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjfont.sty (/usr/pkg/share/texmf-dist/tex/latex/base/tuenc.def)) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjdefs.sty (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/jfm-ujisv.lua) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/jfm-ujis.lua)) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjcore.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjp-atbegshi.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjp-geometry.sty (/usr/pkg/share/texmf-dist/tex/generic/iftex/ifluatex.sty)))) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/luatexja-compat.sty)) (/usr/pkg/share/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/pkg/share/texmf-dist/tex/latex/l3packages/xparse/xparse.sty) (/usr/pkg/share/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty (/usr/pkg/share/texmf-dist/tex/latex/base/fontenc.sty) (/usr/pkg/share/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/patches/lltjp-fontspec.sty) (/usr/pkg/share/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec-27c.sty )) (/usr/pkg/share/texmf-dist/tex/latex/newcomputermodern/NewCM10-Regular.fontspec ) (/usr/pkg/share/texmf-dist/tex/latex/newcomputermodern/NewCMSans10-Regular.font spec) (/usr/pkg/share/texmf-dist/tex/latex/newcomputermodern/NewCMMono10-Regular.font spec) (./test_luatex_cjk_0.aux) (/usr/pkg/share/texmf-dist/tex/latex/base/ts1cmr.fd) [1{/var/lib/texmf/fonts/ma p/pdftex/updmap/pdftex.map}] LaTeX Font Warning: Font shape `TU/lmroman10-regular.otf(0)/m/sc' undefined (Font) using `TU/lmroman10-regular.otf(0)/m/n' instead on input li ne 294. [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] (./test_luatex_cjk_0.aux) LaTeX Font Warning: Some font shapes were not available, defaults substituted. ) 797 words of node memory still in use: 7 hlist, 1 vlist, 4 rule, 2 glue, 3 kern, 1 glyph, 129 attribute, 50 glue_sp ec, 20 attribute_list, 1 write, 9 user_defined nodes avail lists: 1:19,2:33387,3:304,4:176,5:299,6:29,7:3449,8:1,9:1599,10:9,11:1 85 < /usr/pkg/share/texmf-dist/fonts/opentype/huerta/alegreya/Alegreya-Bold.otf> Output written on test_luatex_cjk_0.pdf (15 pages, 874337 bytes). Transcript written on test_luatex_cjk_0.log. % ls -lF test_luatex_cjk_0.* -rw-r--r-- 1 daisuke taiwan 6441 Apr 14 20:43 test_luatex_cjk_0.aux -rw-r--r-- 1 daisuke taiwan 79904 Apr 14 20:43 test_luatex_cjk_0.log -rw-r--r-- 1 daisuke taiwan 874337 Apr 14 20:43 test_luatex_cjk_0.pdf -rw-r--r-- 1 daisuke taiwan 11635 Apr 14 20:38 test_luatex_cjk_0.tex -rw-r--r-- 1 daisuke taiwan 2045 Apr 14 09:47 test_luatex_cjk_0.tex~
出来上がった PDF ファイルは以下のようになっているでござる。
|
---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Google Noto フォントに中国語フォントも含まれているでござる。しかしなが ら、 Google Noto フォントに含まれている中国語フォントは、明朝体のよう なものとゴシック体のようなものだけで、楷書体 (或いは、教科書体) のよう な書体のフォントは見当たらないでござる。中国語繁体字の楷書体については、 arphic font の bkai を使ってみたでござる。 arphic のもの以外に、無料で 自由に使える中国語繁体字の楷書体のフォントがあるかどうか探してみようと 思うでござる。