Thanks to @Ross showing me mathastext
I reckon I've got a working solution.
Solution
Math Symbols
\usepackage{fourier}
In my opinion, fourier's symbols matches better stylistically, however I don't want to keep the font-related changes so I add it first (so that the other font packages overwrite that).
Math Font
\usepackage{plex-serif}
I want to use a serif font for the math, so I add this after fourier
so that it overwrites it, and before mathastext
so that it's actually used for the maths
Apply the font to math
\usepackage[basic,italic,symbolgreek]{mathastext}
mathastext
seems good, but to me it had a few issues when used without any options.
- Brackets for matrices, when multiline brackets were required
mathastext
just grabbed the []
characters used by the font, and didn't do anything to make them multiline. This was fixed by adding the basic
option — though this also had the effect of no replacing a few other symbols (a worthwhile price in my mind)
- Non-italic math by default. This was an easy fix:
italic
- Not using the greek letters from the font. Once again easy fix:
symbolgreek
- Bad kerning / overlapping (or crammed) letters
To solve the last issue I used another command, seen at the end of this mini-section.
Text Font
\usepackage[sfdefault]{plex-sans}
After the serif variant has been set to be used in math by mathastext
I change to the sans font I want to use for the rest of the document.
Spacing Issues
By default, the spacing was the same as italic/slanted text. Which is an issue for math because it can cause overlaps/cramping. To see this in action I drew vertical rules of width 0.1ex
with \hspace{-0.1ex}
after them, producing
For most letters adding 0.5mu of space either side fixed things up, however letters with 'tails' required some extra attention. After some tweaking I managed to get this:
While I wouldn't consider this 'fixed' it's better. This is the code used (sans):
\makeatletter
\@for\@tempa:=a,b,c,d,e,h,i,k,l,m,n,o,q,r,s,t,u,v,w,x\do{%
\MTsetmathskips{\@tempa}{0.5mu}{0.5mu}}%
\makeatother
\MTsetmathskips{f}{2.5mu}{0.5mu}
\MTsetmathskips{g}{1.5mu}{0.5mu}
\MTsetmathskips{j}{2.5mu}{0.5mu}
\MTsetmathskips{p}{1.5mu}{0mu}
\MTsetmathskips{y}{1.5mu}{0.5mu}
\MTsetmathskips{z}{1mu}{0.5mu}
And then for the serif version:
\makeatletter
\@for\@tempa:=a,b,c,d,e,h,i,k,l,m,n,o,q,r,t,u,v,w\do{%
\MTsetmathskips{\@tempa}{0.5mu}{0.5mu}}%
\makeatother
\MTsetmathskips{f}{4.5mu}{0.5mu}
\MTsetmathskips{g}{2.5mu}{0.5mu}
\MTsetmathskips{j}{4mu}{0.5mu}
\MTsetmathskips{p}{2.5mu}{0mu}
\MTsetmathskips{s}{1mu}{0.5mu}
\MTsetmathskips{x}{1.5mu}{0.5mu}
\MTsetmathskips{y}{3.5mu}{0.5mu}
\MTsetmathskips{z}{1.5mu}{0.5mu}
Before
After
It's minor but it's an improvement
All together
\usepackage{fourier}
\usepackage{plex-serif}
\usepackage[basic,italic,symbolgreek]{mathastext}
\usepackage[sfdefault]{plex-sans}
\makeatletter
\@for\@tempa:=a,b,c,d,e,h,i,k,l,m,n,o,q,r,s,t,u,v,w,x\do{%
\MTsetmathskips{\@tempa}{0.5mu}{0.5mu}}%
\makeatother
\MTsetmathskips{f}{2.5mu}{0.5mu}
\MTsetmathskips{g}{1.5mu}{0.5mu}
\MTsetmathskips{j}{2.5mu}{0.5mu}
\MTsetmathskips{p}{1.5mu}{0mu}
\MTsetmathskips{y}{1.5mu}{0.5mu}
\MTsetmathskips{z}{1mu}{0.5mu}
Result
Serif
\usepackage[sfdefault]{plex-sans}
\usepackage[basic,italic,symbolgreek]{mathastext}
Sans
\usepackage{plex-serif}
\usepackage[basic,italic,symbolgreek]{mathastext}
Mixed
\usepackage{plex-serif}
\usepackage[basic,italic,symbolgreek]{mathastext}
\usepackage[sfdefault]{plex-sans}
\setmainfont
to set your main body font, I suggest using\setmathfont
to set your math font.