.png)
我正在嘗試為任何處理電磁學的人解決 LaTeX 中的一個經典問題:定義 Griffiths 的 script-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}
查看格里菲斯 zip 文件http://academic.reed.edu/physicals/faculty/griffiths/script_r.zip, 透過Script-r 符號
(2)
下一個最簡單的方法是使用其中一個\math...
函數(此處為\mathord
):在 XeTeX 中使用 \Umathchardef 定義可變大小的數學符號透過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
使用傳統字體技術。可以透過套件為它們指派 NFSS 別名fontspec
(因此 xelatex 或 lualatex 作為編譯器)來使用 ttf\otf 字體,然後根據連結的問題執行多個步驟。
選項是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 (