From 7d39f6050ecfeed0e08b40464871a9b7f5ffaa12 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 16 Jan 2014 00:10:56 +0000 Subject: xpinyin (15jan14) git-svn-id: svn://tug.org/texlive/trunk@32684 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/xpinyin/xpinyin.sty | 130 ++++++++++++++++-------- 1 file changed, 88 insertions(+), 42 deletions(-) (limited to 'Master/texmf-dist/tex/latex') diff --git a/Master/texmf-dist/tex/latex/xpinyin/xpinyin.sty b/Master/texmf-dist/tex/latex/xpinyin/xpinyin.sty index 0d75f6be182..61ae931166a 100644 --- a/Master/texmf-dist/tex/latex/xpinyin/xpinyin.sty +++ b/Master/texmf-dist/tex/latex/xpinyin/xpinyin.sty @@ -21,10 +21,10 @@ %% \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} -\GetIdInfo$Id: xpinyin.dtx 539 2014-01-04 08:07:32Z sobenlee $ +\GetIdInfo$Id: xpinyin.dtx 542 2014-01-13 18:19:08Z sobenlee $ {Automatically add pinyin to Chinese characters} \ProvidesExplPackage{\ExplFileName} - {\ExplFileDate}{1.6}{\ExplFileDescription} + {\ExplFileDate}{1.7}{\ExplFileDescription} \msg_new:nnn { xpinyin } { no-LuaTeX } { The~xpinyin~package~is~not~supported~in~LuaTeX.\\\\ @@ -190,10 +190,7 @@ \NewDocumentEnvironment { pinyinscope } { O { } } { \keys_set:nn { xpinyin } {#1} - \tl_if_empty:NF \l__xpinyin_hsep_tl - { \cs_set_nopar:Npn \CJKglue { \skip_horizontal:n { \l__xpinyin_hsep_tl } } } - \settowidth \l__xpinyin_CJKglue_dim { \CJKglue } - \__xpinyin_replace_CJKsymbol: + \enablepinyin } { } \NewDocumentCommand \xpinyin { s O { } m } @@ -202,31 +199,68 @@ { \group_begin: \keys_set:nn { xpinyin } {#2} - \tl_if_empty:NF \l__xpinyin_hsep_tl - { \cs_set_nopar:Npn \CJKglue { \skip_horizontal:n { \l__xpinyin_hsep_tl } } } - \settowidth \l__xpinyin_CJKglue_dim { \CJKglue } - \__xpinyin_replace_CJKsymbol: + \enablepinyin #3 \group_end: } { \group_begin: \keys_set:nn { xpinyin } {#2} - \settowidth \l__xpinyin_CJKglue_dim { \CJKglue } + \bool_if:NF \l__xpinyin_enable_bool + { \settowidth \l__xpinyin_CJKglue_dim { \CJKglue } } \leavevmode \__xpinyin_single_aux:nn {#3} } } +\bool_new:N \l__xpinyin_enable_bool +\cs_new_protected_nopar:Npn \__xpinyin_CJKglue: + { \skip_horizontal:n { \l__xpinyin_hsep_tl } } +\NewDocumentCommand \enablepinyin { } + { + \bool_if:NF \l__xpinyin_enable_bool + { + \tl_if_empty:NF \l__xpinyin_hsep_tl + { + \cs_set_eq:NN \__xpinyin_save_CJKglue: \CJKglue + \cs_set_eq:NN \CJKglue \__xpinyin_CJKglue: + } + \settowidth \l__xpinyin_CJKglue_dim { \CJKglue } + \__xpinyin_replace_CJKsymbol: + \__xpinyin_restore_footnote: + \bool_set_true:N \l__xpinyin_enable_bool + } + } +\NewDocumentCommand \disablepinyin { } + { + \bool_if:NT \l__xpinyin_enable_bool + { + \cs_if_eq:NNT \CJKglue \__xpinyin_CJKglue: + { \cs_set_eq:NN \CJKglue \__xpinyin_save_CJKglue: } + \__xpinyin_restore_CJKsymbol: + \bool_set_false:N \l__xpinyin_enable_bool + } + } +\cs_new_protected_nopar:Npn \__xpinyin_restore_footnote: + { + \bool_if:NF \l__xpinyin_footnote_bool + { \tl_put_left:Nn \@parboxrestore { \l__xpinyin_restore_footnote_tl } } + } +\tl_new:N \l__xpinyin_restore_footnote_tl +\tl_set:Nn \l__xpinyin_restore_footnote_tl + { + \int_compare:nNnT \etex_currentgrouptype:D = \c_eleven + { \disablepinyin } + } \dim_new:N \l__xpinyin_CJKglue_dim \cs_new_protected_nopar:Npn \__xpinyin_single_aux:nn #1#2 { - \__xpinyin_single_hook:n { \__xpinyin_replace_CJKsymbol: } \__xpinyin_replace_CJKsymbol_single:n {#2} #1 \group_end: } \cs_new_protected_nopar:Npn \__xpinyin_replace_CJKsymbol_single_aux:n #1 { + \bool_if:NF \l__xpinyin_enable_bool { \__xpinyin_replace_CJKsymbol: } \cs_set_protected_nopar:Npn \CJKsymbol ##1 { \__xpinyin_single_CJKsymbol:nn {##1} {#1} } } @@ -238,14 +272,11 @@ } \cs_new_protected_nopar:Npn \__xpinyin_replace_CJKsymbol_aux: { - \cs_if_eq:NNF \CJKsymbol \__xpinyin_CJKsymbol:n - { - \cs_set_eq:NN \__xpinyin_save_CJKsymbol:n \CJKsymbol - \cs_set_eq:NN \CJKsymbol \__xpinyin_CJKsymbol:n - } + \cs_set_eq:NN \__xpinyin_save_CJKsymbol:n \CJKsymbol + \cs_set_eq:NN \CJKsymbol \__xpinyin_CJKsymbol:n } -\cs_new_protected_nopar:Npn \__xpinyin_single_hook_aux:n - { \cs_if_eq:NNF \CJKsymbol \__xpinyin_CJKsymbol:n } +\cs_new_protected_nopar:Npn \__xpinyin_restore_CJKsymbol_aux: + { \cs_set_eq:NN \CJKsymbol \__xpinyin_save_CJKsymbol:n } \cs_new_protected_nopar:Npn \__xpinyin_select_font_xetex: { \cs_if_exist_use:cF { \l__xpinyin_coor_tl } @@ -291,16 +322,32 @@ \cs_new_eq:NN \__xpinyin_select_font: \__xpinyin_select_font_xetex: \cs_new_eq:NN \__xpinyin_to_unicode:n \__xpinyin_to_unicode_xetex:n \cs_new_eq:NN \__xpinyin_char_to_unicode:n \__xpinyin_to_unicode:n + \cs_new_eq:NN \__xpinyin_restore_CJKsymbol: \__xpinyin_restore_CJKsymbol_aux: \cs_new_eq:NN \__xpinyin_replace_CJKsymbol: \__xpinyin_replace_CJKsymbol_aux: \cs_new_eq:NN \__xpinyin_replace_CJKsymbol_single:n \__xpinyin_replace_CJKsymbol_single_aux:n - \tl_gset:Nn \l__xpinyin_coor_tl - { (\cs_meaning:N \l__xpinyin_font_tl)/\l_xeCJK_current_font_tl/\l__xpinyin_ratio_tl } + \tl_if_exist:NTF \l_xeCJK_current_font_tl + { + \tl_set:Nn \l__xpinyin_coor_tl + { + ( \tl_to_str:N \l__xpinyin_font_tl ) / + \l_xeCJK_current_font_tl/\l__xpinyin_ratio_tl + } + } + { + \tl_set:Nn \l__xpinyin_coor_tl + { + ( \tl_to_str:N \l__xpinyin_font_tl ) / + \xeCJK@family/\f@series/\f@shape/\f@size/\l__xpinyin_ratio_tl + } + } \cs_new_eq:NN \__xpinyin_leavevmode: \prg_do_nothing: - \cs_new_protected_nopar:Npn \__xpinyin_CJKsymbol_hook: - { \makexeCJKinactive \xeCJK_select_font: } - \cs_new_protected_nopar:Npn \__xpinyin_single_hook:n - { \cs_if_eq:NNF \CJKsymbol \__xpinyin_CJKsymbol:n } + \cs_new_protected_nopar:Npx \__xpinyin_CJKsymbol_hook: + { + \exp_not:N \makexeCJKinactive + \cs_if_exist_use:NF \xeCJK_select_font: + { \exp_not:N \xeCJK@setfont } + } } \cs_new_protected_nopar:Npn \__xpinyin_adjust_CJK_hook: { @@ -319,7 +366,7 @@ \@ifpackageloaded { CJKpunct } { \__xpinyin_adjust_CJKpunct_hook: } { - \cs_new_eq:NN \__xpinyin_single_hook:n \__xpinyin_single_hook_aux:n + \cs_new_eq:NN \__xpinyin_restore_CJKsymbol: \__xpinyin_restore_CJKsymbol_aux: \cs_new_eq:NN \__xpinyin_replace_CJKsymbol: \__xpinyin_replace_CJKsymbol_aux: \cs_new_eq:NN \__xpinyin_replace_CJKsymbol_single:n \__xpinyin_replace_CJKsymbol_single_aux:n @@ -327,7 +374,7 @@ { \@ifpackageloaded { CJKpunct } { - \cs_undefine:N \__xpinyin_single_hook:n + \cs_undefine:N \__xpinyin_restore_CJKsymbol: \cs_undefine:N \__xpinyin_replace_CJKsymbol: \cs_undefine:N \__xpinyin_replace_CJKsymbol_single:n \__xpinyin_adjust_CJKpunct_hook: @@ -337,40 +384,37 @@ } \cs_new_protected_nopar:Npn \__xpinyin_adjust_CJKpunct_hook: { + \cs_new_protected_nopar:Npn \__xpinyin_restore_CJKsymbol: + { + \int_compare:nNnTF { \CJKpunct@punctstyle } = { \CJKpunct@ps@plain } + { \__xpinyin_restore_CJKsymbol_aux: } + { \cs_set_eq:NN \CJKosymbol \__xpinyin_save_CJKsymbol:n } + } \cs_new_protected_nopar:Npn \__xpinyin_replace_CJKsymbol: { \int_compare:nNnTF { \CJKpunct@punctstyle } = { \CJKpunct@ps@plain } { \__xpinyin_replace_CJKsymbol_aux: } { - \cs_if_eq:NNF \CJKosymbol \__xpinyin_CJKsymbol:n - { - \cs_set_eq:NN \__xpinyin_save_CJKsymbol:n \CJKosymbol - \cs_set_eq:NN \CJKosymbol \__xpinyin_CJKsymbol:n - } + \cs_set_eq:NN \__xpinyin_save_CJKsymbol:n \CJKosymbol + \cs_set_eq:NN \CJKosymbol \__xpinyin_CJKsymbol:n } } \cs_new_protected_nopar:Npn \__xpinyin_replace_CJKsymbol_single:n ##1 { \int_compare:nNnTF { \CJKpunct@punctstyle } = { \CJKpunct@ps@plain } - { \__xpinyin_replace_CJKsymbol_single_aux:n {##1} } + { \__xpinyin_replace_CJKsymbol_single_aux:n { ##1 } } { \cs_set_protected_nopar:Npn \CJKosymbol ####1 - { \__xpinyin_single_CJKsymbol:nn {####1} {##1} } + { \__xpinyin_single_CJKsymbol:nn { ####1 } { ##1 } } } } - \cs_new_protected_nopar:Npn \__xpinyin_single_hook:n - { - \int_compare:nNnTF { \CJKpunct@punctstyle } = { \CJKpunct@ps@plain } - { \__xpinyin_single_hook_aux:n } - { \cs_if_eq:NNF \CJKosymbol \__xpinyin_CJKsymbol:n } - } } \NewDocumentCommand \pinyin { O { } m } { \group_begin: \keys_set:nn { xpinyin } {#1} \l__xpinyin_font_tl - \l__xpinyin_format_tl + \l__xpinyin_format_tl { } \selectfont \c__xpinyin_reset_UTF_cs_tl \__xpinyin_pinyin:n {#2} @@ -468,8 +512,10 @@ } \NewDocumentCommand \xpinyinsetup { m } { \keys_set:nn { xpinyin } {#1} } \clist_map_inline:nn - { ratio , vsep , hsep , pysep , font , format , multiple } + { ratio , vsep , hsep , pysep , font , format , multiple , footnote } { \keys_define:nn { xpinyin } { #1 .tl_set:c = { l__xpinyin_ #1 _tl } } } +\keys_define:nn { xpinyin } + { footnote .bool_set:N = \l__xpinyin_footnote_bool } \keys_set:nn { xpinyin } { ratio = .4 , -- cgit v1.2.3