2

I found this question:

\chemgreek + \fontspec + Lucida.otf = missing greek characters

which in principle solves my problem (missing greek characters). But since I use a scaling for my fonts another problem rises:

\documentclass[12pt,
           ]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage[babel, german=quotes]{csquotes}

\usepackage{chemmacros}
\usechemmodule{all}
\chemsetup{greek = {fontspec}}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}

\defaultfontfeatures{Scale=.5}

\setmainfont{LucidaBrightOT.otf}
\setmathfont{LucidaBrightMathOT.otf}[NFSSFamily=lbm]

\ExplSyntaxOn
\cs_set_protected:Nn \chemgreek_text:n
{ \ensuremath { \text {\fontfamily{lbm}\selectfont #1} } }
\ExplSyntaxOff

\begin{document}
Blindtext $a_i=5$ blindtext.
\printchemgreekalphabet $\upalpha$ $\alpha$ \chemalpha

\end{document}

As you might see, the math-fonts don't scale correctly. What can I do to fix this? Thanks!

2
  • Welcome to TeX.SX!
    – BambOo
    Commented Aug 7, 2018 at 10:41
  • Argh, I pasted the wrong code. I modified the start post. Now the problem is visible: $a_i=5$ is too large.
    – user168000
    Commented Aug 7, 2018 at 12:45

1 Answer 1

1

To get smaller text in your document, it is much better to change the normal font size instead of scaling all unicode fonts. So instead of

\defaultfontfeatures{Scale=.5}

just replace \documentclass[12pt]{scrreprt} with \documentclass[6pt]{scrreprt}.

Now let's assume that you can not do this for some reason. The problem is the line

\setmathfont{LucidaBrightMathOT.otf}[NFSSFamily=lbm]

unicode-math loads multiple variations of the specified font to set legacy math parameters, but with the NFSSFamily option every font uses the same NFSS family name, so every font overwrites the previous ones. This means only last font is really used, but the last font overwrites the scaling option in order to become a different font. In addition to the scaling problem, this might also lead to wrong math parameters.

To fix this unicode-math should only pass the NFSSFamily option when loading the main font. This can be archived by using \patchcmd from etoolbox to patch the font loading macros from unicode-math:

\documentclass[12pt]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage[babel, german=quotes]{csquotes}

\usepackage{chemmacros}
\usechemmodule{all}
\chemsetup{greek = {fontspec}}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{etoolbox}

\ExplSyntaxOn
\keys_define:nn{unicode-math}{
  NFSSFamily .tl_set:N = \l__my_um_nfssfamily_tl
}
\patchcmd \__um_fontspec_select_font: {
  \l__um_family_tl {\l__um_font_keyval_tl}
}{
  \l__um_family_tl {NFSSFamily={\l__my_um_nfssfamily_tl},\l__um_font_keyval_tl}
}{}{\GenericError{}{Something~broke}{}}
\ExplSyntaxOff

\defaultfontfeatures{Scale=.5}

\setmainfont{LucidaBrightOT.otf}
\setmathfont{LucidaBrightMathOT.otf}[NFSSFamily=lbm]

\ExplSyntaxOn
\cs_set_protected:Nn \chemgreek_text:n
{ \ensuremath { \text {\fontfamily{lbm}\selectfont #1} } }
\ExplSyntaxOff

\begin{document}
Blindtext $a_i=5$ blindtext.
\printchemgreekalphabet $\upalpha$ $\alpha$ \chemalpha
\end{document}
3
  • thank you for your answer. The reason why I use scaling is not to set the fontsize. The documentation of the lucida font recommends to scale it down to about 0.9 (the 0.5 is just to show the problem), because of the large x height. Despite the fact that you solution seems to work, is there a simpler, more straight forward solution for this problem?
    – user168000
    Commented Aug 8, 2018 at 6:28
  • @user168000 In this case I would recomend passing Scale= as a optional argument to the font instead of using \defaultfontfeatures to avoid accidentially affecting other fonts. Anyway this would not fix the scaling problem. Commented Aug 8, 2018 at 17:02
  • @user168000 Regarding an easier solution: I do not think there is one (otherwise I would have used it) but you might want to report this as a bug to the unicode-math maintainer. If they fix it you just have to update and the problem disappears without any complicated code in your file. Commented Aug 8, 2018 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .