2

I am using the implementation I found from this website to write a document in the Calibri font, including the math mode. It looks wonderful, however there is one major flaw: the "large" symbols don't scale properly. This includes integral signs and parentheses.

MWE:

\documentclass[10pt]{article}
\usepackage{amsmath}  % Same for amsmath.
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont[Mapping=tex-text,Ligatures={NoRequired,NoCommon,NoContextual}]{Calibri}
\setmathfont[slash-delimiter=frac]{Cambria Math}
\setmathfont[range={"0000-"FFFF}]{Calibri}
\setmathfont[range=up]{Calibri}
\setmathfont[range=sfup]{Calibri}
\setmathfont[range=it]{Calibri Italic}
\setmathfont[range=bfup]{Calibri Bold}
\setmathfont[range=bfit]{Calibri Bold Italic}
\setsansfont{Calibri}  % Make \mathsf and \textsf also Calibri

\begin{document} Lorem ipsum dolor sit amet, consectetur adipiscing elit... [ x^2y = 2z\left(\frac{\alpha \beta^2}{73c}\right)^2 ] [ \frac{d}{dx}\int f(x),dx = f(x) ] \end{document}

Is there any easy way to fix this? If there's no simple general solution, it would also be fine to just fix the parentheses, as for my purposes the other "large" symbols don't occur.

Thanks in advance.

PS: I'm using this slightly weird implementation instead of, say the sansmath package, or using the cmbright font, as I subjectively prefer the look that it gives. Also, it's better compatible with the Calibri font which I'm using for the main text.

David Carlisle
  • 757,742
YiFan
  • 165
  • 1
    \setmathfont[range={"0000-"FFFF}]{Calibri}looks rather odd, that's replacing the whole basic plane by Calibri so you are hardly using the declared Cambria Math at all, in particular () are no longer coming from a math font with declared extensible characters. – David Carlisle Jan 04 '22 at 16:34
  • @DavidCarlisle I think that was done in order for Cambria Math to be used for the horizontal lines in fractions, as explained in the linked website (and Calibri for everything else, which is the desired outcome). But I'm of course happy to accept alternative implementations if you think that was a bad idea. – YiFan Jan 04 '22 at 16:39
  • well I don't know what final outcome you want but it breaks all math typesetting except fractions as you are not using a unicode math font for anything except that. – David Carlisle Jan 04 '22 at 16:42
  • @DavidCarlisle I know what I'm doing is odd, but is it possible to just have a fix for the parenthesis scaling? That's the most major problem for me right now. Many thanks for your help. – YiFan Jan 04 '22 at 16:44
  • I think it's better to say the code copied from that site is "wrong" rather than "odd" – David Carlisle Jan 04 '22 at 16:50
  • I changed the link for your referenced code to this site as actually the site you linked to just appears to be some site that copies answers from here without attribution – David Carlisle Jan 04 '22 at 16:56
  • @DavidCarlisle Thanks, I didn't realise that. (Actually, maybe the authors of both posts are the same person? Not sure how to verify if that is true though.) – YiFan Jan 04 '22 at 16:59
  • no the whole of that site is just unattributed copies from stackexchange – David Carlisle Jan 04 '22 at 17:02
  • @DavidCarlisle Okay, I see. – YiFan Jan 04 '22 at 17:03

1 Answers1

4

enter image description here

\documentclass[10pt]{article}
\usepackage{amsmath}  % Same for amsmath.
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont[Mapping=tex-text,Ligatures={NoRequired,NoCommon,NoContextual}]{Calibri}
\setmathfont[slash-delimiter=frac]{Cambria Math}
\setmathfont[range={"0000-"FFFF}]{Calibri} %removing this fixes the issue
% Or if you _really_ want to keep that, at least put the () back
\setmathfont[range={"0028-"0029}]{Cambria Math}
\setmathfont[range=up]{Calibri}
\setmathfont[range=sfup]{Calibri}
\setmathfont[range=it]{Calibri Italic}
\setmathfont[range=bfup]{Calibri Bold}
\setmathfont[range=bfit]{Calibri Bold Italic}
\setsansfont{Calibri}  % Make \mathsf and \textsf also Calibri

\begin{document} Lorem ipsum dolor sit amet, consectetur adipiscing elit... [ x^2y = 2z\left(\frac{\alpha \beta^2}{73c}\right)^2 ] [ \frac{d}{dx}\int f(x),dx = f(x) ] \end{document}

Basically

\setmathfont[range={"0000-"FFFF}]{Calibri} %removing this fixes the issue

Will break the math setting as Calibri is not a Math font. You added a line to fix up (just) fractions and I added another to fix up (just) extendable () but not doing that at all would seem safer. (As your output shows \intfor example is barely usable with this setting)

David Carlisle
  • 757,742
  • Thank you so much; I guess the issue is I copy pasted code without understanding it! I'll wait a bit in case a better answer comes along, but otherwise I'll accept yours. :) – YiFan Jan 04 '22 at 16:47