%%
%% This is file `ctex-engine-uptex.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ctex.dtx  (with options: `uptex')
%% 
%%     Copyright (C) 2003--2022
%%     CTEX.ORG and any individual authors listed in the documentation.
%% ---------------------------------------------------------------------
%% 
%%     This work may be distributed and/or modified under the
%%     conditions of the LaTeX Project Public License, either
%%     version 1.3c of this license or (at your option) any later
%%     version. This version of this license is in
%%        http://www.latex-project.org/lppl/lppl-1-3c.txt
%%     and the latest version of this license is in
%%        http://www.latex-project.org/lppl.txt
%%     and version 1.3 or later is part of all distributions of
%%     LaTeX version 2005/12/01 or later.
%% 
%%     This work has the LPPL maintenance status "maintained".
%% 
%% ---------------------------------------------------------------------
%% 
\GetIdInfo$Id: ctex.dtx 13a2256 2022-07-14 18:54:09 +0800 Qing Lee <sobenlee@gmail.com> $
  {upTeX adapter (CTEX)}
\ProvidesExplFile{ctex-engine-uptex.def}
  {\ExplFileDate}{2.5.10}{\ExplFileDescription}
\cs_new_protected:Npn \ctex_set_zhmap:n
  { \tl_gput_right:Nx \g__ctex_zhmap_tl }
\cs_new_protected:Npn \ctex_use_zhmap:
  { \tl_use:N \g__ctex_zhmap_tl }
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
  {
    \cs_new_protected:Npn \ctex_at_shipout_first:n
      { \ctex_gadd_ltxhook:nn { shipout/firstpage } }
    \ctex_at_shipout_first:n { \ctex_use_zhmap: }
  }
  {
    \cs_new_protected:Npn \ctex_add_dvi_zhmap:
      { \AtBeginDvi { \ctex_use_zhmap: } }
    \ctex_after_end_preamble:n { \ctex_add_dvi_zhmap: }
    \ctex_at_end_package:nn { atbegshi }
      {
        \cs_new_protected:Npn \ctex_at_shipout_first:n
          { \AtBeginShipoutFirst }
        \ctex_at_shipout_first:n { \ctex_use_zhmap: }
        \cs_gset_eq:NN \ctex_add_dvi_zhmap: \prg_do_nothing:
      }
  }
