# Using sans font for tick labels in pgfplots

I am using a sans font for my figures. Hence I also want the tick labels of the pgfplots to be in sans. The tick labels, however, are set in a math enviroment. So changing the text font does not change anythings here. I have seen a possible solution here on tex.SE. The problem is that get many error messages like that:

! LaTeX Error: Symbol font um_fam1' not defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.23        \end{axis}


I think the problem is that a non-math font is used with unicode-math, which is not the intended use case for unicode-math. I really tried many ways to change the math font to sans, see for example here, but the essence is that a sans math font is not possible.

Since it is not possible to use a sans math font, maybe it is possible to change the pgfplots to use not an mathematical enviroment. I'm asking here, if it is possible to patch pgfplots to use an non mathematical enviroment for the tick labels? I understand this enviromnent is needed for fractions or some log scales. But I actually don't use those. So I'm fine with a solution ignoring those cases. The only important characters are digits and commas.

% !TeX program = lualatex
\documentclass{article}

\usepackage{siunitx}
\sisetup{locale = DE}

\usepackage{unicode-math}
\setmainfont[Ligatures=TeX, Numbers=OldStyle]{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
% In reality I do not use Adventor but another sans font

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\SendSettingsToPgf

\begin{document}
\begin{tikzpicture}[font=\sffamily]
\begin{axis}[xlabel=x direction, ylabel=y direction, xmin=-1, xmax=1,domain=-1:1]
\end{axis}
\end{tikzpicture}

\textsf{1,2,3,4,5,6,7,8,9,0}
\end{document}


This can be achieved using a setting in the tick label style key. By default (without getting into too much details), pgf/pgfplots uses some "\ensuremath-like" business internally when typesetting the tick labels. We can disable this by setting tick label style={/pgf/number format/assume math mode=true}. What this does is tells pgf to assume that the input is already in math mode (though it is not in this case) and that the "\ensuremath-like" function is not required. So the numbers are passed in directly and typeset in the specified \sffamily.

## Code

% !TeX program = lualatex
\documentclass{article}

\usepackage{siunitx}
\sisetup{locale = DE}

\usepackage{unicode-math}
\setmainfont[Ligatures=TeX, Numbers=OldStyle]{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
% In reality I do not use Adventor but another sans font

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\SendSettingsToPgf

\begin{document}
\begin{tikzpicture}[font=\sffamily]
\begin{axis}[%
xlabel=x direction,
ylabel=y direction,
xmin=-1, xmax=1,
domain=-1:1,
tick label style={/pgf/number format/assume math mode=true} % <=== added here
]
\end{axis}
\end{tikzpicture}

\textsf{1,2,3,4,5,6,7,8,9,0}
\end{document}


## Output

• Thanks, that was what I was looking for. The only flaw is the wrong minus sign. But I found a solution to fix this, which I will post later. – quinmars Jul 13 '14 at 18:52
• thank you, 4h I am trying to convinve the thing to do what I want. – nonsense Oct 30 '15 at 23:46

The solution of Paul Gessler works very well. The only flaw is the small minus sign. In fact it is a hypen. I found a way to circumvent this by using \num command of the siunitx package.

% !TeX program = lualatex
\documentclass{article}

\usepackage{siunitx}
\sisetup{locale = DE}

\usepackage{unicode-math}
\setmainfont[Ligatures=TeX, Numbers=OldStyle]{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
% In reality I do not use Adventor but another sans font

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\SendSettingsToPgf

% The following command will print the tick label with siunitx's \num{}
\def\myprinttick{ %
\bgroup %
\pgfmathprintnumberto{\tick}{\retval}%
\num{\retval}%
\egroup %
}

\begin{document}
\begin{tikzpicture}[font=\sffamily\sisetup{mode=text,text-rm=\sffamily}] % <- changed
\begin{axis}[xlabel=x direction, ylabel=y direction, xmin=-1, xmax=1,
domain=-1:1,
tick label style={/pgf/number format/assume math mode=true}, % from Paul Gessler
`