2

I'm using the awesome-cv class file (from here) to write a statement, but I'm unhappy with the math fonts. Specifically, I don't like the result of using \mathbb. Also, math operators (even predefined ones like \log) are italicized while I would like them to be as in \mathrm (as shown below).

I tried installing a different font (Palatino) in the fonts directory, but this did not affect the math font at all.

I would even be willing to change the font entirely using, e.g., \usepackage{mathpazo}, but it doesn't seem to change anything, probably due to specifications in the awesome-cv.cls file.

The awesome-cv.cls file includes the line \RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}, and it turned out that configuring the math font with this package was most of my problem. Some useful posts: Changing the operator font with unicode-math loaded, Unicode-math changes font outside of range, lost symbols with unicode-math

Final update thanks to Davislor's comments.

MWE:

% Important note:
% This template must be compiled with XeLaTeX, the below lines will ensure this
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[letterpaper]{awesome-cv}
\geometry{left=2cm, top=1.5cm, right=2cm, bottom=2cm, footskip=.5cm}
\fontdir[fonts/]

% math packages

%\usepackage{amssymb} % throws errors/conflicts
\usepackage{amsfonts}
\usepackage{amsmath}

% math commands

% new commands
\renewcommand{\C}{\mathbb C}
\newcommand{\R}{\mathbb R}
\newcommand{\Q}{\mathbb Q}
\newcommand{\Z}{\mathbb Z}

% new operators
\DeclareMathOperator{\Gal}{Gal}

\setmathfont[Path=fonts/STIXv2.0.0/OTF/]{STIX2Math.otf}
%\setmathfont[Path=fonts/,range=\sqrt]{SourceSansPro-Regular.otf}
\setmathfont[range=\mathnormal,Path=fonts/]{SourceSansPro-It.otf}

\ExplSyntaxOn
\makeatletter
\renewcommand{\operator@font}{\um_switchto_mathsf:}
\makeatother
\ExplSyntaxOff


%\setmainfont[Path=fonts/]{SourceSansPro-Regular.otf}
%\setmathfont[Path=fonts/]{SourceSansPro-It.otf}

\begin{document}

%----------------------------------------------------------------------------------------
%   LETTER CONTENT
%----------------------------------------------------------------------------------------

\begin{cvletter}

%------------------------------------------------

$$
\log(N) \qquad \mathrm{log}(N)
$$

$$
\C \quad \R \quad \Q \quad \Z
$$

$$
\Gal(K/\Q) \quad \mathrm{Gal}(K/\Q)
$$

$$
\varphi: X \to Y
$$

\end{cvletter}

\end{document}

enter image description here

