在我的博士论文中,正文是 Times 字体,而我的所有图表(及其标题)都使用 Helvetica 字体。我创建了以下 MWE,展示了如何在正文和图表之间切换 Times 和 Helvetica。我目前的问题是,我没有一种自动的方法将所有大写希腊字母设置为非斜体。所有其他数学符号(小写和大写罗马字母)都应使用斜体。这是我所在领域的惯例。
我现在唯一的解决方法是在文档中每个大写希腊字母前添加一个 \mathrm。
\documentclass[11pt]{report}
\usepackage{tgheros,textcomp}
\usepackage{mathptmx}
\usepackage{sansmath} % sans serif math
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{float}
\usepackage[labelfont=bf, font={small,sf}]{caption}
% Credit: https://tex.stackexchange.com/a/444408/61268
\usepackage{etoolbox} % nice command patching
\usepackage{everyhook} % nice \every... patching
% restyle figures to make \everymath=\sansmath (float package)
\restylefloat{figure}
\floatevery{figure}{\PushPreHook{math}{\sansmath}}
% undo the change to \everymath at the end of the figure (etoolbox)
\apptocmd{\endfigure}{\PopPreHook{math}}{}{}
\tikzset{font=\sffamily\small}
\usepackage{import}
\begin{document}
Main text is in Times. Works without a problem.
\begin{equation}
\Delta\Omega(t)
\end{equation}
My problem is in the figures, which I usually typeset using Ti\emph{k}z
\begin{figure}[H]
\centering
\begin{tikzpicture}
\node[draw] at (0, 0) {Helvetica Equation: $\Delta\Omega(t)$};
\end{tikzpicture}
\caption{Captions are in Helvetica. $\Delta\Omega(t)$}
\end{figure}
I found that I can get a fix if I manually put a {\textbackslash}mathrm around all of my capital Greek letters, but I would like to find a way for this to automatically be done.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\node[draw] at (0, 0) {{\textbackslash}mathrm: $\mathrm{\Delta\Omega}(t)$};
\end{tikzpicture}
\caption{I can fix with {\textbackslash}mathrm... $\mathrm{\Delta\Omega}(t)$}
\end{figure}
\end{document}
答案1
如果您可以使用 LuaLaTeX 或 XeLaTeX,则可以使用 来执行此操作unicode-math
。
但是,强制直立无衬线希腊文的命令是\symsfup
,而不是\mathrm
。
\Delta\Omega
或者,输入而不是\increment\mupOmega
。这样您就可以使用\mathrm
字体中的直立希腊字母来表示version=sans
。
\documentclass[11pt]{report}
\tracinglostchars=2
\usepackage[math-style=TeX]{unicode-math}
\usepackage{tikz}
\usepackage{float}
\usepackage[labelfont=bf, font={small,sf}]{caption}
\defaultfontfeatures{ Scale = MatchLowercase, Ligatures=TeX }
\setmainfont{TeX Gyre Termes}[Scale=1.0]
\setsansfont{TeX Gyre Heros}
\setmathfont{TeX Gyre Termes Math}
\setmathfont{KPMath-Sans.otf}[version=sans]
\setmathfontface\mathrm{TeX Gyre Termes Math}
\setmathfontface\mathrm{TeX Gyre Heros}[version=sans]
\newcommand\sansmath{\mathversion{sans}}
% Credit: https://tex.stackexchange.com/a/444408/61268
\usepackage{etoolbox} % nice command patching
\usepackage{everyhook} % nice \every... patching
% restyle figures to make \everymath=\sansmath (float package)
\restylefloat{figure}
\floatevery{figure}{\PushPreHook{math}{\sansmath}}
% undo the change to \everymath at the end of the figure (etoolbox)
\apptocmd{\endfigure}{\PopPreHook{math}}{}{}
\tikzset{font=\sffamily\small\sansmath}
\usepackage{import}
\begin{document}
Main text is in Times. Works without a problem.
\begin{equation}
\Delta\Omega(t)
\end{equation}
My problem is in the figures, which I usually typeset using Ti\emph{k}z
\begin{figure}[H]
\centering
\begin{tikzpicture}
\node[draw] at (0, 0) {KPMath-Sans Equation: $\Delta\Omega(t)$};
\end{tikzpicture}
\caption{Captions are in Helvetica. $\Delta\Omega(t)$}
\end{figure}
I found that I can get a fix if I manually put a {\textbackslash}mathrm around all of my capital Greek letters, but I would like to find a way for this to automatically be done.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\node[draw] at (0, 0) {{\textbackslash}symsfup: $\symsfup{\Delta\Omega}(t)$};
\end{tikzpicture}
\caption{I can fix with {\textbackslash}symsfup... $\symsfup{\Delta\Omega}(t)$}
\end{figure}
While {\textbackslash}mathrm does not allow {\textbackslash}Delta{\textbackslash}Omega with this configuration,
\(\mathrm{\increment\mupOmega}\) works.
我对您用来设置要使用的标题的复制代码非常怀疑\sansmath
,因为它警告我该命令在数学模式下无效。