I have written a document in serif as the base font for math as well (libertine). In this document I have defined a coloured environment which is sans (josefin sans). Now within that sans environment the default math is serif.
I would want it to be sans.
I tried to force it via $\textsf{F} = \textsf{ma}$
but the numbers go for a toss and is not elegant.
Using $\mathsf{}$
results in defaulting to cm sans font, even if this can default to josefin it should be ok.
Is there any easier way to achieve this in the definition of the environment itself?
I also looked at this similar question, but josefin does not seem to have sansmath option as it is not a mathfont.
I don't want sans as the default font for rest of the document so \renewcommand{\rmdefault}{\sfdefault}
will not work for me. I prefer to use pdflatex.
MWE
\documentclass{article}
\usepackage{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}
\usepackage[medium]{josefin}
\usepackage{xcolor}
\newcommand{\hlred}[1]{\textcolor{red}{\sffamily #1}}% prints in red
\begin{document}
This is regular text with serif math font $F = ma$
\hlred{This is the coloured sans environment. The regular math here appears in serif $F = ma$. Only with textsf, it appears in sans $\textsf{F} = \textsf{ma}$. With mathsf, it defaults to computer modern sans $\mathsf{F = ma}$.}
\end{document}