Preface:
An axis plotted with pgfplots is usually using the current math font for its ticklabels. But if they are overwritten by e.g. xticklabels={-8,-6,...,8} then the current text font is used. Also an axis label ylabel={Y} would be in text font unless put explicitly in math mode ylabel={$Y$}. However it would be nice, if one hadn't to do so.
Question:
I'm aiming to ensure that pgfplots always uses the current math font. But please assume that the classic font commands like \rmfamily are screwed up by the corporate design I'm supposed to use, e.g. assume: \renewcommand{\rmdefault}{\sfdefault}
It works if I explicitly define a font
\newcommand{\pgfmathfont}{\fontfamily{pxfonts}\selectfont}
and pass it to pgfplots together with assume math mode=true:
\begin{axis}[
font = \pgfmathfont,
tick label style={/pgf/number format/assume math mode=true}
]
But it requires that I insert the name of the current math font. How can I do that automatically? How to get the currently used math font to insert it into the macro?
MWE
\documentclass{beamer}
\usetheme{Warsaw}
\usefonttheme{professionalfonts}
\usepackage{pxfonts}
\usepackage{pgfplots}
% screwed up by Corporate Design
\renewcommand{\rmdefault}{\sfdefault}
% I'd like this line to be generic!
\newcommand{\pgfmathfont}{\fontfamily{pxfonts}\selectfont}
% put current math font here X
\begin{document}
\begin{frame}
This is a basic equation:
\[ x + y = 42\]
\begin{tikzpicture}
\begin{axis}[
% font = \rmfamily, % makes no sense here
font = \pgfmathfont,
xlabel={$x$-label: I want to be in math font!},
ylabel={Y},
xtick={-4,-3,...,4},
xticklabels={-8,-6,...,8},
% xticklabels={$-8$,$-6$,...,$8$}, % does not work
tick label style={/pgf/number format/assume math mode=true}
]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
Everything related to fontspec is no option at all!
Thank you!



xticklabels={$-8$,$-6$,$...$,$8$}to make it work. (notice the dollar signs around the ellipsis...) – percusse Dec 04 '15 at 08:10$...$! Well I'm aware that if in my example above probably the text shape of pfxonts is used and not the math shape. But in my above example pgfplots usespxfontsby default, until the labels are overwritten, then it changes to the beamer font used for text. So in this particular case it should be possible to determine what font is loaded (if not pxfonts) which then is used by pgfplots and should be used also in thefont = ...key? – Robert Seifert Dec 04 '15 at 08:43\newcommand{\pgfmathfont}{\fontfamily{\the\font}\selectfont}to work, but I get aMissing \endcsname inserted. \end{frame}error. Any idea on that? Coudl you may try make it an answer for the MWE? – Robert Seifert Dec 04 '15 at 11:09