Skip to content

Commit b11564f

Browse files
committed
add iffieldisCJK.
1 parent 3ea537d commit b11564f

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

doc/biblatex-japanese.pdf

920 Bytes
Binary file not shown.

doc/biblatex-japanese.tex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ \subsection{和文文字判定}
161161
フィールド毎に和文文字を含むかどうかで動作を変更できると便利である.
162162
このためのテストコマンドを準備しておく.
163163

164+
なお,Unicodeであることを前提にしているので,p\TeX の場合は
165+
怪しい動作になる.どうなるのかをちゃんと理解したら対策するかもしれない.
166+
164167
\begin{ltxsyntax}
165168
\cmditem{ifCJKstr}{tokens}{true code}{false code}
166169

@@ -169,9 +172,6 @@ \subsection{和文文字判定}
169172
そうでなければ\prm{false code}を実行する.
170173
テストは一度\prm{tokens}を完全展開してから行われる.
171174

172-
なお,Unicodeであることを前提にしているので,p\TeX の場合は
173-
怪しい動作になる.どうなるのかをちゃんと理解したら対策するかもしれない.
174-
175175
\cmditem{ifbeginwithCJKchar}{tokens}{true code}{false code}
176176

177177
\prm{tokens}の先頭にU+2E80以上のコードポイントの文字があれば
@@ -205,13 +205,19 @@ \subsection{置換コマンド}
205205
\cmditem{replacenameformat}[entrytype, \dots]{format}{replace rule name}{code}
206206

207207
それぞれ\cmd{replacecommand}のbibmacro, field format, name list formatに対応するもの.
208+
209+
\cmd{replacefieldformat}, \cmd{replacenameformat}では,replace ruleの定義中にある
210+
\cmd{blxja@format}が冒頭で\prm{format}と定義される.
211+
このことを利用すると,\prm{format}毎にreplace ruleを用意する手間を省ける.
208212
\end{ltxsyntax}
209213

210-
\prm{replace rule name}には以下のいずれかを指定する(現状では1つしかないが,
211-
今後増やす予定).
214+
\prm{replace rule name}には以下のいずれかを指定する.
212215
\begin{typelist}
213216
\typeitem{iflangidisjapanese}
214217
文献出力処理中に,もしその文献の\bibfield{langid}が\texttt{japanese}ならば真になる.
218+
219+
\typeitem{iffieldisCJK}
220+
\cmd{replacefieldformat}で用いると,対象のfieldが和文文字を含む時に真になる.
215221
\end{typelist}
216222

217223
\begin{ltxsyntax}

