Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add \ifbeginwithCJKtoken and \ifendwithCJKtoken.
  • Loading branch information
kmaed committed Feb 18, 2018
1 parent c3bd4ca commit acb8685
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Binary file modified doc/biblatex-japanese.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions doc/biblatex-japanese.tex
Expand Up @@ -159,6 +159,7 @@ \subsection{和文文字判定}
文献データベース自体に\bibfield{langid}といった言語情報を付加しておくことである.
しかし,このような情報をいちいち付加するのは面倒であるし,
フィールド毎に和文文字を含むかどうかで動作を変更できると便利である.
このためのテストコマンドを準備しておく.

\begin{ltxsyntax}
\cmditem{ifCJKtokens}{tokens}{true code}{false code}
Expand All @@ -167,6 +168,21 @@ \subsection{和文文字判定}
コードポイントの文字が含まれていれば\prm{true code}を実行し,
そうでなければ\prm{false code}を実行する.
テストは一度\prm{tokens}を完全展開してから行われる.

なお,Unicodeであることを前提にしているので,p\TeX の場合は
怪しい動作になる.どうなるのかをちゃんと理解したら対策するかもしれない.

\cmditem{ifbeginwithCJKtoken}{tokens}{true code}{false code}

\prm{tokens}の先頭にU+2E80以上のコードポイントの文字があれば
\prm{true code}を実行し,そうでなければ\prm{false code}を実行する.
テストは一度\prm{tokens}を完全展開してから行われる.

\cmditem{ifendwithCJKtoken}{tokens}{true code}{false code}

\prm{tokens}の末尾にU+2E80以上のコードポイントの文字があれば
\prm{true code}を実行し,そうでなければ\prm{false code}を実行する.
テストは一度\prm{tokens}を完全展開してから行われる.
\end{ltxsyntax}

\subsection{置換コマンド}
Expand Down
39 changes: 36 additions & 3 deletions latex/biblatex-japanese.def
Expand Up @@ -25,17 +25,50 @@

%% --- User commands ---
\ExplSyntaxOn

\cs_new:Nn \blxja_if_CJKtoken:nTF {
\token_if_cs:NTF #1 {#3} {
\int_compare:nNnTF {`#1} > {"2E7F} {#2} {#3} % ToDo: change CJK chars range
}
}
\cs_new:Nn \blxja_if_CJKtoken:nT {\blxja_if_CJKtoken:nTF {#1} {#2} {}}
\DeclareDocumentCommand{\ifCJKtokens}{ m m m }{
\tl_set:Nx \l_tmpa_tl {#1}
\tl_set:Nx \l_tmpa_tl { \tl_to_str:n {#1} }
\bool_set_false:N \l_tmpa_bool
\tl_map_inline:Nn \l_tmpa_tl {
\token_if_cs:NF ##1 {
\int_compare:nNnT {`##1} > {"2E7F} {\bool_set_true:N \l_tmpa_bool} % ToDo: change CJK chars range
\blxja_if_CJKtoken:nT {##1} {\bool_set_true:N \l_tmpa_bool}
}
}
\bool_if:NTF \l_tmpa_bool {#2} {#3}
}
\cs_generate_variant:Nn \blxja_if_CJKtoken:nTF {fTF}
\cs_generate_variant:Nn \tl_if_head_is_group:nTF {oTF}
\DeclareDocumentCommand{\ifbeginwithCJKtoken}{ m m m }{
\tl_set:Nf \l_tmpa_tl { \tl_head:f {#1} }
\tl_if_head_is_group:oTF { \l_tmpa_tl }{
\tl_set:Nf \l_tmpa_tl { \exp_last_unbraced:No \use:n \l_tmpa_tl }
\ifbeginwithCJKtoken { \l_tmpa_tl } {#2} {#3}
}{
\blxja_if_CJKtoken:fTF { \l_tmpa_tl } {#2} {#3}
}
}
\cs_generate_variant:Nn \tl_if_single:nTF {oTF}
\DeclareDocumentCommand{\ifendwithCJKtoken}{ m m m }{
\tl_set:Nf \l_tmpa_tl { #1 }
\tl_if_single:oTF \l_tmpa_tl {} {
\tl_set:Nf \l_tmpa_tl { \tl_tail:f {\l_tmpa_tl} }
}
\tl_if_head_is_group:oTF { \l_tmpa_tl }{
\tl_set:Nf \l_tmpa_tl { \exp_last_unbraced:No \use:n \l_tmpa_tl }
\ifendwithCJKtoken { \l_tmpa_tl } {#2} {#3}
}{
\tl_if_single:oTF {\l_tmpa_tl} {
\blxja_if_CJKtoken:fTF { \l_tmpa_tl } {#2} {#3}
} {
\ifendwithCJKtoken { \l_tmpa_tl } {#2} {#3}
}
}
}
\ExplSyntaxOff

\DeclareDocumentCommand{\replacecommand}{ s }{%
Expand Down

0 comments on commit acb8685

Please sign in to comment.