3

I have the strong conviction that I have only understood 1% of how LaTeX selects (math) fonts, so I guess that most of my problems come from that, apart from the lack of a proper math font matching Helvetica.

My goal is to have sans serif math in surroundings where text is sans serif, and serif math where the text is serif. To that end I define mathversions sans and sansbold (I have heard about this 16-font limitation, so I guess I shouldn't be doing this, but now I'm curious). I have tried to copy at least some stuff from newtxsf.sty (I think) I understand, ending with

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{newtxtext,newtxmath}
\usepackage[scaled=0.87]{helvet}

\DeclareMathVersion{sans}
\DeclareMathVersion{boldsans}

\DeclareFontEncoding{LMS}{}{}
\DeclareFontSubstitution{LMS}{ntxsy}{m}{n}
\DeclareFontSubstitution{U}{ntxsfmia}{m}{it}

\SetSymbolFont{operators}       {sans}{\encodingdefault}{\sfdefault}{m}{n}
\SetSymbolFont{letters}         {sans}{OML}{ntxsfmi}{m}{it}
\SetSymbolFont{lettersA}        {sans}{U}{ntxsfmia}{m}{it}
\SetSymbolFont{largesymbolsTXA} {sans}{U}{ntxexa}{m}{n}
\SetMathAlphabet{\mathbf}       {sans}{T1}{phv}{b}{n}
\SetMathAlphabet{\mathit}       {sans}{OML}{ntxsfmi}{m}{it}

\SetSymbolFont{operators}       {boldsans}{\encodingdefault}{\sfdefault}{b}{n}
\SetSymbolFont{letters}         {boldsans}{OML}{ntxsfmi}{b}{n}
\SetSymbolFont{symbols}         {boldsans}{LMS}{ntxsy}{b}{n}
\SetSymbolFont{AMSm}            {boldsans}{U}{ntxsym}{b}{n}
\SetSymbolFont{symbolsC}        {boldsans}{U}{ntxsyc}{b}{n}
\SetSymbolFont{largesymbols}    {boldsans}{LMX}{ntxexx}{b}{n}
\SetSymbolFont{largesymbolsTXA} {boldsans}{U}{ntxexa}{b}{n}
\SetSymbolFont{lettersA}        {boldsans}{U}{ntxsfmia}{b}{it}
\SetMathAlphabet{\mathbf}       {boldsans}{T1}{phv}{b}{n}
\SetMathAlphabet{\mathit}       {boldsans}{OML}{ntxsfmi}{b}{it}

\newcommand\test{
    \emph{h}$h \sum_i \bigl[\bigr]  \to \lim_{\alpha} \Xi\ \mathbf{aB\Xi}\mathrm{aB}\mathit{aB\Xi}\mathfrak{aB}\mathcal{A}$
}
\begin{document}
        \test
        
        \bfseries\mathversion{bold}\test
        
        \mdseries\sffamily\mathversion{sans}\test

        \bfseries\mathversion{boldsans}\test
\end{document}

enter image description here

The obvious issues are

  • The \bigl[\bigr] don't match. Other brackets and sizes seem to work.
  • The $\mathbf{\Xi}$ does not work (should it even?), which is because \mathrm is done using phv as there seems to be no upright version of ntxsfmi. I'm not sure if I should care.
  • The Fraktur letters look different in mathversion{normal} and \mathversion{sans}. Although it does not hurt so much, I wonder where it comes from.

Apart from that, should I be doing this? Did I miss something really important? You'll have noticed that I used scaled=.87 for helvet instead of the common 0.95, which I chose to be somewhere between Times and newtxsf.