latex/biblatex-japanese.def

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@
8686
\begingroup
8787
\@makeother\#%
8888
\blxja@replace@command@rc@args}
89+
% {<command>}{<rule name>}{<code>}
8990
\long\def\blxja@replace@command@rn@args#1#2#3{%
9091
\ifcsundef{blxja@replacerule@\detokenize{#2}}{%
9192
\blxja@error{Replace rule '\detokenize{#2}' undefined}{}}{%
9293
\expandafter\etb@hooktocmd\csname blxja@replacerule@\detokenize{#2}\endcsname#1{#3}{}{%
9394
\blxja@error{\replacecommand for the command \string#1 failed}
9495
{Try \detokenize{\tracingpatches} to investigate the cause of the problem.\MessageBreak}}}}
96+
% {<command>}{<rule code>}{<code>}
9597
\long\def\blxja@replace@command@rc@args#1#2#3{%
9698
\endgroup
9799
\edef\blxja@reserveda{%
@@ -115,6 +117,7 @@
115117
\begingroup
116118
\@makeother\#%
117119
\blxja@replace@abx@macro@rc@args}
120+
% {<bibmacro>}{<rule name>}{<code>}
118121
\long\def\blxja@replace@abx@macro@rn@args#1#2#3{%
119122
\endgroup
120123
\ifcsundef{blxja@replacerule@\detokenize{#2}}{%
@@ -125,6 +128,7 @@
125128
\expandafter\expandafter\expandafter\etb@hooktocmd\expandafter\blxja@tempa\blxja@tempb{#3}{}{%
126129
\blxja@error{\replacebibmacro for the bibliography macro '\detokenize{#1}' failed}
127130
{Try \detokenize{\tracingpatches} to investigate the cause of the problem.\MessageBreak}}}}
131+
% {<bibmacro>}{<rule code>}{<code>}
128132
\long\def\blxja@replace@abx@macro@rc@args#1#2#3{%
129133
\endgroup
130134
\edef\blxja@reserveda{%
@@ -134,8 +138,8 @@
134138
\begingroup % dummy for \endgroup in \etb@hooktocmd
135139
\blxja@replace@abx@macro@rn@args{#1}{@temprule@}{#3}}
136140

137-
% {<id>}{<type>}{<macro>}
138-
\def\blxja@def@replacemacro#1#2#3{%
141+
% {<id>}{<type>}{<command>}
142+
\def\blxja@def@replacecommand#1#2#3{%
139143
\DeclareDocumentCommand{#3}{ s }{%
140144
\IfBooleanTF{##1}
141145
{\csuse{blxja@replace@abx@\detokenize{#1}@rulecode}}
@@ -145,14 +149,15 @@
145149
\begingroup
146150
\@makeother\#%
147151
\csuse{blxja@replace@abx@\detokenize{#1}@args@}
148-
{\csuse{blxja@replace@abx@\detokenize{#1}@rn@args}}}
152+
{\csuse{blxja@replace@abx@\detokenize{#1}@rn@args}}}
149153
\csdef{blxja@replace@abx@\detokenize{#1}@rulecode}{%
150154
\etb@dbg@trce{#3*}%
151155
\begingroup
152156
\@makeother\#%
153157
\csuse{blxja@replace@abx@\detokenize{#1}@args@}
154158
{\csuse{blxja@replace@abx@\detokenize{#1}@rc@args}}}
155-
159+
% execute <cs> for all <entry type, ...>
160+
% {<cs>}[<entry type, ...>]{<format>}{<replace rule name/code>}{<code>}
156161
\expandafter\DeclareDocumentCommand\expandafter
157162
{\csname blxja@replace@abx@\detokenize{#1}@args@\endcsname}
158163
{ m O{*} m m +m }{%
@@ -161,7 +166,7 @@
161166
\def\@tempc{##1}%
162167
\@for\@tempb:=\@tempa\do{%
163168
\expandafter\@tempc\expandafter{\@tempb}{##3}{##4}{##5}}}
164-
169+
% [<entry type, ...>]{<format>}{<replace rule name>}{<code>}
165170
\expandafter\DeclareDocumentCommand\expandafter
166171
{\csname blxja@replace@abx@\detokenize{#1}@rn@args\endcsname}
167172
{ m m m +m }{%
@@ -170,9 +175,12 @@
170175
\edef\blxja@tempa{\expandonce{\csname blxja@replacerule@\detokenize{##3}\endcsname}}%
171176
\edef\blxja@tempb{\expandonce{\csname abx@#1@\detokenize{##1}@\detokenize{##2}\endcsname}}%
172177
\begingroup % dummy for \endgroup in \etb@hooktocmd
173-
\expandafter\expandafter\expandafter\etb@hooktocmd\expandafter\blxja@tempa\blxja@tempb{##4}{}{%
178+
\expandafter\expandafter\expandafter\etb@hooktocmd\expandafter\blxja@tempa\blxja@tempb{##4}{%
179+
\expandafter\pretocmd\expandafter{\blxja@tempb}{\def\blxja@format{##2}}{}{}%
180+
}{%
174181
\blxja@error{#3 for the #2 '\detokenize{##2}' failed}
175182
{Try \detokenize{\tracingpatches} to investigate the cause of the problem.\MessageBreak}}}}
183+
% [<entry type, ...>]{<format>}{<replace rule code>}{<code>}
176184
\expandafter\DeclareDocumentCommand\expandafter
177185
{\csname blxja@replace@abx@\detokenize{#1}@rc@args\endcsname}
178186
{ m m m +m }{%
@@ -183,8 +191,8 @@
183191
\begingroup % dummy for \endgroup in \etb@hooktocmd
184192
\csuse{blxja@replace@abx@\detokenize{#1}@rn@args}[##1]{##2}{@temprule@}{##4}}}
185193

186-
\blxja@def@replacemacro{ffd}{field format}{\replacefieldformat}
187-
\blxja@def@replacemacro{nfd}{name list format}{\replacenameformat}
194+
\blxja@def@replacecommand{ffd}{field format}{\replacefieldformat}
195+
\blxja@def@replacecommand{nfd}{name list format}{\replacenameformat}
188196

189197
\DeclareDocumentCommand{\newreplacerule}{ m }{%
190198
\ifcsdef{blxja@replacerule@\detokenize{#1}}{%
@@ -208,6 +216,9 @@
208216
{#2}
209217
{#1}}
210218

219+
\newreplacerule{iffieldisCJK}{%
220+
\ifCJKstr{\thefield{\blxja@format}}{#2}{#1}}
221+
211222
\def\blxja@hook@print@getname#1#2#3#4{%
212223
\ifcsundef{blxja@hook@print@#2@\blx@imc@thefield{entrytype}@#3}
213224
{\ifcsundef{blxja@hook@print@#2@*@#3}

latex/lbx/japanese.lbx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,34 @@
9696
{\global\togglefalse{blx@insert}}
9797
{}}
9898
\savefieldformat{booktitle}%
99-
\replacefieldformat{booktitle}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
99+
\replacefieldformat{booktitle}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
100100
\printfieldhook{booktitle}{\blxja@removeunitpunct}
101101
\savefieldformat{citetitle}%
102-
\replacefieldformat{citetitle}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
102+
\replacefieldformat{citetitle}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
103103
\savefieldformats
104104
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
105105
{citetitle}%
106106
\replacefieldformat
107107
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
108-
{citetitle}{iflangidisjapanese}{\mkbibcbrackets{#1}}%
108+
{citetitle}{iffieldisCJK}{\mkbibcbrackets{#1}}%
109109
\printfieldhook{citetitle}{\blxja@removeunitpunct}%
110110
\savefieldformat{issuetitle}%
111-
\replacefieldformat{issuetitle}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
111+
\replacefieldformat{issuetitle}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
112112
\savefieldformat{journaltitle}%
113-
\replacefieldformat{journaltitle}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
113+
\replacefieldformat{journaltitle}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
114114
\printfieldhook{journaltitle}{\blxja@removeunitpunct}%
115115
\savefieldformat{maintitle}%
116-
\replacefieldformat{maintitle}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
116+
\replacefieldformat{maintitle}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
117117
\savefieldformat{pages}%
118-
\replacefieldformat{pages}{iflangidisjapanese}{#1\bibstring{japanese-pages}}%
118+
\replacefieldformat{pages}{iffieldisCJK}{#1\bibstring{japanese-pages}}%
119119
\savefieldformat{title}%
120-
\replacefieldformat{title}{iflangidisjapanese}{\mkbibwcbrackets{#1}}%
120+
\replacefieldformat{title}{iffieldisCJK}{\mkbibwcbrackets{#1}}%
121121
\savefieldformats
122122
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
123123
{title}%
124124
\replacefieldformat
125125
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
126-
{title}{iflangidisjapanese}{\mkbibcbrackets{#1}}%
126+
{title}{iffieldisCJK}{\mkbibcbrackets{#1}}%
127127
\printfieldhook{title}{\blxja@removeunitpunct}%
128128
\printfieldhook{volume}{\blxja@removeunitpunct}%
129129

0 commit comments

Comments
 (0)