3

I applied sans-serif font both in text and math, but then I got the problem with \hat. How to solve it?

Here is a MWE:

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage[scaled]{helvet} %... sets helvet as text font
    \renewcommand{\familydefault}{\sfdefault}
\usepackage{fouriernc}      %... controls math fonts
\usepackage[helvet]{sfmath} %... sets helvet to math fonts
\usepackage{isomath}        %... handles mathrm to match text font (?)

\usepackage{siunitx}

\title{Applying sans-serif font to text and math}


\begin{document}
\maketitle

The equation is
\[
    \mathbf{E} = E \hat{r}.
\]


\end{document}

enter image description here

5 Answers 5

6

General comments

Let's examine your comments to the code.

helvet

\usepackage[scaled]{helvet} %... sets helvet as text font
    \renewcommand{\familydefault}{\sfdefault}

Yes, this makes Helvetica (actually a clone thereof) as the main text font.

fouriernc

\usepackage{fouriernc}      %... controls math fonts

No, this doesn't “control” math fonts: the package chooses a set of math fonts based on New Century Schoolbook. Since you aim to sans serif math, why loading a serif math font?

sfmath

\usepackage[helvet]{sfmath} %... sets helvet to math fonts

OK, this almost does what you claim.

isomath

\usepackage{isomath}        %... handles mathrm to match text font (?)

No, the package sets up math fonts so that they conform to the infamous ISO regulation about mathematics (that basically no mathematician sticks to).

Specific problems

The package fouriernc uses a very peculiar set of encodings for math fonts and it should never be loaded along other font packages that deal with math fonts.

Poor typesetting

Let's remove the problematic packages and try with some more complex math formulas.

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage[scaled]{helvet} %... sets helvet as text font
\usepackage[helvet]{sfmath} %... sets helvet to math fonts
\usepackage{isomath}        %... ISO 89000 conventions
\usepackage{siunitx}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}

