使用texlive+texstudio,编译简单.tex文件,出现Package fontspec Error。

.tex代码如下:

\documentclass{article}

\usepackage{ctex}

\begin{document}
	hello. 
	
	你好
\end{document}

error信息如下:

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.

name = KaiTi/OT, rootname = KaiTi/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf KaiTi/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find KaiTi/OT.mf.

name = KaiTi/B/OT, rootname = KaiTi/B/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf KaiTi/B/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find KaiTi/B/OT.mf.

name = SimHei/OT, rootname = SimHei/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimHei/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimHei/OT.mf.

name = SimHei/I/OT, rootname = SimHei/I/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimHei/I/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimHei/I/OT.mf.

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.

name = SimSun/BI/OT, rootname = SimSun/BI/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimSun/BI/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/BI/OT.mf.

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile! kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile! kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.

name = SimHei/OT, rootname = SimHei/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimHei/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimHei/OT.mf.

name = SimHei/OT, rootname = SimHei/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimHei/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimHei/OT.mf.

name = KaiTi/OT, rootname = KaiTi/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf KaiTi/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find KaiTi/OT.mf.

name = KaiTi/OT, rootname = KaiTi/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf KaiTi/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find KaiTi/OT.mf.

name = SimSun/OT, rootname = SimSun/OT, pointsize = mktexmf: empty or non-existent rootfile!

kpathsea: Running mktexmf SimSun/OT.mf The command name is D:\texlive2020\installfiles_texlive\texlive\2020\bin\win32\mktexmf Cannot find SimSun/OT.mf.


出现错误

error日志如下:

行 101: Package fontspec Error: The font "SimSun" cannot be found. }
行 101: Package fontspec Error: The font "SimSun" cannot be found. }
行 101: Package fontspec Error: The font "SimSun" cannot be found. }
行 101: Package fontspec Error: The font "SimHei" cannot be found. }
行 101: Package fontspec Error: The font "SimHei" cannot be found. }
行 101: Package fontspec Error: The font "KaiTi" cannot be found. }
行 101: Package fontspec Error: The font "KaiTi" cannot be found. }
行 12: Font TU/SimSun(0)/m/n/10.53937=SimSun/OT at 10.53937pt not loadable: Metric (TFM) file or installed font not found. ^^I你
: Font "SimSun" does not contain requested Script(fontspec) "CJK".

解决方法:根据报错的文件,修改字体名字,使之与电脑上字体名字统一。

报错文件通常为:ctex-fontset-windows.def 或者 ctex-fontset-windowsnew.def。修改示例如下:

改动前:

\ctex_fontset_case:nnn
  {
    \ctex_zhmap_case:nnn
      {
        \ctex_punct_set:n { windows }
        \setCJKmainfont { simsun.ttc }
          [ BoldFont = simhei.ttf, ItalicFont = simkai.ttf ]
        \setCJKsansfont { msyh.\c__ctex_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
        \setCJKmonofont { simfang.ttf }
        \setCJKfamilyfont { zhsong  } { simsun.ttc  }
        \setCJKfamilyfont { zhhei   } { simhei.ttf  }
        \setCJKfamilyfont { zhfs    } { simfang.ttf }
        \setCJKfamilyfont { zhkai   } { simkai.ttf  }
        \setCJKfamilyfont { zhyahei } { msyh.\c__ctex_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
        \setCJKfamilyfont { zhli    } { simli.ttf   }
        \setCJKfamilyfont { zhyou   } { simyou.ttf  }
        \ctex_punct_map_family:nn   { \CJKrmdefault          } { zhsong   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault          } { zhhei    }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault          } { zhkai    }
        \ctex_punct_map_family:nn   { \CJKsfdefault          } { zhyahei  }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhyahei } { zhyaheib }
        \ctex_punct_map_family:nn   { \CJKttdefault          } { zhfs     }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { windows }
        \ctex_punct_set:n { windows }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { simsun.ttc                   }
      { simhei.ttf                   }
      { simkai.ttf                   }
      { msyh.\c__ctex_msyh_suffix_tl    }
      { msyhbd.\c__ctex_msyh_suffix_tl  }
      { simfang.ttf                  }
    \ctex_set_upfamily:nnn { zhsong  } { upzhserif   } {}
    \ctex_set_upfamily:nnn { zhhei   } { upzhserifb  } {}
    \ctex_set_upfamily:nnn { zhfs    } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai   } { upzhserifit } {}
    \ctex_set_upfamily:nnn { zhyahei } { upzhsans    } { upzhsansb }
    \ctex_set_upfamily:nnn { zhli    } { upschrm     } {}
    \ctex_set_upfamily:nnn { zhyou   } { upschgt     } {}
    \ctex_set_upmap:nnn { upstsl } { simli.ttf  } {}
    \ctex_set_upmap:nnn { upstht } { simyou.ttf } {}
  }
  {
    \setCJKmainfont   { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
    \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKmonofont   { FangSong }
    \setCJKfamilyfont { zhsong  } { SimSun          }
    \setCJKfamilyfont { zhhei   } { SimHei          }
    \setCJKfamilyfont { zhfs    } { FangSong        }
    \setCJKfamilyfont { zhkai   } { KaiTi           }
    \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKfamilyfont { zhli    } { LiSu            }
    \setCJKfamilyfont { zhyou   } { YouYuan         }
  }
\NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
\NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
\NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
\NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
\NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
\NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }
%% 
%%
%% End of file `ctex-fontset-windows.def'.

改动后:

\ctex_fontset_case:nnn
  {
    \ctex_zhmap_case:nnn
      {
        \ctex_punct_set:n { windows }
        \setCJKmainfont { simsun.ttc }
          [ BoldFont = simhei.ttf, ItalicFont = simkai.ttf ]
        \setCJKsansfont { msyh.\c__ctex_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
        \setCJKmonofont { simfang.ttf }
        \setCJKfamilyfont { zhsong  } { simsun.ttc  }
        \setCJKfamilyfont { zhhei   } { simhei.ttf  }
        \setCJKfamilyfont { zhfs    } { simfang.ttf }
        \setCJKfamilyfont { zhkai   } { simkai.ttf  }
        \setCJKfamilyfont { zhyahei } { msyh.\c__ctex_msyh_suffix_tl }
          [ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
        \setCJKfamilyfont { zhli    } { simli.ttf   }
        \setCJKfamilyfont { zhyou   } { simyou.ttf  }
        \ctex_punct_map_family:nn   { \CJKrmdefault          } { zhsong   }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault          } { zhhei    }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault          } { zhkai    }
        \ctex_punct_map_family:nn   { \CJKsfdefault          } { zhyahei  }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhyahei } { zhyaheib }
        \ctex_punct_map_family:nn   { \CJKttdefault          } { zhfs     }
      }
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { windows }
        \ctex_punct_set:n { windows }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
      { }
  }
  {
    \ctex_set_upfonts:nnnnnn
      { simsun.ttc                   }
      { simhei.ttf                   }
      { simkai.ttf                   }
      { msyh.\c__ctex_msyh_suffix_tl    }
      { msyhbd.\c__ctex_msyh_suffix_tl  }
      { simfang.ttf                  }
    \ctex_set_upfamily:nnn { zhsong  } { upzhserif   } {}
    \ctex_set_upfamily:nnn { zhhei   } { upzhserifb  } {}
    \ctex_set_upfamily:nnn { zhfs    } { upzhmono    } {}
    \ctex_set_upfamily:nnn { zhkai   } { upzhserifit } {}
    \ctex_set_upfamily:nnn { zhyahei } { upzhsans    } { upzhsansb }
    \ctex_set_upfamily:nnn { zhli    } { upschrm     } {}
    \ctex_set_upfamily:nnn { zhyou   } { upschgt     } {}
    \ctex_set_upmap:nnn { upstsl } { simli.ttf  } {}
    \ctex_set_upmap:nnn { upstht } { simyou.ttf } {}
  }
  {
    \setCJKmainfont   { simsun.ttc } [ BoldFont = simhei.ttf , ItalicFont = simkai.ttf ]
    \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKmonofont   { FangSong }
    \setCJKfamilyfont { zhsong  } { simsun.ttc          }
    \setCJKfamilyfont { zhhei   } { simhei.ttf          }
    \setCJKfamilyfont { zhfs    } { FangSong        }
    \setCJKfamilyfont { zhkai   } { simkai.ttf           }
    \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKfamilyfont { zhli    } { LiSu            }
    \setCJKfamilyfont { zhyou   } { YouYuan         }
  }
\NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
\NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
\NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
\NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
\NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
\NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }
%% 
%%
%% End of file `ctex-fontset-windows.def'.

 

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