\tl_new:N \g__ctex_zhmap_tl
\@onlypreamble \ctex_set_zhmap:n
\NewDocumentCommand \CJKfamily { m }
  { \kanjifamily {#1} \selectfont }
\DeclareErrorKanjiFont    {JY2}{zhrm}{m}{n}{10}
\DeclareKanjiSubstitution {JY2}{zhrm}{m}{n}
\DeclareKanjiSubstitution {JT2}{zhrm}{m}{n}
\DeclareSymbolFont{mincho}{JY2}{zhrm}{m}{n}
\SetSymbolFont{mincho}{bold}{JY2}{zhrm}{bx}{n}
\jfam \symmincho
\ctex_patch_cmd_once:NnnnTF \em
  { \ExplSyntaxOff }
  { \eminnershape \else \gtfamily \itshape }
  { \eminnershape \else \itshape }
  { }
  {
    \ctex_patch_cmd:Nnn \em
      { \mcfamily \upshape \else \gtfamily \itshape }
      { \eminnershape \else \itshape }
  }
\cs_set_nopar:Npn \eminnershape { \upshape }
\cs_new_protected:Npn \ctex_set_upfamily:nnn #1#2#3
  {
    \DeclareKanjiFamily{JY2}{#1}{}
    \DeclareKanjiFamily{JT2}{#1}{}
    \DeclareFontShape{JY2}{#1}{m}{n}{<->~ #2-h}{}
    \DeclareFontShape{JT2}{#1}{m}{n}{<->~ #2-v}{}
    \tl_if_empty:nF {#3}
      {
        \DeclareFontShape{JY2}{#1}{b}{n}{<->~ #3-h}{}
        \DeclareFontShape{JT2}{#1}{b}{n}{<->~ #3-v}{}
        \DeclareFontShape{JY2}{#1}{bx}{n}{<->~ #3-h}{}
        \DeclareFontShape{JT2}{#1}{bx}{n}{<->~ #3-v}{}
      }
  }
\cs_new_protected:Npn \ctex_set_upmap:nnn #1#2#3
  {
    \ctex_set_zhmap:n
      {
        \special { pdf:mapline~#1-h~UniGB-UTF16-H~#2 }
        \special { pdf:mapline~#1-v~UniGB-UTF16-V~#2 }
        \tl_if_empty:nF {#3}
          {
            \special { pdf:mapline~#1b-h~UniGB-UTF16-H~#3 }
            \special { pdf:mapline~#1b-v~UniGB-UTF16-V~#3 }
          }
      }
  }
\cs_new_protected:Npn \ctex_set_upmap_unicode:nnn #1#2#3
  {
    \ctex_set_zhmap:n
      {
        \special { pdf:mapline~#1-h~unicode~#2 }
        \special { pdf:mapline~#1-v~unicode~#2 }
        \tl_if_empty:nF {#3}
          {
            \special { pdf:mapline~#1b-h~unicode~#3 }
            \special { pdf:mapline~#1b-v~unicode~#3 }
          }
      }
  }
\cs_new_protected:Npn \ctex_set_upfonts:nnnnnn #1#2#3#4#5#6
  {
    \ctex_set_upmap:nnn { upserif   } {#1} {#2}
    \ctex_set_upmap:nnn { upserifit } {#3} {}
    \ctex_set_upmap:nnn { upsans    } {#4} {#5}
    \ctex_set_upmap:nnn { upmono    } {#6} {}
  }
\@onlypreamble \ctex_set_upfamily:nnn
\@onlypreamble \ctex_set_upmap:nnn
\@onlypreamble \ctex_set_upmap_unicode:nnn
\@onlypreamble \ctex_set_upfonts:nnnnnn
\bool_if:NT \c__ctex_everysel_loaded_bool
  { \RequirePackage { pxeverysel } }
\cs_new_protected:Npn \ctex_provide_font_hook:NNN #1#2
  {
    \exp_args:Nc \__ctex_provide_font_hook_aux:NNNN
      { CTEX \cs_to_str:N #2 } #1#2
  }
\cs_if_exist:NTF \ctex_gadd_ltxhook:nn
  {
    \cs_new_protected:Npn \__ctex_provide_font_hook_aux:NNNN #1#2#3#4
      {
        \tl_new:N #1
        \exp_args:Nx \ctex_gadd_ltxhook:nn { \cs_to_str:N #2 } {#1}
      }
  }
  {
    \cs_new_protected:Npn \__ctex_provide_font_hook_aux:NNNN #1#2#3#4
      {
        \tl_new:N #1
        \cs_if_exist:NTF #3
          { \tl_gput_right:Nn #3 {#1} }
          { \ctex_parse_name:NN \tl_replace_once:Nnn #2 {#4} { #1#4 } }
      }
  }
\ctex_provide_font_hook:NNN \rmfamily \@rmfamilyhook \selectfont
\ctex_provide_font_hook:NNN \sffamily \@sffamilyhook \selectfont
\ctex_provide_font_hook:NNN \ttfamily \@ttfamilyhook \selectfont
\tl_if_exist:NF \CJKfamilydefault
  { \tl_const:Nn \CJKfamilydefault { \CJKrmdefault } }
\tl_if_exist:NF \CJKrmdefault { \tl_const:Nn \CJKrmdefault { zhrm } }
\tl_if_exist:NF \CJKsfdefault { \tl_const:Nn \CJKsfdefault { zhsf } }
\tl_if_exist:NF \CJKttdefault { \tl_const:Nn \CJKttdefault { zhtt } }
\tl_gput_right:Nn \CTEX@rmfamilyhook { \kanjifamily { \CJKrmdefault } }
\tl_gput_right:Nn \CTEX@sffamilyhook { \kanjifamily { \CJKsfdefault } }
\tl_gput_right:Nn \CTEX@ttfamilyhook { \kanjifamily { \CJKttdefault } }
\tl_gset:Nn \kanjifamilydefault { \CJKfamilydefault }
\normalfont
\ctex_at_end_preamble:n { \ctex_update_default_family: }
\cs_new_protected:Npn \ctex_update_default_family:
  {
    \tl_if_eq:NNT \CJKfamilydefault \l__ctex_family_default_init_tl
      {
        \group_begin:
          \cs_set_eq:NN \__ctex_family_default_wrap:n \exp_not:n
          \tl_gset:Nx \CJKfamilydefault
            {
              \str_case:onF { \familydefault }
                {
                  { \rmdefault } { \exp_not:N \CJKrmdefault }
                  { \sfdefault } { \exp_not:N \CJKsfdefault }
                  { \ttdefault } { \exp_not:N \CJKttdefault }
                }
                { \CJKfamilydefault }
            }
        \group_end:
      }
  }
\tl_new:N \l__ctex_family_default_init_tl
\cs_new_eq:NN \__ctex_family_default_wrap:n \use:n
\tl_set:Nx \l__ctex_family_default_init_tl
  {
    \exp_not:N \__ctex_family_default_wrap:n
      { \exp_not:o { \CJKfamilydefault } }
  }
\tl_gset_eq:NN \CJKfamilydefault \l__ctex_family_default_init_tl
\ctex_hypersetup:n
  {
    driverfallback = dvipdfmx ,
    pdfencoding    = pdfdoc
  }
\ctex_at_end_package:nn { hyperref }
  {
    \ctex_at_shipout_first:n
      { \special { pdf:tounicode~UTF8-UTF16 } }
  }
\cs_new_protected:Npn \ctex_update_ccwd:
  { \skip_set:Nn \ccwd { 1zw + \tex_kanjiskip:D } }
\dim_new:N \ccwd
\cs_new_protected:Npn \ctex_update_ccglue:
  { \skip_set_eq:NN \tex_kanjiskip:D \l__ctex_ccglue_skip }
\skip_new:N \l__ctex_ccglue_skip
\prg_new_conditional:Npnn \ctex_if_ccglue_touched: { TF }
  {
    \skip_if_eq:nnTF { \l__ctex_ccglue_skip } { \tex_kanjiskip:D }
      { \prg_return_false: } { \prg_return_true: }
  }
\cs_new_protected:Npn \ctex_update_em_unit:
  { \dim_set:Nn \ccwd { 1zw } }
\cs_new_protected:Npn \ctex_add_to_selectfont:n #1
  {
    \cs_set_protected:Npx \CTEX@selectfont@hook
      { \exp_not:o { \CTEX@selectfont@hook #1 } }
  }
\cs_new_eq:NN \CTEX@selectfont@hook \prg_do_nothing:
\bool_if:NTF \c__ctex_everysel_loaded_bool
  {
    \cs_if_free:NF \@EverySelectfont@Init
      {
        \group_begin:
        \cs_set:Npn \__ctex_tmp:N #1
          {
            \tl_set:Nn \l__ctex_tmp_tl {#1}
            \cs_new_eq:NN \CTEX@selectfont@save #1
            \cs_new_protected:Npn \__ctex_restore_selectfont:
              {
                \cs_if_free:NF \scr@new@selectfont
                  {
                    \cs_if_free:NF \par@update
                      {
                        \tl_put_right:Nn \@EverySelectfont@Init
                          { \tl_put_right:Nn #1 { \par@update } }
                      }
                    \cs_set_eq:NN \scr@new@selectfont #1
                    \cs_set_eq:NN \CTEX@selectfont@save \scr@selectfont
                  }
                \tl_put_left:Nn \@EverySelectfont@Init
                  { \cs_set_eq:NN #1 \CTEX@selectfont@save }
                \cs_undefine:N \__ctex_restore_selectfont:
              }
          }
        \ctex_parse_name:NN \__ctex_tmp:N \selectfont
      \exp_last_unbraced:NNo \group_end:
      \ctex_patch_cmd_once:NnnnTF { \l__ctex_tmp_tl }
        { \ExplSyntaxOff }
        { \size@update }
        { \CTEX@selectfont@hook \size@update }
        { \__ctex_restore_selectfont: }
        { \ctex_patch_failure:N \selectfont }
      }
    \cs_new_protected:Npn \ctex_gadd_selectfont_hook:n
      { \EverySelectfont }
  }
  {
    \cs_new_protected:Npn \ctex_gadd_selectfont_hook:n
      { \ctex_gadd_ltxhook:nn { selectfont } }
  }
\ctex_gadd_selectfont_hook:n { \CTEX@selectfont@hook }
\cs_new_protected:Npn \ctex_update_xkanjiskip:
  {
    \skip_if_eq:nnT
      { \tex_xkanjiskip:D } { \l__ctex_xkanjiskip_skip }
      {
        \skip_set:Nn \l__ctex_xkanjiskip_skip { \l__ctex_xkanjiskip_tl }
        \skip_set_eq:NN \tex_xkanjiskip:D \l__ctex_xkanjiskip_skip
      }
  }
\tl_new:N \l__ctex_xkanjiskip_tl
\tl_set:Nn \l__ctex_xkanjiskip_tl
  { .25zw plus 1pt minus 1pt }
\skip_new:N \l__ctex_xkanjiskip_skip
\skip_set:Nn \l__ctex_xkanjiskip_skip
  { \tex_xkanjiskip:D }
\ctex_add_to_selectfont:n { \ctex_update_xkanjiskip: }
\ctex_define:n
  {
    space .code:n =
      { \msg_warning:nn { ctex } { invalid-option } }
  }
\ctex_define:n
  {
    punct .code:n =
      {
        \tl_set:Nx \l__ctex_punct_tl {#1}
        \msg_warning:nn { ctex } { invalid-option }
      } ,
    punct .default:n = { quanjiao } ,
  }
%% 
%%
%% End of file `ctex-engine-uptex.def'.
