I want to use a different math font in figures (namely tikzpictures). I already asked a question about this topic where I tried to mix mathspec
and unicode-math
. Now after some reseach I realized that mathspec
does not allow to switch the font at all and I should use only unicode-math
.
But there I also get build errors in my MWE (or should I say MnWE, because it does not work):
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\newcommand{\rmmath}{\setmathfont{TeX Gyre Pagella Math}}
\rmmath
\setsansfont[Scale=MatchUppercase]{Candara}
\newcommand{\sfmath}{ %
\setmathfont{TeX Gyre Pagella Math} %
\setmathfont[range=\mathup, Numbers=Lining, Scale=MatchUppercase]{Candara} %
\setmathfont[range=\mathit, Scale=MatchUppercase]{Candara Italic} %
\setmathfont[range=\mathbf, Scale=MatchUppercase]{Candara Bold} %
}
\BeforeBeginEnvironment{tikzpicture}{\sfmath}
\AfterEndEnvironment{tikzpicture}{\rmmath}
\begin{document}
% This would work, but I actually do not need sans math in running text
% \sfmath $I$
% \rmmath $I$
% \sfmath $I$
% \rmmath $I$
% \sfmath $I$
% \rmmath $I$
% \sfmath $I$
% \rmmath $I$
Text $I$
\begin{figure}
\begin{tikzpicture}
\node {Node: $I$};
\end{tikzpicture}
\caption{Caption text with math $I$}
\end{figure}
Text
% If you remove the following lines it will compile
\begin{figure}
\begin{tikzpicture}
\node {Node: $I$};
\end{tikzpicture}
\caption{with math $I$}
\end{figure}
\end{document}
Some interesting notes: if I remove the figure
environment, i.e. only use tikzpicture
it will build. If I use center
instead of figure
it also does not work. Funnily enough, if I have only one figure it will build.
The first error I get:
.................................................
. fontspec info: "defining-font"
.
. Font family 'Candara(1)' created for font 'Candara' with options
. [BoldItalicFont={},ItalicFont={},Script=Math,SizeFeatures={{Size=10-},{Size=7
.40005-10,Font=Candara,Style=MathScript},{Size=-7.40005,Font=Candara,Style=Math
ScriptScript}},Numbers={Lining},Scale={MatchUppercase}].
.
. This font family consists of the following shapes:
.................................................
! LaTeX Error: Symbol font `um_fam1' not defined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.43 ^^I\begin{tikzpicture}
Your command was ignored.
version
option and\mathversion
would be the best, unfortunately theversion
option does not work withrange
.