The equation is
\[
\mathbf{E} = E \hat{r}.
\]
Let's try Greek $\alpha+\beta$ and a more complex formula
\[
\int_{-\infty}^{+\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]
A quantity is \qty{3.14}{\centi\meter}

\end{document}

enter image description here

As you see, the typesetting of math is rather poor quality: the Greek letters are in Computer Modern and are very far from being “sans serif”. Similarly for the integral sign and the infinity symbols.

A slightly better output is obtained with newtxsf.

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage[scaled]{helvet} %... sets helvet as text font
\usepackage{newtxsf} %... sans serif math symbols
\usepackage{siunitx}

\renewcommand{\familydefault}{\sfdefault}
\DeclareSymbolFont{upright}{OT1}{\familydefault}{m}{n}
\DeclareMathAlphabet{\mathbf}{\encodingdefault}{\familydefault}{b}{n}
\DeclareSymbolFontAlphabet{\mathrm}{upright}
\DeclareMathSymbol{0}{\mathalpha}{upright}{`0}
\DeclareMathSymbol{1}{\mathalpha}{upright}{`1}
\DeclareMathSymbol{2}{\mathalpha}{upright}{`2}
\DeclareMathSymbol{3}{\mathalpha}{upright}{`3}
\DeclareMathSymbol{4}{\mathalpha}{upright}{`4}
\DeclareMathSymbol{5}{\mathalpha}{upright}{`5}
\DeclareMathSymbol{6}{\mathalpha}{upright}{`6}
\DeclareMathSymbol{7}{\mathalpha}{upright}{`7}
\DeclareMathSymbol{8}{\mathalpha}{upright}{`8}
\DeclareMathSymbol{9}{\mathalpha}{upright}{`9}

\begin{document}

The equation is
\[
\mathbf{E} = E \hat{r}.
\]
Let's try Greek $\alpha+\beta$ and a more complex formula
\[
\int_{-\infty}^{+\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]
A quantity is \qty{3.14}{\centi\meter}

\end{document}

enter image description here

A possible alternative

Use LuaLaTeX and lete-sans-math. The Text font is not Helvetica, but I don't think most people would notice the difference.

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage{unicode-math}
\usepackage{lete-sans-math}
\usepackage{siunitx}

\setmainfont{Lato}

\begin{document}

The equation is
\[
\mathbf{E} = E \hat{r}.
\]
Let's try Greek $\alpha+\beta+\Gamma$ and a more complex formula
\[
\int_{-\infty}^{+\infty}e^{-x^2}\,dx=\sqrt{\pi}
\]
A quantity is \qty{3.14}{\centi\meter}

\end{document}

enter image description here

3
  • 3
    newtxsf has an (admittedly not well documented) option noSTIXops which doesn't change numbers.
    – campa
    Commented May 25 at 11:06
  • @campa Actually, you get numbers in Computer Modern…
    – egreg
    Commented May 25 at 12:20
  • 1
    I checked, you can avoid the redefinition of the numbers and of \mathbf by using the noSTIXops options, but the redefinition of \familydefault must come before loading newtxsf.
    – campa
    Commented May 25 at 14:13
6

If you want both text and math material to employ matching sans-serif font faces and wish to generate characters with well-placed "hat" accents, I suggest you employ a package such as arev.

enter image description here

\documentclass[12pt]{article}
\usepackage{arev} % see https://ctan.org/pkg/arev

\begin{document}
The equation is $\mathbf{E} = E \hat{r}$.
\end{document}
5

You are loading multiple packages installing conflicting math font encodings.

enter image description here

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage[scaled]{helvet} %... sets helvet as text font
    \renewcommand{\familydefault}{\sfdefault}
%\usepackage{fouriernc}      %... controls math fonts
\usepackage[helvet]{sfmath} %... sets helvet to math fonts
%\usepackage{isomath}        %... handles mathrm to match text font (?)

\usepackage{siunitx}

\title{Applying sans-serif font to text and math}


\begin{document}
\maketitle

The equation is
\[
    \mathbf{E} = E \hat{r}.
\]


\end{document}
5

It works minimally if you don't load fouriernc, which sets up an incompatible font configuration. I say 'minimally' because I would not expect this configuration to work well for any document containing significant amounts of mathematics. Maths isn't meant to be typeset exclusively in sans because the use of sans in maths typically carries meaning i.e. it's a function of the semantics and not (or not primarily) of the aesthetics.

enter image description here

\documentclass[12pt, letterpaper, twocolumn]{article}

\usepackage[scaled]{helvet} %... sets helvet as text font
\renewcommand{\familydefault}{\sfdefault}
\usepackage[helvet]{sfmath} %... sets helvet to math fonts
% \usepackage{isomath}        %... handles mathrm to match text font (?)

\usepackage{siunitx}

\begin{document}
The equation is $\mathbf{E} = E \hat{r}$.
\end{document}

This gets you a composite character typeset in Nimbus Sans L Regular and Regular Italic aka a Helvetica look-somewhat-alike, which is what you presumably want here. (I'm assuming you don't have, say, Adobe Helvetica or whatever.) At any rate, it will use whatever you're using as 'Helvetica' for text.

2
  • 2
    +1. I've added a screenshot. :-)
    – Mico
    Commented May 25 at 8:14
  • @Mico Oh, Thank you. I think my images are improving, but smaller images seem more problematic. (Wish Okular would fix the bug, though I suppose I should really try to figure Wayland out.)
    – cfr
    Commented May 25 at 17:13
3

I add a MWE where I have used the command \skew. This command is specifically designed to move accents while keeping the underlying character still.

\documentclass[12pt, letterpaper, twocolumn]{article}
\usepackage{amsmath}
\usepackage[scaled]{helvet} % sets helvet as text font
\renewcommand{\familydefault}{\sfdefault}
\usepackage[helvet]{sfmath} % sets helvet to math fonts
\usepackage{siunitx}
% Definition of the macro \rhat to shift the \hat accent a bit to the right
\newcommand{\rhat}[1]{\skew{3}\hat{#1}}

\begin{document}
The equation is $\mathbf{E} = E \rhat{r}$.
\end{document}

In this definition, for example, \skew{3} shifts the accent of \hat by 3 mathematical points to the left.

enter image description here

6
  • 2
    +1 for the \skew command.
    – Mico
    Commented May 25 at 11:44
  • @Mico Always very gracious 😄 .
    – Sebastiano
    Commented May 25 at 11:45
  • 1
    \skew does not come from amsmath. Its defined in the kernel, and was defined already in plain TeX.
    – campa
    Commented May 25 at 14:33
  • 2
    Second @Mico ;).
    – cfr
    Commented May 25 at 17:17
  • 1
    @cfr Thank you very much to have appreciated my answer.
    – Sebastiano
    Commented May 25 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .