3

Feeding the code

\documentclass{article}
\pagestyle{empty}
\usepackage[ngerman]{babel}
\usepackage{mathtools}%%% loads amsmath internally
\mathtoolsset{mathic=true} %%% See http://tex.stackexchange.com/a/3496
\usepackage[math-style=ISO]{unicode-math}%%% In general, we wish to have ISO style.
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}%%% Times in general.
\setsansfont{TeX Gyre Heros}[Scale=0.88]%%% scaling somewhat ok.
\setmonofont{TeX Gyre Cursor}%%% no explicit turning on ligatures for the monospaced font.
\setmathfont[Ligatures=TeX]{TeX Gyre Termes Math}%%% Times-like math font.
\newcommand{\concreteSort}[1]{\mathsf{#1}}
\begin{document}
\begin{tabular}{ll}
Normal math italic Latin:& \(Sigma\).\\ %%% product of five variables S, i, g, m, a.
Normal math italic Greek:& \(\Sigma\).\\ %%% a single variable.
Upright sans-serif math Latin:&\(\concreteSort{Sigma}\).\\%%% a constant with a fixed meaning.
Upright sans-serif math Greek:&\(\concreteSort{\upSigma}\).%%% another constant with a fixed meaning. Where to get an upright sans-serif math Σ without changing the rest?
\end{tabular}
\end{document}

to xelatex leads to

enter image description here

As you see above, the last Σ has serifs. How to get rid of the serifs for upright math capital Greek without changing the rest, i.e., maintaining the formatting of the remaining text and math? Yes, we wish to stay with [xe|lua]latex. I expect that a different font is needed, but which one? How to switch to it only for the upright capital Greek math letters? Ideally, \concreteSort should produce the same (upright, sans-serif) formatting for Latin and capital Greek, but it doesn't.

EDIT: Inspired by http://tex.stackexchange.com/a/537218, I fed

\documentclass{standalone}
\usepackage[ngerman]{babel}
\usepackage{mathtools}%%% loads amsmath internally
\mathtoolsset{mathic=true} %%% See http://tex.stackexchange.com/a/3496
\usepackage[math-style=ISO]{unicode-math}%%% In general, we wish to have ISO style.
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}%%% Times in general.
\setsansfont{TeX Gyre Heros}[Scale=0.88]%%% %%% this scaling factor is a middle way between MatchUppercase and MatchLowercase.
\setmonofont{TeX Gyre Cursor}%%% no explicit turning on ligatures for the monospaced font.
\setmathfont[Ligatures=TeX]{TeX Gyre Termes Math}%%% Times-like math font.
\setmathfontface\mathsans{TeX Gyre Heros}%%% suggested by http://tex.stackexchange.com/a/537218
\begin{document}\noindent%
\begin{tabular}{@{}rl@{}}
  \verb!\(\mathsf{\mupSigma}\)!:&\(\mathsf{\mupSigma}\)\\
  \verb!\(\mathsans{\mupSigma}\)!:&\(\mathsans{\mupSigma}\)
\end{tabular}
\end{document}

to xelatex and obtained that \mathsans{\mupSigma} is larger than \mathsf{\mupSigma}:

different sizes

Why? Which one do I need for an identifier Σ with a fixed meaning? Here is some test code:

\documentclass{article}
\pagestyle{empty}
\usepackage[ngerman]{babel}
\usepackage{mathtools}%%% loads amsmath internally
\mathtoolsset{mathic=true} %%% See http://tex.stackexchange.com/a/3496
\usepackage[math-style=ISO]{unicode-math}%%% In general, we wish to have ISO style.
\defaultfontfeatures{Scale=MatchUppercase}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}%%% Times in general.
\setsansfont{TeX Gyre Heros} %[Scale=0.88]%%% this scaling factor is a middle way between MatchUppercase and MatchLowercase.
\setmonofont{TeX Gyre Cursor}%%% no explicit turning on ligatures for the monospaced font.
\setmathfont[Ligatures=TeX]{TeX Gyre Termes Math}%%% Times-like math font.
\setmathfontface\mathsans{TeX Gyre Heros}%%% suggested by http://tex.stackexchange.com/a/537218
\newcommand{\concreteSortSf}[1]{\mathsf{#1}}
\newcommand{\concreteSortSfup}[1]{\mathsfup{#1}}
\newcommand{\concreteSortSans}[1]{\mathsans{#1}}
\begin{document}\noindent%
\begin{tabular}{@{}rl@{}}
  \verb!\mathsf!: & Serif \(\mathsf{sans}\) serif.\\
  \verb!\mathsans!: & Serif \(\mathsans{sans}\) serif.
\end{tabular}

With \verb!\mathsf!:\\
Consider the sort \(\concreteSortSf{Queue}\,\concreteSortSf{\mupSigma}\) and the function signature
\[f\colon\ \,\concreteSortSf{Queue}\,\concreteSortSf{\mupSigma}\ \to\ \concreteSortSf{Stack}\,\concreteSortSf{\mupSigma}\ .\]

With \verb!\mathsfup!:\\
Consider the sort \(\concreteSortSfup{Queue}\,\concreteSortSfup{\mupSigma}\) and the function signature\[f\colon\ \,\concreteSortSfup{Queue}\,\concreteSortSfup{\mupSigma}\ \to\ \concreteSortSfup{Stack}\,\concreteSortSfup{\mupSigma}\ .\]

With \verb!\mathsans!:\\
Consider the sort \(\concreteSortSans{Queue}\,\concreteSortSans{\mupSigma}\) and the function signature\[f\colon\ \,\concreteSortSans{Queue}\,\concreteSortSans{\mupSigma}\ \to\ \concreteSortSans{Stack}\,\concreteSortSans{\mupSigma}\ .\]
\end{document}

The result is good for \mathsf and \mathsans (and the question still remains as which one to use, at least conventionally) and bad for \mathsfup, as it produces a slanted 𝛴 with serifs:

test code

Crosspost: http://latex.org/forum/viewtopic.php?p=112555

  • Your \mathsf is smaller because you loaded \setsansfont with a Scale= parameter. See my answer for a recommendation on how to handle that. – Davislor Apr 7 at 18:49
  • That is, either add \defaultfontfeatures{Scale=MatchUppercase} as I did, or add the [Scale=MatchUppercase] option to each font command, except \setmainfont. – Davislor Apr 7 at 18:53
  • In this case, \mathsf and \mathsans both get you the Σ from TeX Gyre Heros, and there are no problems with either in practice. I think \mathsans is semantically cleaner, but \mathsfup is.more standard. – Davislor Apr 7 at 18:57
  • Also, you should delete the definition of \sansmath if you do not define a version=sans. – Davislor Apr 7 at 19:01
  • 1
    Yes, you can add font options to \setmathfontface. The details are in the link in my answer. – Davislor Apr 7 at 19:48
4

There is no sans-serif Greek math alphabet in Unicode, but unicode-math allows you to define a new math alphabet with \setmathfontface. See §4.4 of the manual for details.

Another option is to select a sans-math version.

A MWE showing both methods:

\documentclass{book}
\usepackage{amsmath} % Only older installations need this.
\usepackage[math-style=ISO]{unicode-math}

\defaultfontfeatures{Scale=MatchUppercase}
\setmainfont{TeX Gyre Termes}[Scale=1.0]
\setsansfont{TeX Gyre Heros}
\setmathfont{TeX Gyre Termes Math}
\setmathfontface\mathsans{TeX Gyre Heros}
\setmathfont[version=sans]{FiraMath-Regular.otf}

\newcommand\sansmath{\mathversion{sans}}
\newcommand\sanssymbol[1]{\text{\mathversion{sans}\ensuremath{#1}}}

\begin{document}

Text Sigma: {\mupSigma} (TeX Gyre Termes)

Math upright Sigma: \(\symup\Sigma\) (TG Termes Math)

Summation symbol: \(\sum\)

Sans face: \(\mathsans{\mupSigma}\) (TeX Gyre Heros)

Sans version: \(\sanssymbol{\symup\Sigma}\) (Fira Math)

\end{document}

Font sample

This adds a new command \mathsans analogous to \mathsfup, \sansmath analogous to \boldmath and \sanssymbol analogous to \boldsymbol. You might need to wrap this version of \sanssymbol in a command such as \mathbin or \mathrel to get correct spacing for things other than letters.

In particular, \mathop{\sanssymbol{\sum}} works. If you just want all summation symbols to be sans-serif, you could use \setmathfont{Fira Math}[range=\sum] instead of [version=sans].

P.S.: You select ISO style when you load unicode-math, but in ISO style, upright Greek capital letters should be slanted, unless they are constants.

P.P.S.: The \mathsfup command would work in this case. It loads the font you loaded with \setsansfont. In theory, it’s intended for words and short phrases in math mode, and for example, if you tried to use it for consecutive symbols, you might get ligatures.

The command intended for tensor symbols and the like is \symsfup, but it will not work for this because there is currently no Greek mathematical sans-serif alphabet in Unicode.

ETA

A better definition of \sansmath and \sanssymbol, based on amsbsy.sty:

\makeatletter
\newcommand\sansmath{\mathversion{sans}}
%% Based on the definition of \boldsymbol from amsbsy.sty"
\DeclareRobustCommand{\sanssymbol}[1]{%
  \begingroup%
  \let\@nomath\@gobble \mathversion{sans}%
  \math@atom{#1}{%
  \mathchoice%
    {\hbox{$\m@th\displaystyle#1$}}%
    {\hbox{$\m@th\textstyle#1$}}%
    {\hbox{$\m@th\scriptstyle#1$}}%
    {\hbox{$\m@th\scriptscriptstyle#1$}}}%
  \endgroup}
\makeatother
| improve this answer | |
  • In the OP, the Σs are not meant to be summation symbols. The slanted ones are logical variables. The upright ones are constants. – Just_A_Man Apr 7 at 7:31
  • @Juat_A_Man Agreed. I think the information about summation is useful enough to someone else who wants to know about a Sigma in math mode to leave in. Do you think I should reword it? – Davislor Apr 7 at 8:07
  • To me, it's pretty clear what you want to say, though I'm not interested in summation. To remain clear, I've just introduced the intented meaning of the various Sigmas and \Sigmas into LaTeX comments of the OP. I'll try your suggestions out in short. Still, as for the other readers, I think you should speak about \Sigma, not about \sum, so that you answer matches the OP more closely, and that the additional complications of an operator are kept away. – Just_A_Man Apr 7 at 9:28
  • Compiling your code with xelatex yields kpathsea:make_tex: Invalid filename `Fira Math/OT', contains ' ' ! Package fontspec Error: The font "Fira Math" cannot be found. Compiling with lualatex yields ! Undefined control sequence. \sanssymbol #1->\text {\mathversion {sans}\ensuremath {#1}} l.24 Sans version: \(\sanssymbol{\symup\Sigma} \) (Fira Math). I have unicode-math v. 0.8o. – Just_A_Man Apr 7 at 13:17
  • I've just noticed that a simple \(\mathsf{\mupSigma}\) is sans-serif capital Greek in math mode, as requested. However, \(\mathsf{\mupSigma}\) produces a slighlty different output than \(\mathsans{\mupSigma}\). Why? – Just_A_Man Apr 7 at 16:57
2

You can define \concreteSort to also modify the meaning of the Greek letter commands.

The list in the definition of \changegreek is incomplete, fill in the missing letters.

The idea is to change \Sigma into \symsfupx{\mupSigma}, which will use the letter in the sans font (assuming it has it, of course; otherwise you need another clone of Helvetica that does).

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{mathtools}

\usepackage[math-style=ISO]{unicode-math}

\setmainfont{TeX Gyre Termes}
\setsansfont{TeX Gyre Heros}[Scale=MatchLowercase]
\setmonofont{TeX Gyre Cursor}
\setmathfont{TeX Gyre Termes Math}
\setmathfontface{\symsfupx}{TeX Gyre Heros}[Scale=MatchLowercase]

\mathtoolsset{mathic=true}

\newcommand{\concreteSort}[1]{\symsfup{\changegreek#1}}

\ExplSyntaxOn
\cs_new_protected:Npn \changegreek
 {
  \clist_map_inline:nn { \Alpha,\Beta,\Gamma,\Delta,\Sigma } % <--- add
   {
    \cs_set_protected:Npn ##1 { \symsfupx{\use:c{mup \cs_to_str:N ##1 }} }
   }
 }
\ExplSyntaxOff


\begin{document}

\begin{tabular}{ll}
Normal math italic Latin:& \(Sigma\).\\
Normal math italic Greek:& \(\Sigma\).\\
Upright sans-serif math Latin:&\(\concreteSort{Sigma}\).\\
Upright sans-serif math Greek:&\(\concreteSort{\Sigma}\).\\
\end{tabular}

\end{document}

enter image description here

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.