使用 xpinyin 包在字符的左侧或右侧显示拼音

使用 xpinyin 包在字符的左侧或右侧显示拼音

xpinyin定义了vsep可以将拼音移到字符下方,但是如何将拼音移到字符的左侧或右侧?有没有办法将拼音向左旋转?谢谢!

在此处输入图片描述

这里是 MWE:

\documentclass{article}
\usepackage{xeCJK}
\usepackage{adjustbox}

\usepackage{xpinyin}


\begin{document}
\Huge\sffamily

\xpinyin[vsep={0.97em}]{举}{ju3} \xpinyin[vsep={-0.57em}]{举}{ju3} \xpinyin*{\rotatebox[origin=c]{90}{举}} \xpinyin*{\rotatebox[origin=c]{-90}{举}}

\end{document}

答案1

也许值得要求软件包维护者添加新功能。

当然,信息在拼音数据库中,一旦读入,项目就可以放置在任何位置,包括多次读出。

示范 (使用 lualatex)

实验

平均能量损失

\documentclass{article}
%\usepackage{xeCJK}
%\usepackage{adjustbox}
%\usepackage{xpinyin}
\usepackage{fontspec}
\newfontfamily\cjk{NotoSerifCJKtc-Regular}
\newfontfamily\cjkb{MingLiu-ExtB}

%-------------------------------------------------------------
\ExplSyntaxOn

