3

This is kind of a follow up question of Make mathfont respect the surrounding family.

For my main text (\rmfamily) I want to use Palatino and for \sffamily Arev. The math fonts should also respect this. And it nearly works, but the following example code has two issues:

  1. Uppercase greek letters don’t work in sans. How can I fix that?
  2. How can I select the other v from Araev, ssince the one selected is nearly indistinguishable from \nu. When I try \DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71} it affects all math fonts and also has no bold version.

Code

\documentclass{book}

\usepackage[scaled=1.15]{newpxtext}
\usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}
\usepackage{letltxmacro}

\renewcommand{\sfdefault}{fav}

\DeclareMathVersion{arev}

\SetSymbolFont {operators}    {arev} {OT1} {zavm}  {m} {n}
\SetSymbolFont {letters}      {arev} {OML} {zavm}  {m} {it}
\SetSymbolFont {lettersA}     {arev} {OT1} {zavm}  {m} {n} % <-- breaks some symbols
\SetSymbolFont {symbols}      {arev} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it}
\SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n}
\SetMathAlphabet {\mathtt} {arev} {T1}  {fvm}  {m} {n}

% ander Form für v
\DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it}
%\DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71}% affects \rmfamily too, and doesnt have bold version

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators}    {arevbold} {OT1} {zavm}  {b} {n}
\SetSymbolFont {letters}      {arevbold} {OML} {zavm}  {b} {it}
\SetSymbolFont {lettersA}     {arevbold} {OT1} {zavm}  {b} {n} % <-- breaks some symbols
\SetSymbolFont {symbols}      {arevbold} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathit}    {arevbold} {OT1} {zavm}  {b} {it}
\SetMathAlphabet {\mathbf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathtt}    {arevbold} {T1}  {fvm}   {b} {n}


\newif\IfInSansMode
\LetLtxMacro\oldsf\sffamily
\renewcommand*{\sffamily}{\oldsf\mathversion{arev}\InSansModetrue}
\LetLtxMacro\oldbf\bfseries
\renewcommand*{\bfseries}{\oldbf\IfInSansMode\mathversion{arevbold}\else\mathversion{bold}\fi\relax}
\LetLtxMacro\oldnorm\normalfont
\renewcommand*{\normalfont}{\oldnorm\InSansModefalse\mathversion{normal}}
\LetLtxMacro\oldrm\rmfamily
\renewcommand*{\rmfamily}{\oldrm\InSansModefalse\mathversion{normal}}

\newcommand{\TestText}{%
   $v \nu$

   $abcdefghijklmnopqrstuvwxyz$

   $ABCDEFGHIJKLMNOPQRSTUVWXYZ$

   $\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

   $\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

   $\int(1-2\cdot 10^{-5}) = \sum_i^\infty\sin x_i + a$
}

\begin{document}
\TestText

\bigskip
\bfseries
\TestText

\bigskip
\sffamily\mdseries
\TestText

\bigskip
\bfseries
\TestText

\end{document}

PS: I have to use pdflatex

2 Answers 2

4

There's actually a lot of work involved, because newpxmath assigns Greek upright letters to the lettersA symbol font and changes several locations for symbols.

\documentclass{book}
\usepackage{iftex}

\usepackage[scaled=1.15]{newpxtext}
\usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}

\iftutex
  \defaultfontfeatures{Ligatures=TeX}
  \setsansfont{DejaVu Sans}
\else
  \renewcommand{\sfdefault}{fav}
\fi

\DeclareMathVersion{arev}

\SetSymbolFont {operators}    {arev} {OT1} {zavm}  {m} {n}
\SetSymbolFont {letters}      {arev} {OML} {zavm}  {m} {it}
\SetSymbolFont {lettersA}     {arev} {OT1} {zavm}  {m} {n} % <-- added
\SetSymbolFont {symbols}      {arev} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it}
\SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n}
\SetMathAlphabet {\mathtt} {arev} {T1}  {fvm}  {m} {n}

