0

There are now a number of OpenType math fonts (or font families) available with Greek sans serif letters in all combinations of upright/italic and regular/bold. Stix 2 is a prime example (although at the moment the non-bold characters are in the private use area). How difficult would it be to have the correct form of Greek characters appear alongside their Latin counterparts based on the surrounding command (those listed in the title)? In other words, \mathsf{a\alpha b\beta c\gamma} should display as enter image description here

I have come very close to accomplishing this based on the answers provided here: Sans serif and serif greek fonts in math expression. In fact, I used (unicode versions of) those methods to generate the above expression (Latin is Tex Gyre Heros and Greek is Stix Two, both OTF). But once you get into more complicated expressions (for instance those involving exponents, say \mathsf{k^{\alpha}}), this fails. I don't expect this to be easy, but it seems like it would be worth the effort.

Note: I do not wish to use unicode-math because I am using mtpro2 for my main math font and am not yet ready to change that. I realize that this means that all of the commands in the title need to be defined (a given with unicode-math, not so otherwise).

What I have written so far is in package form. Since most of it consists of \Umathchardef commands, I am omitting most of those in what follows to keep it short. Also, I am only including the regular upright portion since the other three are analogous. At the moment, the command that takes both Latin and Greek is \sxgksfup. I can worry about renaming it later.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Stix2OTFSansGreek}[07/07/2023]

\newfontfamily\StixTwoGkSfUp{STIXTwoMath-Regular.otf}[NFSSFamily=stixgksfup,Script=Math,Scale=MatchLowercase]
\DeclareSymbolFont{gksfup}{TU}{stixgksfup}{m}{n}
\newfontface\StixTwoGkSfIt{STIXTwoMath-Regular.otf}[NFSSFamily=stixgksfit,Script=Math,Scale=MatchLowercase]
\DeclareSymbolFont{gksfit}{TU}{stixgksfit}{m}{n}
\newfontface\StixTwoGkBfSfUp{STIXTwoMath-Regular.otf}[NFSSFamily=stixgkbfsfup,Script=Math,Scale=MatchLowercase]
\DeclareSymbolFont{gkbfsfup}{TU}{stixgkbfsfup}{m}{n}
\newfontface\StixTwoGkBfSfIt{STIXTwoMath-Regular.otf}[NFSSFamily=stixgkbfsfit,Script=Math,Scale=MatchLowercase]
\DeclareSymbolFont{gkbfsfit}{TU}{stixgkbfsfit}{m}{n}

\Umathchardef\rsualpha       "0 \symgksfup "0E196
\Umathchardef\rsubeta        "0 \symgksfup "0E197
\Umathchardef\rsugamma       "0 \symgksfup "0E198
\Umathchardef\rsuvarTheta    "0 \symgksfup "0E18E
\Umathchardef\rsunabla       "0 \symgksfup "0E1F6

\def\ifiscseq#1{\ifcat$\expandafter\@gobble\string#1$\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}

