latex font 手动指定文件

\documentclass[12pt]{book}
\usepackage{xeCJK}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{geometry}
\geometry {paperheight=297mm, paperwidth=210mm, left=9mm, right=9mm, top=7mm, bottom=7mm}

\def\CustomFontRootPath{./font}

%------------------------------------------------------------------------------%
%                                  cn sc
%------------------------------------------------------------------------------%
% 有衬线CJK
%\rmfamily \textrm
\setCJKmainfont{SourceHanSerifSC}[
    Path=\CustomFontRootPath/cn/roma/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold
]

\newfontfamily\scRoma[
    Path=\CustomFontRootPath/cn/roma/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold
]{SourceHanSerifSC}

% 无衬线CJK
% \sffamily \textsf
\setCJKsansfont{SourceHanSansSC}[
    Path=\CustomFontRootPath/cn/sans/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold
]

\newfontfamily\scSans[
    Path=\CustomFontRootPath/cn/sans/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold
]{SourceHanSansSC}

% 等宽CJK
% \ttfamily \texttt
\setCJKmonofont{sarasa-fixed-sc}[
    Path=\CustomFontRootPath/cn/mono/,
    Scale=1.0,
    Extension = .ttf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic
]

\newfontfamily\scMono[%
    Path=\CustomFontRootPath/cn/mono/,
    Scale=1.0,
    Extension = .ttf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic
]{sarasa-fixed-sc}

%------------------------------------------------------------------------------%
%                                  en
%------------------------------------------------------------------------------%

\setromanfont{SourceSerif4}[
    Path=\CustomFontRootPath/en/roma/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
]

\newfontfamily{\enRoma}[
    Path=\CustomFontRootPath/en/roma/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
]{SourceSerif4}

\setsansfont{SourceSans3}[
    Path=\CustomFontRootPath/en/sans/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
]

\newfontfamily\enSans[
    Path=\CustomFontRootPath/en/sans/,
    Scale=1.0,
    Extension = .otf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
]{SourceSans3}

\setmonofont{sarasa-fixed-sc}[
    Path=\CustomFontRootPath/cn/mono/,
    Scale=1.0,
    Extension = .ttf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic
]

\newfontfamily\enMono[
    Path=\CustomFontRootPath/cn/mono/,
    Scale=1.0,
    Extension = .ttf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic
]{sarasa-fixed-sc}

%------------------------------------------------------------------------------%
%                                  font command
%------------------------------------------------------------------------------%
\DeclareTextFontCommand{\fontscRoma}{\scRoma\rmfamily}
\DeclareTextFontCommand{\fontscSans}{\scSans\sffamily}
\DeclareTextFontCommand{\fontscMono}{\scMono\ttfamily}
\DeclareTextFontCommand{\fontenRoma}{\enRoma\rmfamily}
\DeclareTextFontCommand{\fontenSans}{\enSans\sffamily}
\DeclareTextFontCommand{\fontenMono}{\enMono\ttfamily}


\definecolor{WhatEverColor}{rgb}{0.9,0.4,0.5}
\DeclareTextFontCommand{\fontscRomaColor}{\scRoma\rmfamily\color{WhatEverColor}}
\DeclareTextFontCommand{\fontscSansColor}{\scSans\sffamily\color{WhatEverColor}}
\DeclareTextFontCommand{\fontscMonoColor}{\scMono\ttfamily\color{WhatEverColor}}
\DeclareTextFontCommand{\fontenRomaColor}{\enRoma\rmfamily\color{WhatEverColor}}
\DeclareTextFontCommand{\fontenSansColor}{\enSans\sffamily\color{WhatEverColor}}
\DeclareTextFontCommand{\fontenMonoColor}{\enMono\ttfamily\color{WhatEverColor}}

\begin{document}

\textrm{有衬线 中文}

\textsf{无衬线 中文}

\texttt{等宽 中文}

\textrm{English}

\textsf{English}

\texttt{English}

\texttt{等宽的字体,\\ eng-\\中文,.\\abcdw.}

\fontscRoma{中文 Roma}

\fontscSans{中文 Sans}

\fontscMono{中文 Mono}

\fontenRoma{fontenRoma}

\fontenSans{fontenSans}

\fontenMono{fontenMono}

\fontscRomaColor{中文 Roma}

\fontscSansColor{中文 Sans}

\fontscMonoColor{中文 Mono}

\fontenRomaColor{fontenRoma}

\fontenSansColor{fontenSans}

\fontenMonoColor{fontenMono}

\fontenRomaColor{People have never stopped the pursuit of truth , virtue and beauty since ancient times.}

\fontscRomaColor{人类对真善美的追求, 亘古不变.}

\end{document}

path and file name

gnu font

https://github.com/adobe-fonts/source-han-serif
https://github.com/adobe-fonts/source-han-sans
https://github.com/adobe-fonts/source-han-mono
https://github.com/be5invis/Sarasa-Gothic

https://github.com/adobe-fonts/source-sans
https://github.com/adobe-fonts/source-serif
https://github.com/adobe-fonts/source-code-pro

posted @ 2023-04-19 14:55  fndefbwefsowpvqfx  阅读(73)  评论(0编辑  收藏  举报