fontspec
fontspec copied to clipboard
Can't set mathcal font in lualatex
(fontspec 2.5c, luatex 0.95, xetex 3.14159265-2.6-0.99996)
The following example:
\documentclass{report}
\usepackage{unicode-math}
\setmathfont[range=cal,Contextuals=Swash]{MinionPro-It}
\begin{document}
$\mathcal{F}$
\end{document}
Gives this result in xelatex:

But this in lualatex:

I am using the following workaround to set the mathcal font in lualatex (replacing the \setmathfont line ):
\usepackage{mathtools}
\newfontface\swash[Contextuals=Swash]{MinionPro-It}
\renewcommand\mathcal[1]{\mathmbox{\textrm{\swash #1}}}
Which seems to work, making me think that I had done things correctly and that this is a possible bug in fontspec. If it is a bug it isn't new - it was present in texlive 2015 when I first started using lualatex.
Hi Chris,
Thanks for reporting this. I can’t reproduce this problem myself, perhaps because I don’t have the Minion fonts on hand. I tried this instead; can you confirm whether it replicates the problem you’re having?
\documentclass{report}
\usepackage{unicode-math}
\setmathfont[range=cal,Style=Swash]{EBGaramond12-Italic.otf}
\begin{document}
fontspec: {\fontspec{EBGaramond12-Italic.otf} Q}
text swash: {\fontspec[Style=Swash]{EBGaramond12-Italic.otf} Q}
mathcal: $\mathcal{Q}$
\end{document}
If that also fails for you, could you take a look in the log file and look for an entry near the end like this:
.................................................
. fontspec info: "defining-font"
.
. Font family 'EBGaramond12-Italic.otf(2)' created for font
. 'EBGaramond12-Italic.otf' with options
. [Path=/usr/local/texlive/2015/texmf-dist/fonts/opentype/public/ebgaramond/,Sty
le=Swash].
.
. This font family consists of the following NFSS series/shapes:
.
. - 'normal' (m/n) with NFSS spec.:
. <->"file:/usr/local/texlive/2015/texmf-dist/fonts/opentype/public/ebgaramond/E
BGaramond12-Italic.otf:mode=node;script=latn;language=DFLT;+swsh;"
. - 'small caps' (m/sc) with NFSS spec.:
. <->"file:/usr/local/texlive/2015/texmf-dist/fonts/opentype/public/ebgaramond/E
BGaramond12-Italic.otf:mode=node;script=latn;language=DFLT;+swsh;+smcp;"
.................................................
and report what you see.
Ok, I think I've made some progress.
Your example renders correctly for me with EBGaramond12-Italic:

But not correctly with MinionPro-It. This is the result in both lualatex and xelatex:

Here is the relevant section of the log file:
.................................................
. fontspec info: "defining-font"
.
. Font family 'MinionPro-It(2)' created for font 'MinionPro-It' with options
. [Style=Swash].
.
. This font family consists of the following NFSS series/shapes:
.
. - 'normal' (m/n) with NFSS spec.:
. <->"MinionPro-It:mode=node;script=latn;language=DFLT;"
. - 'small caps' (m/sc) with NFSS spec.:
. <->"MinionPro-It:mode=node;script=latn;language=DFLT;+smcp;"
.................................................
and I also see these warnings:
*************************************************
* fontspec warning: "icu-feature-not-exist-in-font"
*
* OpenType feature 'Style=Swash' (swsh) not available for font 'MinionPro-It'
* with script 'Latin' and language 'Default'.
*************************************************
The issue appears to be something related to the difference between the Style and Contextuals keywords - you may have though I was being silly using Contextuals=Swash in my example, but that's because using Style=Swash doesn't work in either xelatex or lualatex. With your example using Minion Pro and Contextuals=Swash:
\documentclass{report}
\usepackage{unicode-math}
\setmathfont[range=cal,Contextuals=Swash]{MinionPro-It}
\begin{document}
fontspec: {\fontspec{MinionPro-It} Q}
text swash: {\fontspec[Contextuals=Swash]{MinionPro-It} Q}
mathcal: $\mathcal{Q}$
\end{document}
I get the following with xelatex:

And this with lualatex:

and see this in the relevant part of the log file:
.................................................
. fontspec info: "defining-font"
.
. Font family 'MinionPro-It(2)' created for font 'MinionPro-It' with options
. [Contextuals=Swash].
.
. This font family consists of the following NFSS series/shapes:
.
. - 'normal' (m/n) with NFSS spec.:
. <->"MinionPro-It:mode=node;script=latn;language=DFLT;+cswh;"
. - 'small caps' (m/sc) with NFSS spec.:
. <->"MinionPro-It:mode=node;script=latn;language=DFLT;+cswh;+smcp;"
.................................................
But I don't see any warnings about Contextuals=Swash not existing as I did with Style=Swash.
So the problem here has something to do with contextual chararcters being able to use Minion's swashed style, but not all characters when Style=Swash. And then the reason I was seeing the problem with mathcal specifically is because \mathcal{} in lualatex doesn't consider the first character a contextual, whereas xelatex appears to do so (but not further characters - in both xelatex and lualatex only the first character within \mathcal{} is actually rendered in the 'cal' font, the rest are rendered in the regular maths font, which is fine).
So the problem seems to be perhaps two things:
Style=Swashdoesn't work with Minion Pro Italic, althoughContextuals=Swashdoes.- Lualatex doesn't consider the first character within
\mathcal{}to be a contextual, whereas xelatex does.
I have the opposite problem with Garamond Premier Pro Italic. Style=Swash works, but Contextuals=Swash does not.
Is this just the fault of the fonts?
If 2. were fixed (not sure if anything to do with fontspec at this point), one could use both fonts despite their deficiencies - with Style=Swash for Garamond and Contextuals=Swash for Minion.
Just quickly for the time being — I am thinking this is a LuaTeX rather than a fontspec issue; it's not even clear to me if the current behaviour is a bug or just a difference in how XeTeX behaves. I'll leave this open here for now to remind me to check to see if there's anything I can do to work around the problem you're having. Of course, the best approach of course would be if the font provided a non-fragile way to access the swash characters!