\def\gk@@sfup#1#2\@nil{%
    \ifiscseq{#1}{\ifcsdef{rsu\@xp\@gobble\string#1}{\csname rsu\@xp\@gobble\string#1\endcsname}{#1}}{%not a cs
    \mathsf{#1}}    
    \ifblank{#2}{\relax}{\gk@@sfup #2\@nil}}

\DeclareRobustCommand*{\sxgksfup}[1]{\gk@@sfup#1\@nil}

The errors generated by \sxgksfup{k^{\alpha}} are as follows.

! Missing { inserted.
<to be read again> 
                   \egroup 
l.866 \end{align*}
                  
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Missing } inserted.
<inserted text> 
                }
l.866 \end{align*}
                  
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.

This is repeated many times. Of course, this may be unique to that particular expression. I'd like this to work with any expression.

Lastly, is it beneficial to modify the last two arguments to the \DeclareSymbolFont commands to {m}{n}, {m}{it}, {b}{n}, and {b}{it}, respectively?

4
  • 1
    If you've come very close, can you post what you've come up with in the form of a minimal example people can copy-paste-compile?
    – cfr
    Jul 8, 2023 at 3:47
  • you have not provided the code in a form that is easy to test. ... will generate error, and what example like \mathsf{k^{\alpha}} fails and what error do you get. Jul 8, 2023 at 12:41
  • you can not implement this as a change of \fam like a clasisc tex \mathsf you need to re-implement unicode-math \symsf which changes all the \Umathcode settings for all the characters without changing font. Jul 8, 2023 at 12:57
  • 1
    better, but still you are showing an error from line 866 of an unshown document. why not post a document and the error you get from the code posted? Jul 8, 2023 at 13:00

2 Answers 2

0

enter image description here

You do not want multiple fonts, just one, but shift the characters to be taken from the unicode math blocks, eg

https://w3c.github.io/xml-entities/bold.html

That is, you need \symxx from unicode math. I just show three styles here, math italic, upright and upright bold, just for a and alpha.

\documentclass{article}

\usepackage{fontspec}
\newfontfamily\StixTwoMath[NFSSFamily=stix,Script=Math,Scale=MatchLowercase]{STIXTwoMath-Regular.otf}
\DeclareSymbolFont{stix}{TU}{stix}{m}{n}


\def\alpha{^^^^03b1}
\Umathcode`a =   0 \symstix "1D44E % a
\Umathcode"03B1=0 \symstix  "1D6FC % alpha

\def\symup#1{%
\begingroup
\Umathcode`a =   0 \symstix `a    % a
\Umathcode"03B1=0 \symstix  "03B1 % alpha
#1%
\endgroup
}

\def\symbf#1{%
\begingroup
\Umathcode`a =   0 \symstix "1D41A % a
\Umathcode"03B1=0 \symstix  "1D6C2 % alpha
#1%
\endgroup
}


\begin{document}

$
a \alpha a^{\alpha} 
+
\symup{a \alpha a^{\alpha}}
+
\symbf{a \alpha a^{\alpha}}
$

\end{document}
6
  • This almost works. The problem now is that commands like \def\alpha{^^^^03b1} overwrite those definitions in mtpro2. Is there a way around that?
    – Mike Pugh
    Jul 11, 2023 at 15:03
  • well I thought you wanted latin and greek letters to come from stix but if you only want them to come from stix if styled then just replace \Umathcode"03B1=0 \symstix "1D6FC % alpha by whatever mathcode you need for mtpro (which you can get from the package) @MikePugh Jul 11, 2023 at 15:07
  • @MikePugh mtpro2.sty has \DeclareMathSymbol{\alpha}{\mathalpha}{letters}{"0B} so (untested) \Umathcode"03B1=0 \symletters "0B Jul 11, 2023 at 15:14
  • I see how it fits together now. Yes, I should have been more specific. I really like MathTime Pro II and am reluctant to replace it. I also like the TeX Gyre Termes font for text and don't really want to mix a math font that is too different. But mtpro2 is missing a few things critical to my work and a sans serif Greek alphabet is one of them.
    – Mike Pugh
    Jul 11, 2023 at 15:30
  • So my assumption at this point is that I will need to (I replaced your commands with versions containing "sf" and pointing to the appropriate characters in StixTwo and TexGyreHeros) revive your commands for roman upright, boldface, and boldface italic and have them point to the appropriate characters in the correct mt2xxx.pfb font (I think there is one for each style).
    – Mike Pugh
    Jul 11, 2023 at 15:34
0

If you’re trying to work around the absence of certain Greek alphabets in Unicode, a better way is \setmathfontface, e.g.

\setmathfontface\altsfup{CMU Bright}[Scale=MatchLowercase]
\setmathfontface\altsfit{CMU Bright Oblique}[Scale=MatchLowercase]

lets you write

$\altsfit{\mupalpha}$

Note that this method only works with the \mup forms of the commands, even if you want italics. The package maps the Unicode Greek letters to these, and has commands like \alpha try to detect the current math alphabet, in a way that will stymie overriding it this way. You could also input UTF-8 literals.

An alternative is to define

\newcommand\mathsf[1]{\mathord{\textnormal{\sffamily #1}}}

You then have to either use \textalpha and so on, insert a literal UTF-8 α, or define commands like \mupalpha from unicode-math. You also would have to explicitly write out \mathnormal or \mathit.

A more complex way is to load an alternative sans-serif math font with, e.g.

\setmathfont{Fira Math}[version=sans, Scale=MatchLowercase]

You then might define a \sanssymbol command along the lines of \boldsymbol from amsbsy.cls, and use that to implement your commands.

You must log in to answer this question.

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