% ander Form für v
\DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it}
% affects \rmfamily too, and doesn't have bold version
%\DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71}

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators}    {arevbold} {OT1} {zavm}  {b} {n}
\SetSymbolFont {letters}      {arevbold} {OML} {zavm}  {b} {it}
\SetSymbolFont {lettersA}     {arevbold} {OT1} {zavm}  {b} {n} % <-- added
\SetSymbolFont {symbols}      {arevbold} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathit}    {arevbold} {OT1} {zavm}  {b} {it}
\SetMathAlphabet {\mathbf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathtt}    {arevbold} {T1}  {fvm}   {b} {n}


\newif\IfInSansMode
\mathchardef\normalplus="202B
\mathchardef\newpxplus="22CF
\mathchardef\normallparen=16424
\mathchardef\newpxlparen=\mathcode`(
\def\normallparencode{164608 }
\edef\newpxlparencode{\the\delcode`( }
% other similar commands
\newcommand{\choosemathversion}[1]{%
  \mathversion{#1}%
  \symbolfixes{#1}%
}
\newcommand{\symbolfixes}[1]{\csname makesymbolfixes#1\endcsname}
\newcommand{\makesymbolfixesnormal}{%
  \mathcode`+=\newpxplus
  \mathcode`(=\newpxlparen
  \delcode`(=\newpxlparencode\relax
  % other similar fixes
}
\newcommand{\makesymbolfixesarev}{%
  \mathcode`+=\normalplus
  \mathcode`(=\normallparen
  \delcode`(=\normallparencode\relax
  % other similar fixes
}
\newcommand{\makesymbolfixesarevbold}{\makesymbolfixesarev}

\AddToHook{cmd/normalfont/after}{%
  \choosemathversion{normal}\InSansModefalse
}
\AddToHook{cmd/sffamily/after}{%
  \choosemathversion{arev}\InSansModetrue
}
\AddToHook{cmd/bfseries/after}{%
  \IfInSansMode
    \choosemathversion{arevbold}%
  \else
    \choosemathversion{bold}%
  \fi
}

\begin{document}

Some text $v\nu$ with a v.

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip
\bfseries

Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip
\sffamily\mdseries

Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip
\bfseries
Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\end{document}

The “lot of work” refers to what has to be added to those lists of commands in order to change output encodings back and forth.

How to discover what codes to switch? You'll be warned about missing characters.

enter image description here

15
  • Thanks! That solves my issue no. 1. Any ideas vor issue no. 2 (changing v shape in sans only)?
    – Tobi
    Aug 6, 2016 at 7:55
  • @Tobi That's more work, I'll give a look later
    – egreg
    Aug 6, 2016 at 8:43
  • Mille grazie:-)
    – Tobi
    Aug 6, 2016 at 10:46
  • I tried to add your solution to my real document now but it breaks parens and some other symbols. See the updated MWE in my question.
    – Tobi
    Aug 8, 2016 at 15:26
  • @Tobi I'm afraid there are several differences in encodings.
    – egreg
    Aug 8, 2016 at 16:47
0

I found a solution myself:

  1. Uppercase greek: Using the original \DeclareMathSymbol{\Gamma}{\mathalpha}{operators}{"00} etc. from source2e.pdf (p. 224) the uppercase greek letters are taken from the right fonts for roman and sans version.
  2. v vs. \nu: Make vactive in mathe mode and define it to use the italic v of the text font with \text{\textit{v}}.

enter image description here

\documentclass{book}

\usepackage[scaled=1.15]{newpxtext}
\usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}
\usepackage{letltxmacro}

\renewcommand{\sfdefault}{fav}

\DeclareMathSymbol{\Gamma}{\mathalpha}{operators}{"00}
\DeclareMathSymbol{\Delta}{\mathalpha}{operators}{"01}
\DeclareMathSymbol{\Theta}{\mathalpha}{operators}{"02}
\DeclareMathSymbol{\Lambda}{\mathalpha}{operators}{"03}
\DeclareMathSymbol{\Xi}{\mathalpha}{operators}{"04}
\DeclareMathSymbol{\Pi}{\mathalpha}{operators}{"05}
\DeclareMathSymbol{\Sigma}{\mathalpha}{operators}{"06}
\DeclareMathSymbol{\Upsilon}{\mathalpha}{operators}{"07}
\DeclareMathSymbol{\Phi}{\mathalpha}{operators}{"08}
\DeclareMathSymbol{\Psi}{\mathalpha}{operators}{"09}
\DeclareMathSymbol{\Omega}{\mathalpha}{operators}{"0A}

\DeclareMathSymbol{\intop}{\mathop}{largesymbols}{"52}
\DeclareMathSymbol{\ointop}{\mathop}{largesymbols}{"48}

\DeclareMathAlphabet {\mathsfbf} {OT1} {zavm}  {b} {n}

\DeclareMathDelimiter{(}{\mathopen} {operators}{"28}{largesymbols}{"00}
\DeclareMathDelimiter{)}{\mathclose}{operators}{"29}{largesymbols}{"01}

\DeclareMathVersion{arev}

\SetSymbolFont {operators}    {arev} {OT1} {zavm}  {m} {n}
\SetSymbolFont {letters}      {arev} {OML} {zavm}  {m} {it}
\SetSymbolFont {symbols}      {arev} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathsf} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it}
\SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n}
\SetMathAlphabet {\mathtt} {arev} {T1}  {fvm}  {m} {n}

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators}    {arevbold} {OT1} {zavm}  {b} {n}
\SetSymbolFont {letters}      {arevbold} {OML} {zavm}  {b} {it}
\SetSymbolFont {symbols}      {arevbold} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathsf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathsfbf}  {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathit}    {arevbold} {OT1} {zavm}  {b} {it}
\SetMathAlphabet {\mathbf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathtt}    {arevbold} {T1}  {fvm}   {b} {n}

\newif\IfInSansMode

\let\oldsf\sffamily
\renewcommand*{\sffamily}{\oldsf\mathversion{arev}\InSansModetrue}

\let\oldbf\bfseries
\renewcommand*{\bfseries}{\oldbf\IfInSansMode\mathversion{arevbold}\else\mathversion{bold}\fi\relax}

\let\oldnorm\normalfont
\renewcommand*{\normalfont}{\oldnorm\InSansModefalse\mathversion{normal}}

\let\oldrm\rmfamily
\renewcommand*{\rmfamily}{\oldrm\InSansModefalse\mathversion{normal}}

\DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it}
\SetSymbolFont{extraitalic}{arevbold} {OML} {zavm}  {b} {it}
\DeclareMathSymbol{\VarV}{\mathalpha}{extraitalic}{71}
\DeclareSymbolFont{extraitalicbold}{U}{zavm}{b}{it}
\DeclareMathSymbol{\VarVBold}{\mathalpha}{extraitalicbold}{71}
\DeclareMathSymbol{\NormalV}{\mathalpha}{letters}{`v}

\mathcode`\v="8000
{\catcode`\v=\active
\gdef v{\mathalpha{\text{\textit{\char`v}}}}}

\newcommand{\TestText}{%
   $v \nu$

%   $abcdefghijklmnopqrstuvwxyz$

%   $ABCDEFGHIJKLMNOPQRSTUVWXYZ$

%   $\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

   $\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

%   $\int(1-2\cdot 10^{-5}) = \sum_i^\infty\sin x_i + a$
}

\begin{document}
\TestText

\bigskip
\bfseries
\TestText

\bigskip
\sffamily\mdseries
\TestText

\bigskip
\bfseries
\TestText

\end{document}

You must log in to answer this question.

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