3
  • 1
    You talk about \mathrm{\Xi} but your code does not contain it. Do you mean \mathbf{\Xi}? Anyway the issue is that T1 has the dieresis where OT1 has Xi, and you set \mathbf to use T1. Change that to OT1 and replace phv by qhv (that's tgheros, an Helvetica clone which however contains all symbols).
    – campa
    Mar 4, 2021 at 17:04
  • 1
    Also you talk about the math version normal and serif, but there is no math version serif here. Please edit such that your questions do actually match your code.
    – campa
    Mar 4, 2021 at 17:10
  • @campa You are absolutely right; I meant sans mathversion and mathbf. Thank you for mentioning qhv; I wasn't aware that this seems to be the sfdefault font set by newtxtext anyway.
    – Bubaya
    Mar 5, 2021 at 17:53

2 Answers 2

5

What you have looks fine actually (akthough you probably want to use OT1 not T1 in math as campa noted in comments).

The 16 math group limit is 16 fonts per math version so adding two new math versions is exactly the right approach.

The issue with the mis-aligned [] is not your fault, it appears to be an error in the txfonts setup that you should perhaps report:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}

\usepackage{newtxtext,newtxmath}

\begin{document}
        
\boldmath

$[], \bigl[\bigr], \Bigl[\Bigr]$
        
\end{document}

enter image description here

5
  • Thanks for clarifying that the 16 fonts are per math version. Do you know why the Fraktur letters are of slightly different weight?
    – Bubaya
    Mar 5, 2021 at 19:10
  • @Bubaya they are different fonts so no reason they should have the same weight really the two non bold fraktur B are \U/ntxmia/m/it/10.95 B and \U/ntxsfmia/m/it/10.95 B Mar 5, 2021 at 20:20
  • I guess I only expected them to be equal because they almost are. But yes, I figured out how to change this. All this font stuff is really strange if you've been raised with Word…
    – Bubaya
    Mar 5, 2021 at 20:30
  • @Bubaya the opentype font setup in Davislor's answer is much closer to Word setup, in fact the opentype Math Font layout used by luatex or xetex via the unicode-math package is built on the OpenType Math table which was specified by Microsoft while designing its math zones and the cambria math font. Mar 5, 2021 at 20:34
  • Michael has submitted an update to newtx. The output should be fine now.
    – campa
    Mar 25, 2021 at 12:18
2

For completeness, here is how you might do the same thing in the modern toolchain. The \versionsymbol code should work in any engine.

\documentclass{article}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase,
                      Ligatures = TeX }
\setmainfont{TeX Gyre Pagella}[Scale=1.0]
\setmathfont{KpMath-Regular}
\setmathfont[version=bold]{KpMath-Bold}
\setmathfont[version=sans]{KpMath-Sans}
\setmathfont[version=sansbold, FakeBold=1.2]{KpMath-Sans}

% A higher-order version of \boldsymbol from amsbsy.sty:
\makeatletter
\DeclareRobustCommand{\versionsymbol}[2]{%
  \begingroup
  \let\@nomath\@gobble \mathversion{#1}%
  \math@atom{#2}{%
  \mathchoice%
    {\hbox{\(\m@th\displaystyle#2\)}}%
    {\hbox{\(\m@th\textstyle#2\)}}%
    {\hbox{\(\m@th\scriptstyle#2\)}}%
    {\hbox{\(\m@th\scriptscriptstyle#2\)}}}%
  \endgroup}
\makeatother

\newcommand\sansmath{\mathversion{sans}}
\newcommand\sansboldmath{\mathversion{sansbold}}
\newcommand\sanssymbol[1]{\versionsymbol{sans}{#1}}
\newcommand\sansboldsymbol[1]{\versionsymbol{sansbold}{#1}}

\begin{document}

\( [x] \, \boldsymbol{[x]} \, \sanssymbol{[x]} \, \sansboldsymbol{[x]} \)

Default \( (r, \theta, \phi ) \)

{\bfseries\boldmath Bold \( (r, \theta, \phi ) \) }

{\sffamily\sansmath Sans-serif \( (r, \theta, \phi ) \) }

{\sffamily\bfseries\sansboldmath Sans-serif bold \( (r, \theta, \phi ) \)}

\end{document}

KP Fonts sample

You must log in to answer this question.

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