我打算对大部分文本(包括标题)使用衬线字体(TG Pagella),对我的(tikz)图形使用无衬线字体(Candara)。对于文本,这很好用,但对于数学则不行。首先,我仅使用unicode-math
键version
通过 切换到 sans 版本\mathversion{...}
。问题是unicode-math
需要 otf 数学字体,而 Candara 不存在这种字体。使用普通的 Candara 字体会导致数学直立,但我希望它是斜体。使用斜体字体,数学中的所有内容都变成斜体偶数。
所以接下来我尝试使用 mathspecs。在那里,sans math 工作得很好。问题是我不知道如何在 sans 和 serif 之间切换,因为没有version
选项\setmathsfont
,\setmathsfont
只能从序言中调用。所以我只使用了version
Pagella 的键并尝试通过切换到 sans 字体,\mathversion{normal}
但这并没有真正起作用。不知何故,数学字体总是 Candara(见下文)。
有没有什么办法可以完成这项工作?
\documentclass[a5paper]{memoir}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.8}
\usepackage{mathspec}
\usepackage{unicode-math}
\setmainfont[Numbers=OldStyle]{TeX Gyre Pagella}
\setmathfont[version=tgp]{TeX Gyre Pagella Math}
\setsansfont[Scale=MatchUppercase]{Candara}
\setmathsfont(Digits,Latin,Greek)[Scale=MatchUppercase]{Candara}
\usepackage{siunitx}
\SendSettingsToPgf
\tikzstyle{every picture}+=[font=\small\sffamily,
execute at begin picture=\mathversion{normal}
]
\pgfplotsset{unit code/.code 2 args={
\sisetup{detect-family}
\si{#1#2}}}
\pgfplotsset{general plot/.style={
xtick pos=left,
ytick pos=left,
enlarge x limits=false,
minor x tick num=1,
every x tick/.style={color=black, thin},
every y tick/.style={color=black, thin},
tick align=outside,
xlabel near ticks,
ylabel near ticks,
unit markings=parenthesis
}
}
\usepackage{blindtext}
\parindent=0pt
\mathversion{tgp}
\begin{document}
$V_{\textup{DS}}$ in \si{V}\\
1234567890\\
\textsf{1234567890}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
general plot,
xlabel=Voltage $V_{\text{DS}}$,
x unit=\volt,
change y base=true,
y SI prefix=micro,
ylabel=Current $I$,
y unit=\ampere]
\addplot {1.3E-6*x};
\end{axis}
\end{tikzpicture}
\caption{The current $I$ in \si{\micro\ampere} versus the voltage $V_\textup{DS}$ in \si{\volt}}
\end{figure}
\end{document}
编辑:根据 Khaled Hosny 的评论,我尝试仅使用unicode-math
。有一个问题,该range
选项不适用于version
-tagged 字体。所以我创建了两个命令来在设置之间切换。事实上,这对于正文中的数学运算很有效。但如果我将它们与 tikz 键结合使用,execute at begin picture
我会得到构建错误:
I can only handle fonts at positive sizes that are
less than 2048pt, so I've changed what you said to 10pt.
LaTeX Font Info: Font shape `EU1/CandaraItalic(0)/m/n' will be
(Font) scaled to size 0.0pt on input line 57.
! Improper `at' size (0.0pt), replaced by 10pt.
<to be read again>
relax
l.57 ^^I^^I^^I\end{axis}
另一条错误消息是:
*************************************************
* fontspec warning: "script-not-exist-latn"
*
* Font 'Candara' does not contain script 'Math'.
* 'Latin' script used instead.
*************************************************
! Font \nullfont has only 7 fontdimen parameters.
<recently read> \font
下面是源代码:
\documentclass[a5paper]{memoir}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.8}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\newcommand{\rmmath}{\setmathfont{TeX Gyre Pagella Math}}
\rmmath
\setsansfont[Scale=MatchUppercase]{Candara}
\newcommand{\sfmath}{
\setmathfont[Numbers=Lining, Scale=MatchUppercase]{Candara}
\setmathfont[range=\mathit, Scale=MatchUppercase]{Candara Italic}
}
\usepackage{siunitx}
\sisetup{detect-family}
\SendSettingsToPgf
\tikzstyle{every picture}+=[font=\small\sffamily,
% This does not compile:
execute at begin picture=\sfmath,
execute at end picture=\rmmath
]
\pgfplotsset{unit code/.code 2 args={
\si{#1#2}}}
\pgfplotsset{general plot/.style={
xtick pos=left,
ytick pos=left,
enlarge x limits=false,
minor x tick num=1,
every x tick/.style={color=black, thin},
every y tick/.style={color=black, thin},
tick align=outside,
xlabel near ticks,
ylabel near ticks,
unit markings=parenthesis
}
}
\parindent=0pt
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
general plot,
xlabel=Voltage $V_{\text{DS}}$,
x unit=\volt,
change y base=true,
y SI prefix=micro,
ylabel=Current $I$,
y unit=\ampere]
\addplot {1.3E-6*x};
\end{axis}
\end{tikzpicture}
\caption{The current $I$ in \si{\micro\ampere} versus the voltage $V_\textup{DS}$ in \si{\volt}}
\end{figure}
{\sffamily V \sfmath $5 V_{\mathrm{DS}}$ in \si{V}}\\
V \rmmath $5 V_{\textup{DS}}$ in \si{V}\\
\end{document}