textit{} 和 textbf{} 不起作用,并且存在多个错误,我不知道如何解决

textit{} 和 textbf{} 不起作用,并且存在多个错误,我不知道如何解决

这是代码,

% !TEX TS-program = lualatex

\documentclass[12pt]{article}

\usepackage[paperwidth=9in, paperheight=14in]{geometry}


\usepackage{graphicx}

\usepackage{amssymb}

\usepackage{amsmath}

\usepackage{amsthm}

\usepackage{empheq}

\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\usepackage{fontspec}

\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}

\setmainfont[%
ItalicFont=NewCM10-Italic.otf%
BoldFont=NewCM10-Bold.otf,%
BoldItalicFont=NewCM10-BoldItalic.otf,%
SmallCapsFeatures={Numbers=OldStyle}]{NewCM10-Regular.otf}

\setsansfont[%
ItalicFont=NewCMSans10-Oblique.otf,%
BoldFont=NewCMSans10-Bold.otf,%
BoldItalicFont=NewCMSans10-BoldOblique.otf,%
SmallCapsFeatures={Numbers=OldStyle}]{NewCMSans10-Regular.otf}

\setmonofont[ItalicFont=NewCMMono10-Italic.otf,%
BoldFont=NewCMMono10-Bold.otf,%
BoldItalicFont=NewCMMono10-BoldOblique.otf,%
SmallCapsFeatures={Numbers=OldStyle}]{NewCMMono10-Regular.otf}

\setmathfont{NewCMMath-Regular.otf}

\begin{document}

Stay back, I'm \textit{going} to do some \textbf{science}.

\end{document}

错误

~/.config/nvim/test5.tex      0:0      W Package lualatex-math Warning: I've expected \MT_cramped_internal: Nn to have the meaning macro:#1#2-->\setbox \z@ \hbox {$\m@th #1\kern} -\nulldelimiterspace \radical \z@ {#2}$}\ifx .... "some long error, it's very long to type and I can't copy it. tell me if its needed."

~/.config/nvim/test5.tex      23:0     E Use of \??? doesn't match its definition.

~/.config/nvim/test5.tex      23:0     E Use of \??? doesn't match its definition.

~/.config/nvim/test5.tex      23:0     E Use of \??? doesn't match its definition.

~/.config/nvim/test5.tex      23:0     E Use of \??? doesn't match its definition.

~/.config/nvim/test5.tex      0:0      W Latex Font Warning: Font shape 'TU/NewCM10-Regular.otf(0)/m/it' undefined using 'TU/NewCM10-Regular.otf(0)/m/n' instead on input line 40.

答案1

,后面缺少一个ItalicFont=NewCM10-Italic.otf

% !TeX TS-program = lualatex

\documentclass[12pt]{article}

\usepackage[paperwidth=9in, paperheight=14in]{geometry}


\usepackage{graphicx}

\usepackage{amssymb}

\usepackage{amsmath}

\usepackage{amsthm}

\usepackage{empheq}

\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\usepackage{fontspec}

\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}

\setmainfont[%
ItalicFont=NewCM10-Italic.otf,%
BoldFont=NewCM10-Bold.otf,%
BoldItalicFont=NewCM10-BoldItalic.otf,%
SmallCapsFeatures={Numbers=OldStyle}
]{NewCM10-Regular.otf}
%
\setsansfont[%
ItalicFont=NewCMSans10-Oblique.otf,%
BoldFont=NewCMSans10-Bold.otf,%
BoldItalicFont=NewCMSans10-BoldOblique.otf,%
SmallCapsFeatures={Numbers=OldStyle}]{NewCMSans10-Regular.otf}

\setmonofont[ItalicFont=NewCMMono10-Italic.otf,%
BoldFont=NewCMMono10-Bold.otf,%
BoldItalicFont=NewCMMono10-BoldOblique.otf,%
SmallCapsFeatures={Numbers=OldStyle}]{NewCMMono10-Regular.otf}

\setmathfont{NewCMMath-Regular.otf}

\begin{document}

Stay back, I'm \textit{going} to do some \textbf{science}.

\end{document}

在此处输入图片描述

答案2

在你的案例中,总是查看第一个错误消息

! Use of \??? doesn't match its definition.
<argument> \???
                 ! LaTeX Error: Misplaced '=' in key-value input on line 31
l.31

这很清楚:第 31 行之前的一行缺少一个逗号。不要看 Vim 提供的简略简历:请查看日志文件。

您的代码中还有其他一些错误。不要amssymb与 一起加载unicode-math,否则只会让 TeX 做无用功(或者如果前一个包在后一个包之后加载,则会出现错误)。

fontspec如果在定义字体时使用功能,则可以节省击键次数,同时还能提高清晰度。

\documentclass[12pt]{article}
\usepackage[paperwidth=9in, paperheight=14in]{geometry}

\usepackage{fontspec}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{empheq}
%\usepackage{amssymb} % not with unicode-math
\usepackage{amsthm}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}


\setmainfont{NewCM10}[
  Extension=.otf,
  UprightFont=*-Regular,
  ItalicFont=*-Italic,% <--- was missing
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldItalic,
  SmallCapsFeatures={Numbers=OldStyle},
]

\setsansfont{NewCMSans10}[
  Extension=.otf,
  UprightFont=*-Regular,
  ItalicFont=*-Oblique,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldOblique,
  SmallCapsFeatures={Numbers=OldStyle},
]

\setmonofont{NewCMMono10}[
  Extension=.otf,
  UprightFont=*-Regular,
  ItalicFont=*-Italic,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldOblique,
  SmallCapsFeatures={Numbers=OldStyle},
]

\setmathfont{NewCMMath-Regular.otf}

\begin{document}

Stay back, I'm \textit{going} to do some \textbf{science}.

\texttt{Stay back, I'm \textit{going} to do some \textbf{science}.}

\end{document}

在此处输入图片描述

请注意,%键值选项后面的逗号是不需要的;养成在该上下文中始终添加尾随逗号的习惯。

相关内容