In a project we're using a commercial text font. The project is not a math related project but has some math in it here and there. The text font of course does not have a direct math font. But the XITS Math font (which is a part of standard LaTeX, at least TeX Live) seems a good enough match.

I decided to play with unicode-math to see if you could get it even closer, by changing the font for latin letters in the math font to the italic text font with the numbers being taken from the upright text font. Works surprisingly well.

Here is the catch though: since we are mixing the fonts used in math, math accents aren't placed particularly good.

I've prepared a MWE that is similar to our setup, but using a text font already in TeXLive so most people should be able to test it.

\setmathfont[Scale=MatchUppercase]{XITS Math}
\setmathfont[range=it/{latin,Latin},Ligatures={NoCommon, NoDiscretionary, NoHistoric, NoRequired, NoContextual}]{Cochineal-Italic}

UprightFont = *-Roman ,
BoldFont= *-Bold ,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,


$  p^{\ast}=c\vert \hat{\jmath}\vert ^{1/2}e^{l-\hat{l}} $


Resulting in

enter image description here

As we can see the hats are placed incorrectly

If we use only XITS Math we get

enter image description here

Which is much more reasonably.

So my question is this, given that the accent is probably placed using the top_accent data from the XITS Math font, how can we in Lua patch this font setup such that we can fix the placement of the accent on the chars that needs it? I've seen some examples of code that should be able to do this, but could not get that to work when we are missing fonts like this.

BTW: Yes, I can also fix this on the macro level (adapted from one of egregs answers):

\NewDocumentCommand{\myhat}{ m }{\myinnerhat{#1}}
% we are assuming \myhat is only being used in single chars
   \str_case_x:nnF { \tl_item:nn { #1 } { -1 } }

Your Answer

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

Browse other questions tagged or ask your own question.