Thanks for any help!

  • Let's start off by not using $$...$$. See Why is \[ ... \] preferable to $$ ... $$? – Werner Oct 25 '18 at 02:11
  • 1
    Not a complete answer, because I'm not at home to test. From the snippet, your class is loading OpenType fonts with fontspec. You therefore probably want to load unicode-math and use the \setmathfont command. (You would want \setmathfont[range=it]{SourceSansPro-It.otf} and so on to match your text font.) You might also be able to use mathspec. – Davislor Oct 25 '18 at 21:21
  • You might find Fira Math to be a good match for your text fonts. – Davislor Oct 25 '18 at 21:22
  • If you want a Palatino clone, I would recommend Asana Math for an OpenType math font and either the real Palatino if you have it or TeX Gyre Pagella as a free alternative for your body font. With legacy packages, newpxtext and newpxmath are more up-to-date than mathpazo. – Davislor Oct 25 '18 at 21:28
  • Hi @Davislor, thanks for your help! Indeed, the .cls file contains \RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}. I tried adding something close to your suggestion, \setmathfont[range=\mathnormal,Path=fonts/]{SourceSansPro-It.otf}. As you can see in the updated picture, now the math operators are displayed correctly, but I've lost \mathbb and math symbols like $\phi$. How do I fix this? Thanks again! – Viktor Vaughn Oct 25 '18 at 23:03
  • Do I need to do something like in this thread? – Viktor Vaughn Oct 25 '18 at 23:05
  • 1
    Yes, you got it. You need to set your main math font first, for example, \setmathfont{STIX Two Math}, and then override one or more of the math alphabets (up, it, by up, bfit, etc.). I would also suggest you set \defaultfontfeatures{Scale=MatchLowercase} before you start declaring any fonts. That will ensure they come out properly scaled. – Davislor Oct 26 '18 at 00:32
  • 1
    There are a few solutions for the remaining \mathrm{Gal} problem. Since you appear to be using this font only for operator names, the simplest workaround is to use \operatorname{Gal}. You can also, however, \setmathfont[range=up]{SourceSansPro-Regular.otf} and use \symup, as well as overriding \setoperatorfont and \setmathrm if you need to. – Davislor Oct 26 '18 at 00:48
  • However, unless there's a bug in the class file, setting the math font properly should get it to work put of the box. – Davislor Oct 26 '18 at 00:50
  • @Davislor Thank you again for your invaluable help. I installed the STIX math fonts, which fixed the \mathbb typesetting. I think the class file is kind of wonky, so I did have to fix the operator fonts, too. I think \DeclareMathOperator{\Gal}{Gal} is just a wrapper for \newcommand{\Gal}{\operatorname{Gal}}, so I had to try something a bit trickier. I think my version of unicode-math needs updating so I had to do some more fiddling, but the answer here worked. – Viktor Vaughn Oct 26 '18 at 01:31
  • Anyway, thank you once more. If you would like to combine your comments into an answer, I'd be happy to upvote it. – Viktor Vaughn Oct 26 '18 at 01:31
  • 1
    You're welcome. I'm on my phone right now, but I should be able to test an answer and make a sample image when I get home. – Davislor Oct 26 '18 at 01:55
  • Are you sure you want to include heavy maths with your Curriculum Vitae? Why not simply include your paper with the CV? – Johannes_B Oct 26 '18 at 06:08
  • @Johannes_B I'm writing a research statement so I need quite a bit of math. And I already use this class for my CV, so I'd like to use the same class for both if possible. – Viktor Vaughn Oct 26 '18 at 07:02
  • This class is designed for CVs only. And not even in a very good way. I recommend to use a minimal template. https://en.wikibooks.org/wiki/LaTeX/Scientific_Reports – Johannes_B Oct 26 '18 at 07:04
  • @Johannes_B Well, there is an example cover letter template as well, which is what I've adapted for my statement. I agree that the class is not very flexible: it took me several hours and help from people here to modify it. But now it compiles and looks pretty good, so I don't plan to throw away my hard work! – Viktor Vaughn Oct 26 '18 at 07:10
  • 1
    @André3000 Okay, posted. (If this is your first question, by the way, the green accept button is different from the upvote button. Apologies if you knew that.) – Davislor Oct 26 '18 at 19:26
  • @André3000 One more word of advice: beware the sunk-cost fallacy! – Davislor Oct 26 '18 at 19:32

1 Answers1

2

To turn my comments into an answer: you should seriously consider whether you want to write your paper in a non-standard CV class. However, if you really do, here is what I got to work.

Note that I needed to make several changes to your .cls file to get it to compile at all in TeX Live 2018. I had to change a \newfontfamily to \setfontfamily for a family that had previously been defined in a package it loaded. (A recent version of fontspec made this compatibility-breaking change.) I also had it use the more recent version of the fonts installed on my system. The sourcesanspro package also needed [sfdefault]. That having been done, the problem with the operator names was that the class file loaded unicode-math before you load amsmath. Adding \RequirePackage{amsmath} before \documentclass enabled some hackish workarounds.

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\RequirePackage{amsmath}
\documentclass[letterpaper]{awesome-cv}
\geometry{left=2cm, top=1.5cm, right=2cm, bottom=2cm, footskip=.5cm}

%% Math Font setup
\defaultfontfeatures{Scale=MatchLowercase}
\unimathsetup{partial=upright} % Source Sans Pro contains \partial at U+2202.
% If you should actually need \mitpartial, \mbfpartial, etc., load them from a
% math font.  If you want an italic \partial, load from SourceSansPro-It.
\setmathfont{STIX2Math.otf}
% Sets math symbols present in Source Sans Pro and that work. You still might
% not, e.g. want ≥ and ≤ from the text font if ≰ does not match them.
\setmathfont[range={up,"21,"23-"25,"2A-"2F,"5C,"5E-"5F,"7E,
                      `¬,`±,`·,`×,`÷,`≤,`≥,`≠,`≈,`∞,`√}
              ]{SourceSansPro-Regular.otf}
% Must load separately, or this will prevent autodetection of the upright math
% alphabet:
\setmathfont[range=\partial]{SourceSansPro-Regular.otf}
\setmathfont[range={it}]{SourceSansPro-RegularIt.otf}
\setmathfont[range={bfup}]{SourceSansPro-Bold.otf}
\setmathfont[range={bfit}]{SourceSansPro-BoldIt.otf}
% Greek variant letters Missing from Source Sans Pro:
\setmathfont[range={\mupvarepsilon,\mupvarphi,\mupvartheta,\mupvarpi,
                      \mupvarkappa,\mupvarrho,\mupvarTheta,\nabla,
                      \mitvarepsilon,\mitvarphi,\mitvartheta,\mitvarpi,
                      \mitvarkappa,\mitvarrho,\mitvarTheta,\mitnabla,
                      \mbfvarepsilon,\mbfvarphi,\mbfvartheta,\mbfvarpi,
                      \mbfvarkappa,\mbfvarrho,\mbfvarTheta,\mbfnabla,
                      \mbfitvarepsilon,\mbfitvarphi,\mbfitvartheta,
                      \mbfitvarpi,\mbfitvarkappa,\mbfitvarrho,
                      \mbfitvarTheta,\mbfitnabla }
               ]{GFSNeohellenicMath.otf}
% By default, \mathscr is the same as \mathcal, but several math fonts provde
% two separate alphabets as variants.
\setmathfont[range={scr,bfscr},
               Scale=MatchUppercase,
               StylisticSet=1
              ]{STIX2Math.otf}

% Workaround for \operatorname and \mathrm:
\setmathrm{SourceSansPro}[
  UprightFont = *-Regular ,
  BoldFont = *-Bold ,
  Ligatures = {Common, TeX },
  Extension = .otf ]
\setoperatorfont\mathup

% math commands

% new commands
\renewcommand{\C}{\mathbb C}
\newcommand{\R}{\mathbb R}
\newcommand{\Q}{\mathbb Q}
\newcommand{\Z}{\mathbb Z}

% new operators
\DeclareMathOperator{\Gal}{Gal}

\begin{document}

%----------------------------------------------------------------------------------------
%   LETTER CONTENT
%----------------------------------------------------------------------------------------

\begin{cvletter}

%------------------------------------------------

\[
\log(N) \qquad \mathrm{log}(N)
\]
\[
\C \quad \R \quad \Q \quad \Z
\]
\[
\Gal(K/\Q) \quad \mathrm{Gal}(K/\Q)
\]
\[
\varphi: X \to Y
\]
\[
\symup{i} \symup{e} \symup{\pi} \cdot
\Biggl\{ \Biggl[ \Biggl( \biggl\{ \biggl[ \biggl( \Bigl\{ \Bigl[ \Bigl(
\nabla \frac{\partial \vartheta}{\partial t}
\Bigr) \Bigr] \Bigr\} \biggr) \biggr] \biggr\} \Biggr) \Biggr] \Biggr\}        
\]

\end{cvletter}

\end{document}

Font Sample

ETA: Went back and tweaked it a bit more. Now resizing delimiters and \nabla work.

That image is an unusual mashup of several different fonts. I loaded the math symbols that work correctly from Source Sans Pro, then took the variant Greek letters that are not present from GFS Neohellenic, then fell back to STIX Two Math for the remaining symbols. (You might want the upright math symbols to be different from the body text.)

You shouldn’t load amsfonts or amssymb with unicode-math, as they use legacy font encodings and there are OpenType replacements. You also should use the \setoperatorfont command from unicode-math instead of attempting to redefine operator@font.

There is at least one limitation I left in rather than making the font selection even more overcomplicated. You would need to load yet another math font with [range={\partial,\mitpartial,\mbfpartial,\mbfitpartial}] if for some reason you need to use the upright, italic, bold and bold italic forms of the partial derivative symbol in the same document.

Davislor
  • 44,045