summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx')
-rw-r--r--Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx284
1 files changed, 172 insertions, 112 deletions
diff --git a/Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx b/Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx
index b9a14299694..5b11fb4a31c 100644
--- a/Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx
+++ b/Master/texmf-dist/source/latex/xpinyin/xpinyin.dtx
@@ -51,7 +51,7 @@ The package is supplied in dtx format and as a pre-extracted zip file,
xpinyin.tds.zip. The later is most convenient for most users: simply
unzip this in your local texmf directory and run texhash to update the
database of file locations. If you want to unpack the dtx yourself,
-running "xetex xpinyin.dtx" will extract the package whereas
+running "luatex xpinyin.dtx" will extract the package whereas
"xelatex xpinyin.dtx" will typeset the documentation.
The package requires LaTeX3 support as provided in the l3kernel and l3packages
@@ -71,6 +71,19 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%</internal>
%<*install>
+\begingroup\expandafter\expandafter\expandafter\endgroup
+\expandafter\ifx\csname directlua\endcsname\relax
+ \begingroup
+ \newlinechar=10 %
+ \errmessage{^^J
+ ********************************************^^J
+ * LuaTeX is required to unpack this package.^^J
+ ********************************************^^J
+ }
+ \endgroup
+ \csname @@end\expandafter\endcsname\expandafter\end
+\fi
+
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse
@@ -118,6 +131,8 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
\file{xpinyin.lua} {\from{\jobname.dtx}{lua}}
}
+\directlua{dofile("xpinyin.lua")}
+
\let\MetaPrefix\DoubleperCent
\generate
@@ -146,19 +161,19 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%<*driver|package>
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
-\GetIdInfo$Id: xpinyin.dtx 700 2014-06-25 10:54:28Z sobenlee $
+\GetIdInfo$Id: xpinyin.dtx 746 2014-12-23 13:58:49Z sobenlee@gmail.com $
{Automatically add pinyin to Chinese characters}
%<*driver>
\ProvidesExplFile{\ExplFileName.\ExplFileExtension}
%</driver>
%<package>\ProvidesExplPackage{\ExplFileName}
- {\ExplFileDate}{1.9}{\ExplFileDescription}
+ {\ExplFileDate}{2.0}{\ExplFileDescription}
%<*driver>
\ExplSyntaxOff
%</driver>
%</driver|package>
%<database>\ProvidesFile{xpinyin-database.def}%
-%<database> [2014/06/24 v1.9 xpinyin database]
+%<database> [2014/12/23 v2.0 xpinyin database]
%
%<*driver>
\documentclass[full,a4paper]{l3doc}
@@ -191,69 +206,59 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
{
\exp_not:N \href
{ http \token_to_str:N : //www.ctan.org/pkg/ \IfNoValueTF {#1} {#2} {#1} }
- } { \pkg{#2} }
+ } { \pkg {#2} }
}
-\cs_set_protected_nopar:Npn \__codedoc_special_main_index:n #1
+\cs_set_protected:Npn \__codedoc_special_index_aux:nnnnn #1#2#3#4#5
{
- \tl_if_empty:NTF \l__codedoc_function_name_prefix_tl
- { \SpecialOptionIndex }
- { \SpecialUsageIndex }
- {#1}
- }
-\cs_new_eq:NN \@@_special_main_index:n \SpecialMainIndex
-\group_begin:
- \char_set_lccode:nn { `\/ } { `\\ }
- \char_set_lccode:nn { `\L } { `\L }
- \char_set_lccode:nn { `\T } { `\T }
- \char_set_lccode:nn { `\X } { `\X }
-\tex_lowercase:D
- {
- \group_end:
- \DeclareDocumentCommand \SpecialMainIndex { m }
+ \__codedoc_special_index_set:Nn \l__codedoc_index_escaped_macro_tl {#2}
+ \str_if_eq:onTF { \@currenvir } { macrocode }
+ { \codeline@wrindex }
{
- \tl_if_head_eq_meaning:nNTF {#1} /
- { \@@_special_main_index:n }
- { \@@_special_main_option_index:n }
- {#1}
+ \HD@target
+ \index
}
- \cs_new_protected:Npn \@@_special_main_option_index:n #1
{
- \@bsphack
- \group_begin:
- \special@index
- {
- #1 \actualchar { /ttfamily ~ #1 } ~ (option)
- \encapchar main
- }
- \special@index
- {
- options: \levelchar #1 \actualchar { /ttfamily ~ #1 }
- \encapchar main
- }
- \group_end:
- \@esphack
- }
- \DeclareDocumentCommand \tn { m }
- {
- { \ttfamily /#1 }
- \SortIndex
- { TeX~and~LaTeX2e~commands }
- {
- /TeX{} ~ and ~ /LaTeXe{} ~ commands: \levelchar
- #1 \actualchar { /ttfamily /bslash ~ #1 }
- }
+ \tl_if_empty:nF { #3 #4 }
+ { #3 \actualchar #4 \levelchar }
+ #1
+ \actualchar
+ {
+ \token_to_str:N \verbatim@font \c_space_tl
+ \l__codedoc_index_escaped_macro_tl
+ }
+ \encapchar
+ hdclindex{\the\c@HD@hypercount}{#5}
}
}
+\DeclareDocumentCommand \cs { O{} m }
+ { \__codedoc_cmd_aux:no {#1} { \c__codedoc_backslash_tl #2 } }
+\DeclareDocumentCommand \tn { O{} m }
+ {
+ \__codedoc_cmd_aux:no
+ { index = TeX , replace = false , #1 }
+ { \c__codedoc_backslash_tl #2 }
+ }
+\DeclareDocumentCommand \meta { +m }
+ { \__codedoc_meta_aux:n {#1} }
+\DeclareExpandableDocumentCommand \bookmarkcstn { O{} m }
+ { \tl_to_str:n {#2} }
+\cs_new:Npn \bookmarkmeta #1 { < \tl_to_str:n {#1} > }
+\cs_generate_variant:Nn \__codedoc_cmd_aux:nn { no }
\ExplSyntaxOff
+\pdfstringdefDisableCommands{%
+ \let\cs\bookmarkcstn
+ \let\tn\bookmarkcstn
+ \let\meta\bookmarkmeta
+ \let\path\@firstofone
+ \let\pkg\@firstofone}
\def\LaTeX{\hologo{LaTeX}}
\def\pdfLaTeX{\hologo{pdfLaTeX}}
\def\XeLaTeX{\hologo{XeLaTeX}}
-\def\TF{true\orvar{}false}
-\def\TTF{\defaultvar{true}\orvar{}false}
-\def\TFF{true\orvar\defaultvar{false}}
-\def\orvar{\textup{\textbar}}
-\def\defaultvar#1{\textbf{\textup{#1}}}
-\def\argbrace#1{\{#1\}}
+\def\TF{true\orval{}false}
+\def\TTF{\defaultval{true}\orval{}false}
+\def\TFF{true\orval\defaultval{false}}
+\def\orval{\textup{\textbar}}
+\def\defaultval#1{\textbf{\textup{#1}}}
\makeatother
\def\indexname{代码索引}
\IndexPrologue{%
@@ -269,7 +274,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%</driver>
% \fi
%
-% \CheckSum{692}
+% \CheckSum{707}
% \GetFileInfo{\jobname.dtx}
%
% \title{\bfseries\pkg{xpinyin} 宏包}
@@ -295,7 +300,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \pkg{xpinyin} 还依赖 \package{l3kernel} 和 \package{l3packages},使用 (pdf)\LaTeX
% 下的 \texttt{GBK} 编码时,还将依赖 \package{xCJK2uni}。
%
-% 需要注意的是,\pkg{xpinyin} 缺省将拼音的字体设置为与文档的主字体(\cs{normalfont})相同,
+% 需要注意的是,\pkg{xpinyin} 缺省将拼音的字体设置为与文档的主字体(\tn{normalfont})相同,
% 所以为了保证声调字母的正确输出,应该选用合适的西文主字体。也可以通过将在下一节介绍的
% \meta{font} 选项来单独设置拼音的字体。
%
@@ -339,9 +344,9 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%
% \begin{function}{pinyinscope}
% \begin{syntax}
-% \cs{begin}\argbrace{pinyinscope}\oarg{options}
+% \tn{begin}\{pinyinscope\}\oarg{options}
% .....
-% \cs{end}\argbrace{pinyinscope}
+% \tn{end}\{pinyinscope\}
% \end{syntax}
% 为 \env{pinyinscope} 环境中的汉字自动注音。例如
% \begin{Example}[frame=single,numbers=left,gobble=5]
@@ -356,12 +361,12 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%
% \begin{function}{\xpinyin}
% \begin{syntax}
-% \cs{xpinyin} \oarg{options} \Arg{单个汉字} \Arg{拼音}
-% \cs{xpinyin*} \oarg{options} \Arg{文字}
+% \tn{xpinyin} \oarg{options} \Arg{单个汉字} \Arg{拼音}
+% \tn{xpinyin*} \oarg{options} \Arg{文字}
% \end{syntax}
-% 对于多音字,可以使用 \cs{xpinyin} 为其设置拼音;而 \cs{xpinyin*} 相当于
-% \env{pinyinscope} 环境的命令形式。\cs{xpinyin} 可以在 \env{pinyinscope} 环境和
-% \cs{xpinyin*} 中使用。例如,
+% 对于多音字,可以使用 \tn{xpinyin} 为其设置拼音;而 \tn{xpinyin*} 相当于
+% \env{pinyinscope} 环境的命令形式。\tn{xpinyin} 可以在 \env{pinyinscope} 环境和
+% \tn{xpinyin*} 中使用。例如,
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.5\linewidth,gobble=5]
% \xpinyin{长}{chang2}\\
% \xpinyin*{甄士隐梦幻识通灵}\\
@@ -371,7 +376,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%
% \begin{function}{\pinyin}
% \begin{syntax}
-% \cs{pinyin} \oarg{options} \Arg{拼音}
+% \tn{pinyin} \oarg{options} \Arg{拼音}
% \end{syntax}
% 用于输出拼音,为了输入的方便 \texttt{\"u} 可以用 |v| 代替。例如,
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.5\linewidth,gobble=5]
@@ -382,41 +387,41 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%
% \begin{function}{\setpinyin}
% \begin{syntax}
-% \cs{setpinyin} \Arg{汉字} \Arg{拼音}
+% \tn{setpinyin} \Arg{汉字} \Arg{拼音}
% \end{syntax}
-% \pkg{xpinyin} 宏包的拼音数据(\file{xpinyin-database.def})来源于 \texttt{Unicode 7.0.0}
+% \pkg{xpinyin} 宏包的拼音数据(\file{xpinyin-database.def})来源于 \texttt{Unicode}
% 的 \texttt{Unihan} 数据库\footnotemark 中的 \file{Unihan_Readings.txt} 文件。对于多
-% 音字,一般来说这个文件选用的是常用读音。可以使用 \cs{setpinyin} 来设置多音字的首选读音。
+% 音字,一般来说这个文件选用的是常用读音。可以使用 \tn{setpinyin} 来设置多音字的首选读音。
% \end{function}
%
% \footnotetext{\url{http://www.unicode.org/Public/UNIDATA/Unihan.zip}}
%
% \begin{function}{\xpinyinsetup}
% \begin{syntax}
-% \cs{xpinyinsetup} \argbrace{\meta{key_1}=\meta{var_1}, \meta{key_2}=\meta{var_2}, ...}
+% \tn{xpinyinsetup} \{ \meta{key_1}=\meta{val_1}, \meta{key_2}=\meta{val_2}, ... \}
% \end{syntax}
% 用于在导言区或文档中,设置拼音的格式。目前可以设置的 \meta{key} 如下介绍。
% \end{function}
%
% \begin{function}{ratio}
% \begin{syntax}
-% ratio = \marg{number}
+% ratio = \Arg{number}
% \end{syntax}
% 设置拼音字体大小与当前正文字体大小的比例,缺省值是 |0.4|。
% \end{function}
%
% \begin{function}{vsep}
% \begin{syntax}
-% vsep = \marg{dimen}
+% vsep = \Arg{dimen}
% \end{syntax}
% 设置拼音的基线与汉字基线的间距,缺省值是 |1 em|。
% \end{function}
%
% \begin{function}{hsep}
% \begin{syntax}
-% hsep = \marg{skip}
+% hsep = \Arg{skip}
% \end{syntax}
-% 设置注音汉字之间的间距,缺省值与 \cs{CJKglue} 的值相同。为了断行时行末的对齐,设置
+% 设置注音汉字之间的间距,缺省值与 \tn{CJKglue} 的值相同。为了断行时行末的对齐,设置
% 的 \meta{skip} 最后有一定的弹性。例如
% \begin{Example}[frame=single,numbers=left,gobble=5]
% \xpinyin*[ratio={.7},hsep={.5em plus .1em},vsep={1.1em}]{贾雨村风尘怀闺秀}
@@ -425,29 +430,29 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
%
% \begin{function}{pysep}
% \begin{syntax}
-% pysep = \marg{glue}
+% pysep = \Arg{glue}
% \end{syntax}
-% 设置 \cs{pinyin} 输出的相邻两个汉语拼音的空白,缺省值是一个空格。
+% 设置 \tn{pinyin} 输出的相邻两个汉语拼音的空白,缺省值是一个空格。
% \end{function}
%
% \begin{function}{font}
% \begin{syntax}
-% font = \marg{font}
+% font = \Arg{font}
% \end{syntax}
-% 设置拼音的字体,缺省值是 \cs{normalfont},即以正文西文字体相同。为了保证拼音能正确
+% 设置拼音的字体,缺省值是 \tn{normalfont},即以正文西文字体相同。为了保证拼音能正确
% 输出,最好选用收字量较大的西文字体。
% \end{function}
%
% \begin{function}{format}
% \begin{syntax}
-% format = \marg{format}
+% format = \Arg{format}
% \end{syntax}
% 设置拼音的其它格式,例如颜色等,缺省值为空。
% \end{function}
%
% \begin{function}{multiple}
% \begin{syntax}
-% multiple = \marg{format}
+% multiple = \Arg{format}
% \end{syntax}
% 设置多音字拼音的其它格式,缺省值为空。可以通过这个选项来提醒校正多音字的拼音。例如
% 本文档设置多音字拼音的颜色是红色(需要载入 \pkg{color} 宏包):
@@ -460,13 +465,13 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \begin{syntax}
% footnote = \meta{\TFF}
% \end{syntax}
-% 是否对拼音环境中的脚注(\cs{footnote})汉字加上拼音。缺省值为 \texttt{false}。
-% 更一般的情况,请使用 \cs{disablepinyin}。
+% 是否对拼音环境中的脚注(\tn{footnote})汉字加上拼音。缺省值为 \texttt{false}。
+% 更一般的情况,请使用 \tn{disablepinyin}。
% \end{function}
%
% \begin{function}[added=2014/01/12]{\disablepinyin,\enablepinyin}
-% \cs{disablepinyin} 用于在拼音环境(\env{pinyinscope})中临时取消对汉字的注音,而
-% \cs{enablepinyin} 用于其后的恢复。
+% \tn{disablepinyin} 用于在拼音环境(\env{pinyinscope})中临时取消对汉字的注音,而
+% \tn{enablepinyin} 用于其后的恢复。
% \end{function}
%
% \end{documentation}
@@ -493,25 +498,32 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \end{macrocode}
%
% \begin{macrocode}
-\RequirePackage{xparse}
-\RequirePackage{l3keys2e}
+\RequirePackage { xparse }
+\RequirePackage { l3keys2e }
% \end{macrocode}
%
% \begin{macro}[internal]{\c_@@_tone_prop}
+% 重音标记 |\`|、|\'| 和 |\=| 在 \env{tabbing} 环境中被移作他用,为避免错误,
+% 我们使用内部命令 \tn{@tabacckludge} 或 \tn{a} 来定义。
% \begin{macrocode}
\prop_new:N \c_@@_tone_prop
\clist_map_inline:nn
{
- { ā }{ \= a } , { á }{ \' a } , { ǎ }{ \v a } , { à }{ \` a } ,
- { ō }{ \= o } , { ó }{ \' o } , { ǒ }{ \v o } , { ò }{ \` o } ,
- { ē }{ \= e } , { é }{ \' e } , { ě }{ \v e } , { è }{ \` e } ,
- { ū }{ \= u } , { ú }{ \' u } , { ǔ }{ \v u } , { ù }{ \` u } ,
- { ḿ }{ \' m } , { ń }{ \' n } , { ň }{ \v n } , { ǹ }{ \` n } ,
- { ī }{ \= { \i } } , { í }{ \' { \i } } ,
- { ǐ }{ \v { \i } } , { ì }{ \` { \i } } ,
+ { ā }{ \@tabacckludge= a } , { á }{ \@tabacckludge' a } ,
+ { ǎ }{ \v a } , { à }{ \@tabacckludge` a } ,
+ { ō }{ \@tabacckludge= o } , { ó }{ \@tabacckludge' o } ,
+ { ǒ }{ \v o } , { ò }{ \@tabacckludge` o } ,
+ { ē }{ \@tabacckludge= e } , { é }{ \@tabacckludge' e } ,
+ { ě }{ \v e } , { è }{ \@tabacckludge` e } ,
+ { ū }{ \@tabacckludge= u } , { ú }{ \@tabacckludge' u } ,
+ { ǔ }{ \v u } , { ù }{ \@tabacckludge` u } ,
+ { ḿ }{ \@tabacckludge' m } , { ń }{ \@tabacckludge' n } ,
+ { ň }{ \v n } , { ǹ }{ \@tabacckludge` n } ,
+ { ī }{ \@tabacckludge= { \i } } , { í }{ \@tabacckludge' { \i } } ,
+ { ǐ }{ \v { \i } } , { ì }{ \@tabacckludge` { \i } } ,
{ ü }{ \" u } ,
- { ǖ }{ \= { \" u } } , { ǘ }{ \' { \" u } } ,
- { ǚ }{ \v { \" u } } , { ǜ }{ \` { \" u } }
+ { ǖ }{ \@tabacckludge= { \" u } } , { ǘ }{ \@tabacckludge' { \" u } } ,
+ { ǚ }{ \v { \" u } } , { ǜ }{ \@tabacckludge` { \" u } }
}
{ \prop_gput:Nnn \c_@@_tone_prop #1 }
% \end{macrocode}
@@ -643,6 +655,21 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[internal]{\@@_leave_vmode:}
+% \begin{macrocode}
+\cs_if_exist:NTF \quitvmode
+ { \cs_new_eq:NN \@@_quit_vmode: \quitvmode }
+ {
+ \cs_new_protected_nopar:Npn \@@_quit_vmode:
+ {
+ \if_mode_vertical:
+ \exp_after:wN \tex_indent:D
+ \fi:
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}[internal]{\@@_make_pinyin_box:nnn}
% \begin{macrocode}
\cs_new_protected_nopar:Npn \@@_make_pinyin_box:nnn #1#2#3
@@ -729,7 +756,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
\keys_set:nn { xpinyin } {#2}
\bool_if:NF \l_@@_enable_bool
{ \@@_width:Nn \l_@@_CJKglue_dim { \CJKglue } }
- \leavevmode
+ \@@_quit_vmode:
\@@_single_aux:nn {#3}
}
}
@@ -886,7 +913,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \begin{macro}[internal]{\@@_to_unicode_xetex:n}
% \begin{macrocode}
\cs_new_nopar:Npn \@@_to_unicode_xetex:n #1
- { \int_to_Hex:n { `#1 } }
+ { \int_to_arabic:n { `#1 } }
% \end{macrocode}
% \end{macro}
%
@@ -894,11 +921,11 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \begin{macrocode}
\cs_new_nopar:Npn \@@_UTF_to_unicode:n #1
{
- \int_to_Hex:n
+ \int_to_arabic:n
{ \exp_args:No \int_from_hex:n { \CJK@plane } * "100 + #1 }
}
\cs_new_nopar:Npn \@@_UTFchar_to_unicode:n #1
- { \int_to_Hex:n { \@@_UTF_viii_to_unicode:NNNw #1 \q_stop } }
+ { \int_to_arabic:n { \@@_UTF_viii_to_unicode:NNNw #1 \q_stop } }
\cs_new_nopar:Npn \@@_UTF_viii_to_unicode:NNNw #1#2#3#4 \q_stop
{
\tl_if_empty:nTF {#4}
@@ -911,9 +938,9 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
% \begin{macro}[internal]{\@@_GBK_to_unicode:n,\@@_GBKchar_to_unicode:n}
% \begin{macrocode}
\cs_new_nopar:Npn \@@_GBK_to_unicode:n #1
- { \CJKtu_sfd_map:nn { \CJK@plane } {#1} }
+ { \int_to_arabic:n { " \CJKtu_sfd_map:nn { \CJK@plane } {#1} } }
\cs_new_nopar:Npn \@@_GBKchar_to_unicode:n #1
- { \CJKchartouni {#1} }
+ { \int_to_arabic:n { " \CJKchartouni {#1} } }
% \end{macrocode}
% \end{macro}
%
@@ -968,7 +995,7 @@ and some specific Chinese Simplified fonts (TrueType or OpenType).
\cs_new_eq:NN \@@_char_to_unicode:n \@@_UTFchar_to_unicode:n
}
\cs_new_eq:NN \@@_select_font: \@@_select_font_aux:
- \cs_new_eq:NN \@@_leavevmode: \leavevmode
+ \cs_new_eq:NN \@@_leavevmode: \@@_quit_vmode:
\cs_new_eq:NN \@@_CJKsymbol_hook: \prg_do_nothing:
\@ifpackageloaded { CJKpunct }
{ \@@_adjust_CJKpunct_hook: }
@@ -1268,8 +1295,9 @@ end
%
% \begin{macrocode}
xpinyin = {
- svnid = "$Id: xpinyin.dtx 700 2014-06-25 10:54:28Z sobenlee $",
+ svnid = "$Id: xpinyin.dtx 746 2014-12-23 13:58:49Z sobenlee@gmail.com $",
uchar = unicode.utf8.char,
+ ugsub = unicode.utf8.gsub,
readings = { },
fixreadings = {
% \end{macrocode}
@@ -1282,13 +1310,23 @@ xpinyin = {
{"U+5973", "HanyuPinlu", "nǚ(1129) rǔ(37)"}
},
database = {
+ source = "http://www.unicode.org/Public/UNIDATA/Unihan.zip",
file = "Unihan_Readings.txt",
date = "Date: 2014-05-09 18:17:02 GMT [JHJ]",
version = "Unicode version: 7.0.0",
dbfile = "xpinyin.db"
},
% \end{macrocode}
-% \pkg{DocStrip} 会将一行开头的 |%%| 替换成 \cs{MetaPrefix},因此我们在行首加了
+% \texttt{Unihan} 的 \texttt{kHanyuPinlu} 数据把韵母 |ou| 的音调都标在了 |u| 上。
+% \begin{macrocode}
+ outones = {
+ oū = "ōu" ,
+ oú = "óu" ,
+ oǔ = "ǒu" ,
+ où = "òu"
+ },
+% \end{macrocode}
+% \pkg{DocStrip} 会将一行开头的 |%%| 替换成 \tn{MetaPrefix},因此我们在行首加了
% 空格,需要把它去掉。
% \begin{macrocode}
preamble = string.gsub([[
@@ -1300,7 +1338,7 @@ xpinyin = {
%% $date
%% $version
%%
- %% by "]] .. arg[-1] .. " " .. arg[0] .. [[" on ]]
+ %% by "texlua xpinyin.lua" on ]]
.. os.date("%Y-%m-%d %X ") .. xpinyin.tzoffset
.. "\n%%", "[ ]+(%%%%)", "%1")
}
@@ -1310,7 +1348,18 @@ xpinyin = {
% \footnote{\url{http://http://www.unicode.org/reports/tr38/}。} 保存到一张表里面。
% \begin{macrocode}
function xpinyin.maketable (txt)
- local f = assert(io.open(txt or xpinyin.database.file, "r"))
+ local f = io.open(txt or xpinyin.database.file, "r")
+ if not f then
+ local source = xpinyin.database.source
+ local zfilename = source:match("[^/]+$")
+ local zfile = zip.open(zfilename)
+ if not zfile then
+ xpinyin.download(source, zfilename)
+ zfile = assert(zip.open(zfilename))
+ end
+ f = assert(zfile:open(xpinyin.database.file))
+ zfile:close()
+ end
local s, prop
for line in f:lines() do
s = line:explode("\t")
@@ -1337,6 +1386,17 @@ function xpinyin.maketable (txt)
end
% \end{macrocode}
%
+% 下载 \file{Unihan.zip}。
+% \begin{macrocode}
+function xpinyin.download (source, zip)
+ print("\nRetrieving Unihan Database from\n", source)
+ local unihan_data = assert(socket.http.request(source), "download failed")
+ local f = assert(io.open(zip, "wb"), "Unihan file (" .. zip .. ") not writable")
+ f:write(unihan_data)
+ f:close()
+end
+% \end{macrocode}
+%
% 往拼音表中加入项目。
% \begin{macrocode}
function xpinyin.insert (unicode, prop, value)
@@ -1354,16 +1414,15 @@ function xpinyin.output (db)
local f = assert(io.open(db or xpinyin.database.dbfile, "w"))
local preamble = xpinyin.preamble:gsub("%$(%w+)", xpinyin.database)
f:write(preamble, "\n")
- local pinyin, code_point, char
+ local hanzi, pinyin
local mt = { }
for index, pyt in xpinyin.pairsByKeys(xpinyin.readings) do
pinyin = assert(xpinyin.grep(pyt))
- code_point = string.format("%X", index)
- char = xpinyin.uchar(index)
- f:write("\\XPYU{", char, "}{", code_point, "}{", pinyin, "}\n")
+ hanzi = xpinyin.uchar(index)
+ f:write("\\XPYU{", hanzi, "}{", index, "}{", pinyin, "}\n")
pinyin = xpinyin.multiple(pyt)
if pinyin then
- mt[#mt + 1] = "\\XPYUM{" .. char .. "}{" .. code_point .. "}{" .. pinyin .."}"
+ mt[#mt + 1] = "\\XPYUM{" .. hanzi .. "}{" .. index .. "}{" .. pinyin .."}"
end
end
f:write(table.concat(mt, "\n"), "\n")
@@ -1391,7 +1450,8 @@ end
% \begin{macrocode}
function xpinyin.grep (pyt)
if pyt.HanyuPinlu then
- return pyt.HanyuPinlu:match("[^%(]+"), "HanyuPinlu"
+ return xpinyin.ugsub(pyt.HanyuPinlu:match("[^%(]+"), "o[ūúǔù]$", xpinyin.outones),
+ "HanyuPinlu"
elseif pyt.Mandarin then
return pyt.Mandarin:match("%S+"), "Mandarin"
elseif pyt.XHC1983 then