For my current document I want to use a normal serif font for the main text. Most diagrams from other sources and myself are with sans serif fonts (TeX Gyre Heros). Now I want to use pgfplots
to create
figures using these fonts but keep the math in the main text in the normal font. Something similar has been achieved with sansmath
here but this does not switch to completely different font, as I am trying here. I thought with unicode-math
I can switch back and forth easily but the switching back part fails.
My MWE looks as follows:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\begin{document}
\begin{figure}
\sffamily
\setmathfont{TeX Gyre Heros}
\setmathfont[range=\mathit/{latin, Latin, greek, Greek}]{texgyreheros-italic.otf}
\begin{tikzpicture}
\begin{axis}
\addplot [blue] coordinates { (0,0) (1,2) };
\end{axis}
\node at (4, 1) { $\Delta T_{\mathrm S}$};
\node at (2, 5) {normal sans serif text};
\end{tikzpicture}
\rmfamily
\setmathfont{Latin Modern Math}
\caption{Some caption text.}
\end{figure}
Normal text in Latin Modern Roman here but math fails unless the next line is used.
%\setmathfont{Latin Modern Math}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\end{document}
and gives the following output:
Thank you for any hints, why the switching back fails and comments in general how this might be improved.
\rmfamily\setmathfont{Latin Modern Math}
after thefigure
environment. Does it helps?