From 2ce6be275d6b405c4e116a24f2ac0053962f96a8 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Wed, 22 Aug 2012 08:39:49 +0900 Subject: [PATCH] Fix ticket 29311. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - 29311-test.tex にあった対処方法のテストを取り込み. - listings 用の禁則テーブルは(今のところ)カスタマイズを想定していない. 現在は luatexja-kinsoku.tex の中から {pre,post}breakpenalty が 10000 の文字について設定している. - ドキュメントの更新は未完である. --- doc/luatexja.dtx | 135 ++++++++++++++++++++----------------- src/ltj-jfmglue.lua | 2 +- src/patches/lltjp-listings-jpt.tex | 75 +++++++++++++++++++++ src/patches/lltjp-listings.sty | 66 ++++++++++++++---- 4 files changed, 202 insertions(+), 76 deletions(-) diff --git a/doc/luatexja.dtx b/doc/luatexja.dtx index 76bb7d2..43f06a0 100644 --- a/doc/luatexja.dtx +++ b/doc/luatexja.dtx @@ -2684,59 +2684,6 @@ xyz漢字 \end{LTXexample} -%\subsection{Cropmark} -%\subsection{トンボ} -%\subsection{裁剪框标记} - -%<*en> -Cropmark is a mark for indicating 4~corners and horizontal/vertical -center of the paper. In Japanese, we call cropmark as tombo(w). -\pLaTeX\ and this \LuaTeX-ja support `tombow' by their kernel. -The following steps are needed to typeset cropmark: -% -%<*ja> -トンボは用紙の四つ角と水平/垂直方向の中心を表す印である. -\pLaTeX と \LuaTeX-jaではトンボの出力をサポートしている. -トンボを出力するためには以下の手順が必要である: -% -%<*zh> -裁剪框标记是在一页的四角和水平/垂直中央放置的标记。在日文中,裁剪框被称为“トンボ”。 -\pLaTeX 和\LuaTeX-ja均在底层支持裁剪框标记。需要下列步骤来实现: -% - -\begin{enumerate} -%<*en> -\item First, define the banner which will be printed at the upper left - of the paper. This is done by assigning a token list to - \verb+\@bannertoken+. - -For example, the following sets banner as `\texttt{filename (YYYY-MM-DD hh:mm)}': -% -%<*ja> -\item まず,用紙の左上に印刷されるバナーを定義する.これは \verb+\@bannertoken+ - にトークンリストを与えることでなされる. - -例えば,以下はバナーとして`\texttt{filename (YYYY-MM-DD hh:mm)}'を設定する: -% -%<*zh> -\item 首先,首先定义页面左上角将会出现的注记。这由向\verb!@bannertoken!分配一个token列完成。\\ -例如,下列所示将会设定注记为“\textsf{filename (YYYY-MM-DD hh:mm)}”: -% - -\begin{verbatim} -\makeatletter - -\hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax -\minute\time \advance\minute-\@tempcnta -\@bannertoken{% - \jobname\space(\number\year-\two@digits\month-\two@digits\day - \space\two@digits\hour:\two@digits\minute)}% -\end{verbatim} - -\item ... -\end{enumerate} - - %\part{Reference} %\part{リファレンス} %\part{参考指南} @@ -4266,8 +4213,9 @@ With the help of this example, we remark the specification of \verb+\inhibitglue %<*ja> \item \verb+\inhibitglue+ の(制限された)水平モード中での呼び出しはその場でのみ 有効であり,段落の境界を乗り越えない. - さらに,\verb+\inhibitglue+ は上の例の最終行のようにリガチャとカーニングを - 打ち消す. + さらに,\verb+\inhibitglue+ は上の例の最終行のように(欧文における)リガチャとカーニングを + 打ち消す.これは,\verb+\inhibitglue+ が内部的には「現在のリスト中にwhatsitノードを + 追加する」ことを行なっているからである. % %<*en> @@ -4471,19 +4419,15 @@ As closing this subsection, we shall introduce an example of % %<*ja> この節の終わりに,\verb+\SetRelationFont+ と \verb+\userelfont+ の例を -紹介しておこう. +紹介しておこう.\verb+\userelfont+ の使用によって,「abc」の部分のフォントが +Avant Garde (OT1/pag/m/n) に変わっていることがわかる. % \begin{LTXexample} -\gtfamily{}あいうabc +\kanjifamily{gt}\selectfont あいうxyz \SetRelationFont{JY3}{gt}{m}{n}{OT1}{pag}{m}{n} -\userelfont\selectfont{}あいうabc +\userelfont\selectfont あいうabc \end{LTXexample} - -%\subsection{Cropmark/`tombow'} -%\subsection{トンボ} -% ToDo - %\section{Extensions} %\section{拡張} \subsection{\texttt{luatexja-fontspec.sty}} @@ -5960,6 +5904,71 @@ $\mathit{Nq}.\mathit{tail}$は無意味なので, \section{psft} + +%<*ja> +\subsection{\Pkg{listings} パッケージへの対応} +\Pkg{listings} パッケージが,そのままでは日本語をまともに出力できないこと +はよく知られている,きちんと整形して出力するために,\Pkg{listings}パッケー +ジは内部で「ほとんどの文字」をアクティブにし,各文字に対してその文字の出 +力命令を割り当てている (\cite{listings}). +しかし,そこでアクティブにする文字の中に,和文文 +字がないためである.p\TeX 系列では,和文文字をアクティブにする手法がなく, +\Pkg{jlisting.sty} というパッチ\cite{jlisting}を用いることで無理やり解決していたが, +\LuaTeX-jaでは,(\LuaTeX がネイティブでUnicodeを理解することから)「和文 +文字をアクティブ化し,それらに対して適切に出力命令を設定する」というより正統的な +方法を取ることにした. + +\LuaTeX-ja で利用される \Pkg{listings} パッケージへのパッチ \Pkg{lltjp-listings.sty} は, +\Pkg{listings.sty} と\LuaTeX-jaを読み込んでおけば, +\verb+\begin{document}+ の箇所において自動的に読み込まれるので,通常はあまり +意識する必要はない. + +\paragraph{文字種} +\Pkg{listings} パッケージの内部では,大雑把に言うと +\begin{enumerate} +\item 識別子として使える文字 (``letter'',~``digit'') たちを +集める. +\item letterでもdigitでもない文字が現れた時に,収集した文字列を(必要なら修飾して)出力する. +\item 今度は逆に,letterでない文字たちをletterが現れるまで集める. +\item letterが出現したら集めた文字列を出力する. +\item 1.に戻る. +\end{enumerate} +という処理が行われている.これにより,識別子の途中では行分割が行われないようになっている. +直前の文字が識別子として使えるか否かは \verb+\lst@ifletter+ というフラグに格納されている. + +さて,日本語の処理である.殆どの和文文字の前後では行分割が可能であるが,その一方で +括弧類や音引きなどでは禁則処理が必要なことから,\Pkg{lltjp-listings.sty} では, +直前が和文文字であるかを示すフラグ \verb+lst@kanji+ を新たに導入した. +以降,説明のために以下のように文字を分類する: +\begin{center} +\small +\begin{tabular}{lcccc} +\toprule +&Letter&Other&Kanji&Nobreak\\\midrule +\verb+\lst@ifletter+&T&F&T&F\\ +\verb+\lst@ifkanji+&F&F&T&T\\ +意図&識別子中の文字&その他欧文文字&殆どの和文文字&和文開き括弧類\\ +\bottomrule +\end{tabular} +\end{center} +なお,本来の\Pkg{listings} パッケージでの分類``digit''は, +出現状況によって,上の表のLetterとOtherのどちらにもなりうる. + + +%% ↓ここで行分割が許容されるか否か +%% L--L: 保留 L--O: 出力 L--K: 出力 L--P: 出力 +%% O--L: 出力 O--O: 保留 O--K: 出力 O--P: 出力 +%% K--L: 出力 K--O: 出力 K--K: 出力 K--P: 出力 +%% P--L: 保留 p--O: 保留 P--K: 保留 P--P: 保留 +%% 閉じ括弧類については,直前での出力はせず,Other 扱いとする. + + + + + +% + + \begin{thebibliography}{99} \addcontentsline{toc}{section}{\refname} \bibitem{texbytopic} diff --git a/src/ltj-jfmglue.lua b/src/ltj-jfmglue.lua index a07e89f..b414f19 100644 --- a/src/ltj-jfmglue.lua +++ b/src/ltj-jfmglue.lua @@ -415,7 +415,7 @@ do local attr_jchar_class = luatexbase.attributes['ltj@charclass'] function set_np_xspc_jachar(Nx, x) local m = ltjf_font_metric_table[x.font] - local c = has_attr(x, attr_orig_char) + local c = has_attr(x, attr_orig_char) or x.char local cls = ltjf_find_char_class(x.char, m) if c ~= x.char and cls==0 then cls = ltjf_find_char_class(-c, m) end Nx.class = cls; set_attr(x, attr_jchar_class, cls) diff --git a/src/patches/lltjp-listings-jpt.tex b/src/patches/lltjp-listings-jpt.tex index e5b4827..505ea38 100644 --- a/src/patches/lltjp-listings-jpt.tex +++ b/src/patches/lltjp-listings-jpt.tex @@ -963,4 +963,79 @@ \ltj@@listing@jpsetN{65280}{65376}{\lst@ProcessJALetter} \ltj@@listing@jpsetN{65377}{65439}{\lst@ProcessJALetterHalf} \ltj@@listing@jpsetN{65504}{65509}{\lst@ProcessJALetter} + +\message{Opening and Closing brackets} +\@temptokena{}% DO NOT REMOVE THIS LINE + +\ltj@@listing@jpsetN@{`,}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`。}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`,}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`.}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`・}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`:}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`;}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`?}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`!}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`゛}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"212B +\ltj@@listing@jpsetN@{`゜}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"212C +\ltj@@listing@jpsetN@{`´}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"212D +\ltj@@listing@jpsetN@{``}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"212E +\ltj@@listing@jpsetN@{`々}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2139 +\ltj@@listing@jpsetN@{`…}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2144 +\ltj@@listing@jpsetN@{`‥}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2145 +\ltj@@listing@jpsetN@{`‘}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2146 +\ltj@@listing@jpsetN@{`’}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2147 +\ltj@@listing@jpsetN@{`“}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2148 +\ltj@@listing@jpsetN@{`”}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2149 +\ltj@@listing@jpsetN@{`)}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`(}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`}}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`{}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`]}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`[}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`〔}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"214C +\ltj@@listing@jpsetN@{`〕}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"214D +\ltj@@listing@jpsetN@{`〈}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2152 +\ltj@@listing@jpsetN@{`〉}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2153 +\ltj@@listing@jpsetN@{`《}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2154 +\ltj@@listing@jpsetN@{`》}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2155 +\ltj@@listing@jpsetN@{`「}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2156 +\ltj@@listing@jpsetN@{`」}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2157 +\ltj@@listing@jpsetN@{`『}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"2158 +\ltj@@listing@jpsetN@{`』}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"2159 +\ltj@@listing@jpsetN@{`【}{\lst@ProcessJALetter@inhibit@postbreak}%\jis"215A +\ltj@@listing@jpsetN@{`】}{\lst@ProcessJALetter@inhibit@prebreak}%\jis"215B +\ltj@@listing@jpsetN@{`ー}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〳}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〴}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〵}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〻}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`⦅}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`⦆}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`⦅}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`⦆}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〘}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`〙}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〖}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`〗}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`«}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`»}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`〝}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`〟}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`‼}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`⁇}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`⁈}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`⁉}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`¡}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`¿}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`ː}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`ª}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`º}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`¹}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`²}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`³}{\lst@ProcessJALetter@inhibit@prebreak} +\ltj@@listing@jpsetN@{`€}{\lst@ProcessJALetter@inhibit@postbreak} +\ltj@@listing@jpsetN@{`™}{\lst@ProcessJALetter@inhibit@prebreak} + +\ltj@@listing@jpset@after{other}% DO NOT REMOVE THIS LINE \message{done.} diff --git a/src/patches/lltjp-listings.sty b/src/patches/lltjp-listings.sty index 5059ef9..a65ee47 100644 --- a/src/patches/lltjp-listings.sty +++ b/src/patches/lltjp-listings.sty @@ -17,33 +17,75 @@ \setcatcoderange{"20000}{"2FFFF}{13}} % lowest level +\def\lst@kanjitrue{\let\lst@ifkanji\iftrue} +\def\lst@kanjifalse{\let\lst@ifkanji\iffalse} +\lst@AddToHook{InitVars}{\lst@kanjifalse} + +\def\lst@AppendOther{% + \lst@ifletter\lst@Output\lst@letterfalse\fi\lst@kanjifalse + \futurelet\lst@lastother\lst@Append} +\def\lst@AppendLetter{% + \lst@ifletter + \lst@ifkanji\lst@Output\lst@kanjifalse + \fi + \else + \lst@lettertrue\lst@ifkanji\lst@kanjifalse\else\lst@OutputOther\fi + \fi + \lst@Append} + \def\lst@ProcessJALetter{\lst@whitespacefalse \lst@AppendJALetter} +\def\lst@ProcessJALetterHalf{\lst@whitespacefalse \lst@AppendJALetterHalf} +\def\lst@ProcessJALetter@inhibit@prebreak{% + \lst@whitespacefalse \lst@AppendJALetter@inhibit@prebreak} +\def\lst@ProcessJALetter@inhibit@postbreak{% + \lst@whitespacefalse \lst@AppendJALetter@inhibit@postbreak} + \def\lst@AppendJALetter{% - \lst@ifletter \lst@Output\else\lst@OutputOther\fi\lst@lettertrue + \lst@ifletter + \lst@Output + \else + \lst@ifkanji\else\lst@OutputOther\fi\lst@lettertrue + \fi\lst@kanjitrue \advance\lst@length\@ne\lst@Append} -\def\lst@ProcessJALetterHalf{\lst@whitespacefalse \lst@AppendJALetterHalf} \def\lst@AppendJALetterHalf{% - \lst@ifletter \lst@Output\else\lst@OutputOther\fi\lst@lettertrue + \lst@ifletter + \lst@Output + \else + \lst@ifkanji\else\lst@OutputOther\fi\lst@lettertrue + \fi\lst@kanjitrue \lst@Append} +\def\lst@AppendJALetter@inhibit@prebreak{% + \lst@ifletter\else\lst@lettertrue\fi\lst@kanjitrue + \advance\lst@length\@ne\lst@Append} +\def\lst@AppendJALetter@inhibit@postbreak{% + \lst@ifletter + \lst@Output + \else + \lst@ifkanji\else\lst@OutputOther\fi + \fi\lst@letterfalse\lst@kanjitrue + \advance\lst@length\@ne\lst@Append} + % loading lltjp-listing-jpt.tex \def\ltj@@listing@jpset#1#2{% fast: #2-#1+1 must be a multiple of 16 \@tempcnta=#1 \@tempcntb=#2 \@temptokena{}% \loop\relax\ifnum\@tempcnta<\@tempcntb\relax \ltj@@listing@jpset@\global\advance\@tempcnta\sixt@@n\repeat - \expandafter\edef\csname ltj@@listing@jpcmd@i#1\endcsname{\the\@temptokena}% - \toks@\expandafter\expandafter\expandafter\expandafter% - \expandafter\expandafter\expandafter{\expandafter\expandafter% - \expandafter\the\expandafter\toks@\csname ltj@@listing@jpcmd@i#1\endcsname}% + \ltj@@listing@jpset@after{#1} } -\def\ltj@@listing@jpsetN#1#2#3{% +\def\ltj@@listing@jpsetN#1#2#3{% for (not large) range \@tempcnta=#1 \@tempcntb=#2 \@temptokena{}% \loop \global\advance\@tempcnta\@ne\ifnum\@tempcnta<\@tempcntb\relax - \ltj@@listing@jpsetN@#3\repeat + \ltj@@listing@jpsetN@{\@tempcnta}{#3}\repeat + \ltj@@listing@jpset@after{#1} +} + +\def\ltj@@listing@jpset@after#1{% \expandafter\edef\csname ltj@@listing@jpcmd@i#1\endcsname{\the\@temptokena}% \toks@\expandafter\expandafter\expandafter\expandafter% \expandafter\expandafter\expandafter{\expandafter\expandafter% \expandafter\the\expandafter\toks@\csname ltj@@listing@jpcmd@i#1\endcsname}% + \@temptokena{}% } \begingroup @@ -87,9 +129,9 @@ \expandafter\expandafter\expandafter{\expandafter\expandafter% \expandafter\the\expandafter\@temptokena\@temp}% } -\gdef\ltj@@listing@jpsetN@#1{{% - \lccode`\~=\@tempcnta \lccode`\/=\@tempcnta - \lowercase{\gdef\@temp{\gdef~{#1/}}}}% +\gdef\ltj@@listing@jpsetN@#1#2{{% + \@tempcnta=#1 \lccode`\~=\@tempcnta \lccode`\/=\@tempcnta + \lowercase{\gdef\@temp{\gdef~{#2/}}}}% \@temptokena\expandafter\expandafter\expandafter\expandafter% \expandafter\expandafter\expandafter{\expandafter\expandafter% \expandafter\the\expandafter\@temptokena\@temp}% -- 2.11.0