% Adapted from xpinyin.sty:
% #1 (character), rather than #2 (Unicode codepoint),
% becomes part of the control sequence name.
% #3 is the pinyin. All three are in the database.
\cs_new_protected:Npn \xpinyin_customary:nnn #1#2
  { \cs_gset_nopar:cpn { c__xpinyin_#1_tl } }
\cs_new_protected:Npn \xpinyin_multiple:nnn #1#2
  { \cs_gset_nopar:cpn { c__xpinyin_multiple_#1_clist } }
\group_begin:
  \cs_set_eq:NN \XPYU  \xpinyin_customary:nnn
  \cs_set_eq:NN \XPYUM \xpinyin_multiple:nnn
  \file_input:n { xpinyin-database.def }
\group_end:
%==============================


        \cs_generate_variant:Nn 
            \tl_replace_all:Nnn 
            { Nxx }


\bool_new:N \g__mpy_printfirstvar_bool
\NewDocumentCommand \xpppinyin { s m }
  {
  \IfBooleanTF {#1 }
        { \bool_gset_false:N \g__mpy_printfirstvar_bool }
        { \bool_gset_true:N \g__mpy_printfirstvar_bool }
  
        \tl_set:Nn \l_tmpa_tl { #2 }

        \tl_map_function:NN
        \l_tmpa_tl 
        \gl_funcxpp:n 

        \tl_use:N \l_tmpa_tl

  }


%-----------------------------
    \cs_set:Npn \gl_funcxpp:n #1 { 
     \tl_set:Nn \l_tmpb_tl { #1 }
%    \tl_show:N \l_tmpb_tl

   \tl_replace_all:Nxx
    \l_tmpa_tl
    { \l_tmpb_tl }
    {
        \clist_if_exist:cTF
                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                { % there is a comma list for the character
        \bool_if:NTF
        \g__mpy_printfirstvar_bool
        { % bool true = print first reading
                        \clist_item:cn 
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { 1 }
                                * %=multi
            }
            {   % bool false = print all readings               
                                (
                                \clist_use:cn                               
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { , }
                                )                               
     }
                                \tex_space:D
                 }
                { % not a comma list = only one reading
                    \cs_if_exist:cT
                    { c__xpinyin_ \l_tmpb_tl _tl }
                    {
                     \use:c { c__xpinyin_ \l_tmpb_tl _tl }
                     \tex_space:D
                    }
                }
                }

%   \cs_show:c { c__xpinyin_ \l_tmpb_tl _tl }
}


        \cs_generate_variant:Nn 
                    \seq_set_split:Nnn 
                { cnx }

%-----------------------------
\keys_define:nn { mpy }
{
mpya .tl_set:c = { l_mpy_char1_tl },
mpya .initial:n = { },
mpya .default:n = { },
mpyb .tl_set:c = { l_mpy_char2_tl },
mpyb .initial:n = { },
mpyb .default:n = { },
mpyc .tl_set:c = { l_mpy_char3_tl },
mpyc .initial:n = { },
mpyc .default:n = { },
}
\seq_new:c { l_mpy_char1_seq }
\seq_new:c { l_mpy_char2_seq }
\seq_new:c { l_mpy_char3_seq }

\int_new:c { l_mpy_char1item_int }
\int_new:c { l_mpy_char2item_int }
\int_new:c { l_mpy_char3item_int }

\int_new:c { l_mpy_char1py_int }
\int_new:c { l_mpy_char2py_int }
\int_new:c { l_mpy_char3py_int }



\int_new:c { l_mpy_char1count_int }
\NewDocumentCommand \xppname { O{ } m }
  {
  
     \int_gset:cn { l_mpy_char1count_int } { 0 }
     \int_gset:cn { l_mpy_char1item_int  } { 0 } 
     \int_gset:cn { l_mpy_char2item_int  } { 0 } 
     \int_gset:cn { l_mpy_char3item_int  } { 0 } 
          
      \IfNoValueF{#1}
    {
        \keys_set:nn { mpy } { #1 } 
        }
  
  
  %----- if the option has been set
        \tl_if_empty:cF { l_mpy_char1_tl }
        {  
                %----- store the record
                    \seq_set_split:cnx
                             { l_mpy_char1_seq }
                            { ; } % separator
                            { \tl_use:c { l_mpy_char1_tl } }
                %----- store the fields
                \int_set:cn
                        { l_mpy_char1item_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char1_seq }
                                    { 1 } %the i-th character
                        }
                \int_set:cn
                        { l_mpy_char1py_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char1_seq }
                                    { 2 } %the k-th pinyin reading
                        }

        }%end1
  %----- if the option has been set
        \tl_if_empty:cF { l_mpy_char2_tl }
        {  
                %----- store the record
                    \seq_set_split:cnx
                             { l_mpy_char2_seq }
                            { ; } % separator
                            { \tl_use:c { l_mpy_char2_tl } }
                %----- store the fields
                \int_set:cn
                        { l_mpy_char2item_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char2_seq }
                                    { 1 } %the i-th character
                        }
                \int_set:cn
                        { l_mpy_char2py_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char2_seq }
                                    { 2 } %the k-th pinyin reading
                        }

        }%end2
  %----- if the option has been set
        \tl_if_empty:cF { l_mpy_char3_tl }
        {  
                %----- store the record
                    \seq_set_split:cnx
                             { l_mpy_char3_seq }
                            { ; } % separator
                            { \tl_use:c { l_mpy_char3_tl } }
                %----- store the fields
                \int_set:cn
                        { l_mpy_char3item_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char3_seq }
                                    { 1 } %the i-th character
                        }
                \int_set:cn
                        { l_mpy_char3py_int }
                        {
                                \seq_item:cn
                                    { l_mpy_char3_seq }
                                    { 2 } %the k-th pinyin reading
                        }

        }%end3
  
  





  
  %-----
        \tl_set:Nn \l_tmpa_tl { #2 }

        \tl_map_function:NN
        \l_tmpa_tl
        \gl_funcxppname:n 

        \seq_set_split:NnV \l_tmpa_seq { ~ } \l_tmpa_tl

    \seq_map_function:NN 
                \l_tmpa_seq 
                \gl_functitlecase:n
  }


%-----------------------------
    \cs_set:Npn \gl_funcxppname:n #1 { 

        \int_gincr:c { l_mpy_char1count_int }
    
     \tl_set:Nn \l_tmpb_tl { #1 }

   \tl_replace_all:Nxx
    \l_tmpa_tl
    { \l_tmpb_tl }
    {
        \clist_if_exist:cTF
                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                { % there is a comma list for the character
                   % nth character's mth pinyin
                        \int_compare:nNnTF
                                  { \int_use:c { l_mpy_char1count_int } }
                                   = 
                                   { \int_use:c { l_mpy_char2item_int } }
                                  {
                        \clist_item:cn 
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { \int_use:c { l_mpy_char2py_int } }
                                        }%%
                            { %not 2            
                   % nth character's mth pinyin
                        \int_compare:nNnTF
                                  { \int_use:c { l_mpy_char1count_int } }
                                   = 
                                   { \int_use:c { l_mpy_char3item_int } }
                                  {
                        \clist_item:cn 
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { \int_use:c { l_mpy_char3py_int } }
                                        }%%
                    { % not 3
                   % nth character's mth pinyin
                        \int_compare:nNnTF
                                  { \int_use:c { l_mpy_char1count_int } }
                                   = 
                                   { \int_use:c { l_mpy_char1item_int } }
                                  {
                        \clist_item:cn 
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { \int_use:c { l_mpy_char1py_int } }
                                        }%%
                                        { % not 1, therefore 1st pinyin
                        \clist_item:cn 
                                { c__xpinyin_multiple_ \l_tmpb_tl _clist }
                                { 1 }
                                }%false1
                                }%false2
                                }%false3
                 }
                { % not a comma list = only one reading
                    \cs_if_exist:cTF
                    { c__xpinyin_ \l_tmpb_tl _tl }
                    {
                     \use:c { c__xpinyin_ \l_tmpb_tl _tl }
                    }
                    { % anything else
                        #1
                    }
                }
                }
}


\tl_new:N \l_gl_item_tl
%-----------------------------
    \cs_set:Npn \gl_functitlecase:n #1
      {~
            \tl_set:Nn \l_gl_item_tl { #1 }
        \text_titlecase:nn {en} { \tl_use:N \l_gl_item_tl }
%        \tex_space:D
      }
%-----------------------------




\ExplSyntaxOff



\begin{document}
\Huge

{\cjk 举} $\mapsto$ \xpppinyin{举} 

{\cjk 我诸葛亮} $\mapsto$ \xpppinyin{我诸葛亮}

{\cjk 我诸葛亮} $\mapsto$ \xpppinyin*{我诸葛亮}

{\cjkb 

相关内容