4

At the moment I am experimenting with a sans-serif font for figures and a serif font for the rest of the document. When compiling this MWE with pdflatex everything seems to work smoothly. Switching to lualatex (on Texlive 2014) leads to error messages (Font shape OT1/ClearSans(0)/m/sl undefined) that some characters cannot be found and they are replaced by the standard serif font.

Why is the font handling different in this case and how can I fix this?

\documentclass{article}

\usepackage{pgfplots}

\usepackage{ClearSans}

\usepackage[eulergreek]{sansmath}

\pgfplotsset{
    tick label style = {font=\sansmath\sffamily},
    every axis label = {font=\sansmath\sffamily},
    legend style = {font=\sansmath\sffamily},
    label style = {font=\sansmath\sffamily},
    /tikz/font=\sansmath\sffamily
}

\begin{document}

\begin{figure}
    \begin{sansmath}
        \begin{tikzpicture}
                \begin{axis}
                        \addplot [blue] coordinates { (0,0) (1,2) };
                \end{axis}
                \node at (4, 1) { $\Delta T_{\mathrm S} + 25 + \alpha + \beta + a^2$};
                \node at (2, 5) {normal sans serif text};
        \end{tikzpicture} 
    \end{sansmath}
\caption{Some caption text.}
\end{figure}


text text text...

\begin{equation}
a^2 + b^2 = c^2
\end{equation}

\end{document}
  • Did you forget something in your question title? – Stephan Lehmke Jun 27 '14 at 14:25
  • "Why is the font handling different in this case and how can I fix this?" Tautological answer: because lualatex and pdflatex handle font in different ways. You can see tex.stackexchange.com/questions/13593/… for some more details (not a dupe). [This comment is less relevant now that your title is complete, I'm afraid] – T. Verron Jun 27 '14 at 14:27
  • @StephanLehmke: Thanks, that last bit got lost somehow before saving. – Alexander Jun 27 '14 at 14:27
  • @egreg: That almost solves it, now the numbers are sans-serif but in italics. – Alexander Jun 27 '14 at 14:34
3

The sansmath does

\providecommand\sansmathencoding{OT1}

at the beginning; this can so be overridden by adding

\newcommand\sansmathencoding{\encodingdefault}

before loading the package. You also must ensure that fontspec doesn't hijack math codes and fix another setting where sansmath hardwires OT1. For uppercase Greek, EULERGREEK is needed.

\documentclass{article}

\usepackage{pgfplots}
\usepackage[no-math]{fontspec}
\usepackage{ClearSans}

\newcommand{\sansmathencoding}{\encodingdefault}
\usepackage[EULERGREEK]{sansmath}
\SetSymbolFont{operators}{sans}{\encodingdefault}{\sfdefault}{m}{n}

\pgfplotsset{
    tick label style = {font=\sansmath\sffamily},
    every axis label = {font=\sansmath\sffamily},
    legend style = {font=\sansmath\sffamily},
    label style = {font=\sansmath\sffamily},
    /tikz/font=\sansmath\sffamily
}

\begin{document}

\begin{figure}
\centering
\begin{sansmath}
\begin{tikzpicture}
\begin{axis}
  \addplot [blue] coordinates { (0,0) (1,2) };
\end{axis}
\node at (4, 1) { $\Delta T_{\mathrm{S}} + 25 + \alpha + \beta + a^2$};
\node at (2, 5) {normal sans serif text};
\end{tikzpicture} 
\end{sansmath}
\caption{Some caption text with math $\Delta T_{\mathrm{S}} + 25 + \alpha + \beta + a^2$.}
\end{figure}


text text text...

\begin{equation}
a^2 + b^2 = c^2
\end{equation}

\end{document}

enter image description here

I really can't understand why graphs with sans serif type are so fashionable.

  • This is great, thank you. It is not so much fashion but more or less a universal style convention in many scientific journals. I have no strong feelings about the issue but when combining different graphs from other sources it is much nicer if they have common typesetting. – Alexander Jun 27 '14 at 15:12
  • 1
    @Alexander Is it a convention? Or is it just that they include a figure which came from a different program so they cannot use (they don't know) the font used in the document? I always thought it was the second option. – Manuel Jun 27 '14 at 15:31
  • @Manuel That's my impression, too. – egreg Jun 27 '14 at 15:38
  • @Manuel, egreg: Taken from the Authors guide for figures of Science: "Use a sans-serif font whenever possible (we prefer Helvetica)." – Alexander Jun 27 '14 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.