我正在尝试使用\fontfamily
命令为文档中的特定内容插入特定类型的字体。此外,使用该命令\renewcommand{\ttdefault}{<Font Name>}
似乎也不起作用。这些命令相对简单,我基本上只想更改字体系列。这可能是由于我的某些软件包存在兼容性问题吗?
以下是我得到的结果示例:
我的源代码:
\documentclass[12pt]{book}
% !TeX program = xelatex
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\setmainfont{TeX Gyre Adventor}
\newcommand*{\myfont}{\fontfamily{Courier}\selectfont}
\renewcommand{\ttdefault}{Courier}
\usepackage{amsmath}
\usepackage{amssymb, amsfonts}
\usepackage[Omega]{gensymb}
\usepackage[]{mathtools}
\usepackage{cuted}
\usepackage[thicklines]{cancel}
\usepackage{float}
\usepackage[]{rotating}
\usepackage{subfloat}
\usepackage{cleveref}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage[flushleft]{threeparttable}
\usepackage{colortbl}
\usepackage{comment}
\usepackage{pifont}
\usepackage[pointedenum]{paralist}
\usepackage[autostyle, english = american]{csquotes}
\usepackage{embrac}
\usepackage[perpage, multiple, stable]{footmisc}
\usepackage{marginnote}
\usepackage[svgnames]{xcolor}
\usepackage{soul}
\usepackage[normalem]{ulem}
\usepackage{blindtext}
\usepackage{environ}
\usepackage{bigfoot}
\usepackage[]{matlab-prettifier}
\newcommand*\pct{\scalebox{0.7}{\hspace{0.5mm}$\%$}}
\newcommand*\note{\scalebox{0.35}{$0$}}
\setcounter{chapter}{1}
\usepackage[nodayofweek]{datetime}
\renewcommand{\timeseparator}{:}
\renewcommand{\amname}{ AM}
\renewcommand{\pmname}{ PM}
\settimeformat{ampmtime}
\renewcommand{\dateseparator}{/}
\newdateformat{usvardate}{\monthname[\THEMONTH] \ordinaldate{\THEDAY}, \THEYEAR}
\usvardate
\begin{document}
\centering \section*{ECE 331 - Exam 1 Pitfall Notes}
\textbf{\today \mbox{ }- \currenttime}
\justify
\texttt{Note that typewriter command $\backslash$texttt does not really change the font}
{\myfont This text is also supposed to be in Courier format}
OK guys. In what follows, I will provide you with a some notes about your pitfalls, why they are pitfalls and how to avoid or rectify them.
\paragraph{Area Conversion.} I \strong{noted that many} of you make mistakes when converting from $cm^{2}$ to $m^{2}$. When doing conversion of areas from one unit to another, the original unit is scaled \emph{twice}. Hence, converting from $cm^{2}$ to $m^{2}$ requires that you divide over $100$ two times. For instance, $30 \thickspace cm^{2} = \frac{30}{100\times100} \thickspace m^{2} \Rightarrow 30 \thickspace cm^{2} = 0.003 \thickspace m^{2}$.
\paragraph{Neglecting Air Gap in Iron Cores.} The relative permeability of iron can be thousands of times that of air ($\mu_{r} = 2000-100,000$), which means that the reluctance of the air gap $\displaystyle \mathcal{R}_{g} = \frac{l_{g}}{\mu_{\note} A_{g}}$ would be much more than the reluctance of the core $\displaystyle \mathcal{R}_{c} = \frac{l_{c}}{\mu_{r}\mu_{\note} A_{c}}$. Hence, significant error would definitely result in if you did not take into account the air gap in magnetic~circuits.
\vfill
\textit{\Large All the best,}
\vspace{2mm}
\emph{\Large Al-Motasem Aldaoudeyeh}
\end{document}
答案1
您不能使用任意名称作为字体系列。必须先声明它们。使用 fontspec 时,您可以使用 来执行此操作NFSSFamily
,但也可以简单地定义新的字体系列。
\documentclass[12pt]{book}
\usepackage{fontspec}
\setmainfont{TeX Gyre Adventor}
\setmonofont{TeX Gyre Cursor}
\newfontfamily\verbatimfont{DejaVu Sans Mono}[NFSSFamily=dejamono]
\begin{document}
standard text
{\ttfamily courier}
{\fontfamily{dejamono}\selectfont DejaVu Sans Mono} is then equivalent to
{\verbatimfont DejaVu}
\end{document}