我正在尝试为任何与电磁学打交道的人解决 LaTeX 中的一个经典问题:定义格里菲斯的脚本-r 符号。这次,我想使用他书中使用的实际 Kaufmann 字体来完成此操作,并且我已经设法获取了文件。虽然在 LuaLaTeX 中可以很容易地“自由”使用字体,但我想定义一个使用它的数学符号,以便代码可以与我使用的其他软件包很好地配合使用,例如由physics
。
看完之后这个答案在有关通用 script-r 问题的帖子上,我试图通过命令实现 script-r 符号\DeclareMathSymbol
,但我不明白如何在其中使用 Kaufmann 字体。
简而言之:我有两个.ttf
字体文件Kaufmann-Regular.ttf
和Kaufmann-Bold.ttf
。如何使用它们来定义\rcurs
使用 Kaufmann 字体的数学符号,以便像命令这样的命令\mathbf{\rcurs}
返回其粗体版本?
答案1
数学字母和运算符形成一个集合,因此混合搭配通常需要不同类型的低级调整。
话虽如此,导入符号有多种方式和方法。
(1)
最简单的方法是将字形作为图像\PDF 包含进来,并在需要时调整大小等,就像 Griffiths 所做的那样:
代码:
\documentclass{report}
\usepackage{graphicx}
\def\rcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{ScriptR}}$}}}
\def\brcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{BoldR}}$}}}
\def\hrcurs{{\mbox{$\hat \brcurs$}}}
\begin{document}
Here's a sample:
$\resizebox{.16in}{.08in}{\includegraphics{BoldR}}$
Can I put it into a line of type? $\resizebox{.21in}{.11in}{\includegraphics{BoldR}}$
How about using the macro: \brcurs.
How about using the macro: \rcurs?
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
{\bf E} = {1\over 4\pi\epsilon_0}\int {\rho\over \rcurs^2}{\hrcurs}\,d\tau.
\end{equation}
\end{document}
查看 Griffiths zip 文件http://academic.reed.edu/physics/faculty/griffiths/script_r.zip, 通过Script-r 符号
(2)
其次最简单的方法是使用以下\math...
函数之一(此处为\mathord
):使用 \Umathchardef 在 XeTeX 中定义可变大小的数学符号通过LuaTeX:在数学模式下使用其他字体的单个符号
以下是列表:
(texdoc 源2e)
平均能量损失
\documentclass{report}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmathfont{Asana-Math}
\newfontfamily{\miama}{Miama}[Colour=red,
Scale=1.3,
Path=C:/Users/.../tl/texlive/2020/texmf-dist/fonts/opentype/public/miama/,
Extension=.otf,
UprightFont=*,
]
\DeclareRobustCommand\mysym{%
\mathord{\text{\normalfont\miama r}}%
}
%\def\rcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{ScriptR}}$}}}
%\def\brcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{BoldR}}$}}}
%\def\hrcurs{{\mbox{$\hat \brcurs$}}}
\def\hrcurs{{\mbox{$\hat\mbfscrr$}}}
\begin{document}
\fbox{Asana-Math: $\mbfscrr, \mscrr $}
Here's a sample:
$\mbfscrr$
Can I put it into a line of type? $\mbfscrr$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mscrr^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\renewcommand\mbfscrr{{\mysym}}
\def\hrcurs{{\mbox{$\hat\mbfscrr$}}}
\bigskip
\fbox{Miama: $\mysym$}
Here's a sample:
$\mysym$
Can I put it into a line of type? $\mysym$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mscrr^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\end{document}
(2a)
要正确调整重音,需要进行字距调整等。这里,一种不同的非数学字体避免了这个问题:
平均能量损失
\documentclass{report}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmathfont{Asana-Math}
\newfontfamily{\gfs}{GFSBodoni}[Colour=red,
Scale=1.3,
Path=C:/Users/.../tl/texlive/2020/texmf-dist/fonts/opentype/public/gfsbodoni/,
Extension=.otf,
UprightFont=*,
ItalicFont=GFSBodoniIt,
BoldFont=GFSBodoniBold,
BoldItalicFont=GFSBodoniBoldIt,
]
\DeclareRobustCommand\mysymbi{%
\mathord{\text{\normalfont\gfs\bfseries\itshape r}}%
}
\DeclareRobustCommand\mysym{%
\mathord{\text{\normalfont\gfs\itshape r}}%
}
\def\hrcurs{{\mbox{$\hat\mbfscrr$}}}
\begin{document}
\fbox{Asana-Math: $\mbfscrr, \mscrr $}
Here's a sample:
$\mbfscrr$
Can I put it into a line of type? $\mbfscrr$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mscrr^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\renewcommand\mbfscrr{{\mysymbi}}
\def\hrcurs{{\mbox{$\hat\mbfscrr$}}}
\bigskip
\fbox{GFS Bodoni: $\mysymbi, \mysym$}
Here's a sample:
$\mysym$
Can I put it into a line of type? $\mysym$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mysym^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\end{document}
(3)
接下来,使用unicode-math
包的range=
字体选项进行映射。
从 Unicode 数学字体映射:
平均能量损失
\documentclass{report}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmathfont{Asana-Math}
\def\hrcurs{{\mbox{$\hat\mbfscrr$}}}
\begin{document}
\fbox{Asana-Math: $\mbfscrr,\mscrr$}
Here's a sample:
$\mbfscrr$
Can I put it into a line of type? $\mbfscrr$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mscrr^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\setmathfont{TexGyreSchola-Math}[range={\mbfscrr,\mscrr},Colour=red]
\bigskip
\fbox{TexGyreSchola-Math: $\mbfscrr,\mscrr$}
Here's a sample:
$\mbfscrr$
Can I put it into a line of type? $\mbfscrr$
How about using the macro: \hrcurs?
What if it's in an equation?
\begin{equation}
\symbf{E} = {1\over 4\mitpi\mitepsilon_0}\int {\mitrho\over \mscrr^2}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\end{document}
(4)
\DeclareMathSymbol
使用传统字体技术。可以通过包(因此 xelatex 或 lualatex 作为编译器)为 ttf\otf 字体分配一个 NFSS 别名fontspec
,然后根据链接的问题执行多个步骤来使用。
该选项是NFSSFamily=
。
示例使用QTFloraline
字体(在 tex 分布中)L,它有常规字体和粗体字体。请用您的 kaufmann 文件替换。
平均能量损失
\documentclass{article}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmathfont{Asana-Math}
\newfontface\ffontc{QTFloraline}[
Extension=.otf,
UprightFont=*,
BoldFont=*-Bold,
NFSSFamily=floraline,
]
\usepackage{bm}
\DeclareFontFamily{U}{floraline}{}
\DeclareFontShape{U}{floraline}{m}{n}{<-> QTFloraline}{}
\DeclareFontShape{U}{floraline}{b}{n}{<-> QTFloraline-Bold}{}
\DeclareSymbolFont{myfloraline}{U}{floraline}{m}{n}
\SetSymbolFont{myfloraline}{bold}{U}{floraline}{b}{n}
\DeclareMathSymbol{\rcurs}{\mathalpha}{myfloraline}{`\r}
\DeclareBoldMathCommand{\brcurs}{\rcurs}
\newcommand*\hrcurs{\hat{\brcurs}}
\begin{document}
\[
\mathbf{E}(\mathbf{r}) = \frac{1}{4 \pi \epsilon_0} \int\limits_{\mathcal{V}} \frac{\rho(\mathbf{r}')}{\rcurs^2} \hrcurs d \tau'
\]
Using \texttt{unicode-math} macros:
\[
\symbfup{E}(\symbfup{r}) = \frac{1}{4 \mitpi \mitepsilon_0} \int\limits_{\symcal{V}} \frac{\mitrho(\symbfup{r}')}{\rcurs^2} \hrcurs d \mittau'
\]
\end{document}
(5)
对于一两个符号来说,该\mathord{}
方法更简单,并且也不会用尽整个数学字母表。
事实证明,unicode-math
定义了两个宏,\mbfscrr
和\mscrr
。这些可以renewcommand
通过重新定义()\mathord
,就是这样。
代码逐步完成需要更改的各个阶段,说明每个结果,并使用QTChanceryType
字体达到最后一步:
平均能量损失
\documentclass{report}
\usepackage{xcolor}
\usepackage{unicode-math}
\setmathfont{Asana-Math}
\newfontface\bodb{BOD_BLAR.TTF}[Colour=red]
\newfontface\ffontbreg{QTChanceryType.otf}
\newfontface\ffontbbold{QTChanceryType-Bold.otf}
\DeclareRobustCommand\xmbfscrr{%
\mathord{\text{\normalfont\bodb A}}%
}
\DeclareRobustCommand\myscrr{%
\mathord{\text{\normalfont\ffontbreg r}}%
}
\DeclareRobustCommand\mybfscrr{%
\mathord{\text{\normalfont\ffontbbold r}}%
}
\begin{document}
%======================: 0: base
\fbox{Asana-Math: $\mbfscrr,\mscrr$}
\begin{equation}
\symbfup{E} = {\frac{1}{4\mitpi\mitepsilon_0}}\int {\frac{\mitrho}{\mscrr^2}}{\hat\mbfscrr}\,d\mittau.
\end{equation}
%======================: 1: A
\renewcommand{\mbfscrr}{A}
\bigskip
\begin{equation}
\symbfup{E} = {\frac{1}{4\mitpi\mitepsilon_0}}\int {\frac{\mitrho}{\mscrr^2}}{\hat\mbfscrr}\,d\mittau.
\end{equation}
%======================: 2: A from another font
\renewcommand{\mbfscrr}{{\xmbfscrr}}
\bigskip
\begin{equation}
\symbfup{E} = {\frac{1}{4\mitpi\mitepsilon_0}}\int {\frac{\mitrho}{\mscrr^2}}{\hat\mbfscrr}\,d\mittau.
\end{equation}
%======================: 3: r and bold r, from another font
\renewcommand{\mbfscrr}{{\mybfscrr}}
\renewcommand{\mscrr}{{\myscrr}}
\bigskip
\begin{equation}
\symbfup{E} = {\frac{1}{4\mitpi\mitepsilon_0}}\int {\frac{\mitrho}{\mscrr^2}}{\hat\mbfscrr}\,d\mittau.
\end{equation}
\end{document}
附录
为了避免歧义,就字体而言,文本模式和数学模式是完全不同的世界。
斜体 x (